0

I have a weird problem with drawing fonts in C#. Basically I followed the steps in this blog https://web.archive.org/web/20141224204810/http://bobpowell.net/embedfonts.aspx to load the font. Everything works fine, but sometimes when I load the application the text gets messy like this picture: http://oi41.tinypic.com/20jphkx.jpg

Anyone has any idea what's happening?

P.S: Here is how I load the font

_fonts = new PrivateFontCollection();
byte[] fontData = Properties.Resources.PlacardMTCondensed;
IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length);
Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
_fonts.AddMemoryFont(fontPtr, fontData.Length);
Marshal.FreeCoTaskMem(fontPtr);

And here is how I try to use it in OnPain event:

g.DrawString(stBuilder.ToString(), "Something", blackBrush, 0, 0);
Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Gabriel
  • 578
  • 3
  • 8
  • 22
  • 2
    Details. Provide code. – Aurelia Nov 18 '13 at 20:37
  • I added some code, but for more details you can also refer to the links i provided. As I mentioned, this bug sometimes happens. Also, the font I'm using is embedded in the resources and it's called PlacardMTCondensed – Gabriel Nov 18 '13 at 21:38
  • Don't you need a call to [AddFontMemResourceEx](http://msdn.microsoft.com/en-us/library/windows/desktop/dd183325(v=vs.85).aspx) as well? – 500 - Internal Server Error Nov 18 '13 at 23:20
  • @500-InternalServerError I already added the ttf file to my resources, do I need to use that function too? Should I add it after the loading to memory or before that? – Gabriel Nov 21 '13 at 00:07
  • 1
    See this question: http://stackoverflow.com/questions/1955629/c-sharp-using-an-embedded-font-on-a-textbox – 500 - Internal Server Error Nov 21 '13 at 00:43

0 Answers0