TrueType to C Array
I am writing a low level C app, and I'm planning on using an array to store my fonts.
The problem is, the font I'd like to use开发者_开发百科 is in TrueType format. How shall I:
Convert TTF to a large sized, B&W, bitmap font without any kind of AA (not strictly programming related);
Parse the B&W bitmap font into a C byte array.
What format should I use for the bitmap? Should be simple enough that me, a beginner programmer with little over a year of experience can write a parser to store it in said array.
I don't want to use external libraries, and I'd like to keep C Std. Lib. usage to a minimum. It's for a college project and I want to write everything myself.
It's not the most professional or cleanest, but here's what I'd do in your situation:
- Choose a monospaced font and a size where each character is an integral number of pixels.
- Open GIMP (or your favorite image editing program) and make an image that's
font_width
pixels wide andfont_height*96
pixels tall. - Make a text element anchored at the upper-left corner containing
<space> <newline> ! <newline> " <newline> # <newline>
... (i.e. all the ASCII glyphs). - Save it as an uncompressed image format that's easy to process, like PNM.
- Load it into an array of type
uint8_t [96][font_height][font_width]
.
Use Win32 GDI APIs to write bitmaps: create a bitmap, print a letter, use GetPixel
to read it. Serialize to .c file.
Try Freetype. It can provide you with data you can use for your bitmap creation.
精彩评论