0

I am adding the font using

GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
CustomFonts.Fonts.AddMemoryFont(pointer, data.Length);
pinnedArray.Free();

But when I use it for a label, it just shows up as a bunch of letters(when running). I have turned on CompatibleTextRendering. I am trying to embed "Visitor". When I use it without embedding it, it works fine. But I want to embed it as it is not a standard font.

Edit:

Just tried using AddFile and that works. No idea why adding it from memory is failing.

Will
  • 10,013
  • 9
  • 45
  • 77

1 Answers1

2

Apparently AddMemoryFont does not make an additional api call that it should.

[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);

GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
CustomFonts.Fonts.AddMemoryFont(pointer, data.Length);
uint dummy = 0;
AddFontMemResourceEx((IntPtr)pointer, (uint)data.Length, IntPtr.Zero, ref dummy);
pinnedArray.Free();
Will
  • 10,013
  • 9
  • 45
  • 77