views:

377

answers:

4

How do you do your own fonts? I don't want a heavyweight algorithm (freetype, truetype, adobe, etc) and would be fine with pre-rendered bitmap fonts.

I do want anti-aliasing, and would like proportional fonts if possible.

I've heard I can use Gimp to do the rendering (with some post processing?)

I'm developing for an embedded device with an LCD. It's got a 32 bit processor, but I don't want to run Linux (overkill - too much code/data space for too little functionality that I would use)

C. C++ if necessary, but C is preferred. Algorithms and ideas/concepts are fine in any language...

+4  A: 

In my old demo-scene days I often drew all characters in the font in one big bitmap image. In the code, I stored the (X,Y) coordinates of each character in the font, as well as the width of each character. The height was usually constant throughout the font. If space isn't an issue, you can put all characters in a grid, that is - have a constant distance between the top-left corner of each character.

Rendering the text then becomes a matter of copying one letter at a time to the destination position. At that time, I usually reserved one color as being the "transparent" color, but you could definitely use an alpha-channel for this today.

A simpler approach, that can be used for small b/w fonts, is to define the characters directly in code:

LetterA  db 01111100b
         db 11000110b
         db 11000110b
         db 11111110b
         db 11000110b
         db 11000110b

The XPM file format is actually a file format with C syntax that can be used as a hybrid solution for storing the characters.

norheim.se
+1  A: 

Pre-rendered bitmap fonts are probably the way to go. Render your font using whatever, arrange the characters in a grid, and save the image in a simple uncompressed format like PPM, BMP or TGA. If you want antialiasing, make sure to use a format that supports transparency (BMP and TGA do; PPM does not).

In order to support proportional widths, you'll need to extract the widths of each character from the grid. There's no simple way to do this, it depends on how you generate the grid. You could probably write some short little program to analyze each character and find the minimal bounding box. Once you have the width data, you put it in an auxiliary file which contains the coordinates and sizes of each character.

Finally, to render a string, you look up each character and bitblit its rectangle from the font bitmap onto your frame buffer, advancing the raster position by the width of the character.

Adam Rosenfield
+1  A: 

We have successfully used the SRGP package for fonts. We did use fixed-pitch fonts, so I'm not sure if it can proportional fonts.

Jeff
+1  A: 

We're using bitmap fonts generated by anglecode#s bitmap font generator :

http://www.angelcode.com/products/bmfont/

This is very usable as it has XML output which will be easy to convert to any data format you need.

Angel Code's bmfont also adds kerning and better packing to the old alternative that was MudFont.

Richard Fabian