Хорошо, я понял это благодаря сетям и Google.
На будущее, если кто-нибудь имеет эту проблему, исправление: после получения вашего встроенного шрифта в виде потока, и перед вызовом AddMemoryFont, вы должны позвонить AddFontMemResourceEx! (не доступен в C#, так что вы должны импортировать его:
[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
, а затем:.
//create an unsafe memory block for the data
System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);
//create a buffer to read in to
Byte[] fontData = new Byte[fontStream.Length];
//fetch the font program from the resource
fontStream.Read(fontData, 0, (int)fontStream.Length);
//copy the bytes to the unsafe memory block
Marshal.Copy(fontData, 0, data, (int)fontStream.Length);
// We HAVE to do this to register the font to the system (Weird .NET bug !)
uint cFonts = 0;
AddFontMemResourceEx(data, (uint)fontData.Length, IntPtr.Zero, ref cFonts);
//pass the font to the font collection
mFontCollection.AddMemoryFont(data, (int)fontStream.Length);
//close the resource stream
fontStream.Close();
//free the unsafe memory
Marshal.FreeCoTaskMem(data);
И вуаля, вы будете иметь возможность использовать шрифт Без AddFontMemResourceEx это не будет работать .
+1 Полезно знать это, спасибо, Led – BillW
Священный краб Я ударил головой о стену часами, спасибо! – Mike
Где находится «fontStream»? –