开发者

TrueType to C Array

开发者 https://www.devze.com 2023-01-24 21:12 出处:网络
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:

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:

  1. Convert TTF to a large sized, B&W, bitmap font without any kind of AA (not strictly programming related);

  2. 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 and font_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.

0

精彩评论

暂无评论...
验证码 换一张
取 消