[.net] Including Fonts as Resources
If I want to use an unusual font in my C# game, I think it would be a good idea to put it in my game resource folder and package it with the game. Is there a way to load a font from a particular directory to use?
I don't want users to have to register my fonts with their system.
It's possible to bundle a set of application specific fonts with C#. A good starting point is the System.Drawing.Text.PrivateFontCollection class. In particular pay attention to the AddFontFile() method.
You can also compile the font file in the assembly and use it as an embedded resource if you want. Here's some example code on how to load a font embedded in your assembly: http://www.tek-tips.com/faqs.cfm?fid=4747
Bob
Bob
Quote:Original post by cyansoft
You can also compile the font file in the assembly and use it as an embedded resource if you want. Here's some example code on how to load a font embedded in your assembly: http://www.tek-tips.com/faqs.cfm?fid=4747
Bob
There's nothing wrong with SiCrane's method, but I think this is the more advisable route. Fonts are resources just like other resources, and you shouldn't have to do extra work to get them to behave the same way. Instead, you should be able to recycle the resource-loading/using code just as if you were retrieving, say, a localized text string or an icon.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement