Once again I need your help.
I'm developing a small application on C# that uses a custom Font. The problem is, the font must be installed previously on the system. If the font is not present in the system it just uses Times New Roman. Is there any way to embed the font file in the application so it doesn't need to be installed in every system?
Thank you.
If you're still reading this, I might point out that you don't have to use unsafe code to load the font from a resource. Here's an example using Marshal.
PrivateFontCollection _fonts = new PrivateFontCollection();
byte[] fontData = Resources.CustomFontResourceName;
IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length);
Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
_fonts.AddMemoryFont(fontPtr, fontData.Length);
Marshal.FreeCoTaskMem(fontPtr);
Font customFont = new Font(_fonts.Families[0], 6.0F);
Note that if you use AddMemoryFont, you will need to use this api call "AddFontMemResourceEx" or it wont work.
PrivateFontCollection giving me symbols
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With