cfontsheaderbitmap

C header file with bitmapped fonts


I need to do some rudimentary text rendering to a pixel buffer, and I think that having a table indexed by char with the representation of the letters as a binary array would be more than enough... Anybody knows about a free header as such?

Example:

char data[256][8][8];
void init()
{
  data['a'] = {
    {0,0,1,1,1,0,0,0},
    {0,1,0,0,0,1,0,0},
    {0,0,0,0,0,0,1,0},
    {0,0,1,1,1,0,1,0},
    {0,1,0,0,0,1,1,0},
    {0,1,0,0,0,0,1,0},
    {0,1,0,0,0,1,1,0},
    {0,0,1,1,1,0,1,0},
  };
}

I could go on with the rest of the alphabet, but then I wouldn't need to ask... ¡But that gives me an idea! if there's no free header with a bitmapped font readily available, each answer could implement a letter and I could assemble the whole file here ^_^


Solution

  • Update: I tried this approach and the characters come out fairly distorted. Possibly Nimbus is a poor font choice.

    Go with the imagemagick approach. You can generate each character with this:

    convert -resize 7x13\! -font Nimbus-Mono-Regular -pointsize 10 label:A A.xbm
    

    A.xbm looks like:

    #define A_width 7
    #define A_height 13
    static char A_bits[] = {
      0x00, 0x00, 0x00, 0x00, 0x1C, 0x08, 0x00, 0x3C, 0x00, 0x66, 0x00, 0x00,
      0x00, };
    

    Loop through the characters you need and assemble this into a single header file.

    Even though Nimbus-Mono-Regular is a monospace font, sometimes the character widths are off by a pixel. The convert option "-resize 7x13!" forces a 7x13 output size. Again, this might be a problem specifically with the Nimbus font.