Rendering glyphs to bitmaps with the FreeType library

I've been trying to learn a little bit of Japanese, just for the hell of it, and so I've been wanting to look at good quality renderings of particular symbols to get the feel of what they look like.

I've hacked up a little program in C (render-unicode-character.c) to render glyphs from TrueType fonts, using the FreeType library (version 2). It works quite well. It doesn't do anything clever, just outputs a PGM image (to standard output) showing a single glyph.

The following options can be passed in:

  • -f — filename of the font file to use (required)
  • -s — point size to render at (default 72)
  • -r — resolution to render at, in DPI (default 600)
  • -b — number of pixels of blank border to put round the edge (default 10)

The default values give nice big output. The only non-option argument to supply is the character code (in Unicode) of the character to render. It can be given as decimal or hexadecimal (if you prefix it with 0x).

As an example I dug a random interesting-looking kanji out of Edict (a free Japanese dictionary in a big text file). This is 磯 (beach), pronounced いそ (iso). It's Unicode character U+78EF from the free Kochi Mincho font.

Chinese/Japanese character meaning ‘beach’.  It is made up of many cursive strokes, mostly quite short, like tear-shaped blobs, with a longer curve down the right hand side, and a box shape in the bottom left.

< Friend network website things | Orkut — now I'm in the club >

Miniblog

(nuggets of inanity)

Tuesday Apr 24th 2007, 16:54 »
Just took the annual web design survey that AListApart do. I don't realy consider myself to be a web designer, but I have been doing a lot of HTML and CSS lately.
Monday Apr 23rd 2007, 18:23 »
Strange, there appears to be a bare-knuckle boxing match going on in the field outside my flat. Wish they wouldn't make so much noise about it.
Thursday Mar 1st 2007, 18:47 »
“In its written form, Hebrew has no vowels, making it the ideal language for texting.”
—Said in jest on some Radio 4 programme just now.

Archive: 2007 · 2006 · 2005 · 2004
Feed