Working with SVGAlib Fonts: Page 2

WEBINAR: On-demand webcast

Next-Generation Applications Require the Power and Performance of Next-Generation Workstations REGISTER >

Posted January 13, 2000

Jay Link

(Page 2 of 2)

linux graphics

Creating Bitmapped Fonts

You now know that each character in an 8-pixel by 8-pixel bitmapped font is defined by eight values. This, in turn, means that a 256-character font requires 2048 numbers. That's fine, but what do those numbers mean? Would anything bad happen if you changed them? And how can you create your own fonts? Let's find out.

Each character in an 8 x 8 font is actually comprised of eight horizontal lines, containing eight pixels apiece. Accordingly, each font number refers to one of the eight horizontal lines. The lines run from top to bottom, so the numbers refer to the lines in sequential order. For example, a capital "S" can be created with the numbers 126, 128, 128, 124, 2, 2, 252, and 0. (The 0 is to provide a buffer between multiple lines of text). See the illustration below for a better representation.

8 horizontal font strips

Did you see how the eight numbers made the letter "S"? Now, what would happen if you just used the number "124" for all eight lines? Here's how that would look:

All eight strips are number 124

So, as you can see, the numbers in the font's char array logically create each character in the font.

That said, how do you know which numbers do what? Is it random? No -- it's organized rather well. As you know, each of the character's eight lines contains eight pixels. That means that there are 256 possible combinations of pixels in each line. (2 possible values [on or off] to the 8th power). So, the numbers 0 - 255 match the 256 possible horizontal lines. Further, far from being random values, they're instead ordered in a logical, binary sequence. The first number, 0, is an entirely blank line. If "0" equals a blank pixel, and "1" equals a painted pixel, line 0 would look like this:


The next line, 1, would look like this:


In turn, lines 2 - 10 would be as follows:

00000010 = 2 (compare this with the "2" line in the letter "S" above)
00000011 = 3
00000100 = 4
00000101 = 5
00000110 = 6
00000111 = 7
00001000 = 8
00001001 = 9
00001010 = 10

Can you see the binary sequence? Of course, line 255 would be this:

11111111 = 255

Although I won't map out all of the 256 font "strips" for you, it would be trivial for you to do this on your own. And to create your own font, you would merely need to match the eight appropriate font strip numbers to the character you were creating. (Then, repeat for the other 255 characters). For more fun, you can even skip over the characters you won't be using by using eight zeros instead.

Of course, this process can be time consuming. Instead, you may find it useful to use a simple program called FontBuilder that I've developed. FontBuilder provides a basic graphical interface for drawing the characters for a new font. When you're finished, it figures out what font strips are needed, and it writes the font file (or char array) for you. See the SVGAlib website for a copy. What a relief!

Scalable Fonts

After all that effort, though, you still can't avoid the fact that bitmapped fonts are less than perfect. They *are* easy to use, but they just don't cut it, so far as serious presentations go. Wouldn't it be nice to be able to use regular fonts like those found in the Windows and Mac world? Finally, you can.

Thanks to a recent and highly successful project called FreeType (, TrueType fonts are now available for console graphics. The actual routines for screen rendering were ported from X11 to SVGAlib by the SVGAlib maintainer, Matan Ziv-Av. Thanks, Matan!

The first step is to download, compile, and install the FreeType libraries. These go into the /usr/local/lib directory, so you'll probably need to run ldconfig afterwards to re-synch (re-cache) the libraries in your system. Note that you'll have to edit your Makefile if you don't have X11 installed on your system -- you'll need to remove all references to the X Windows test programs, or you'll get some compile-time errors.

Next, you can download the SVGAlib demos from Matan Ziv-Av's site:

This will show you how to integrate FreeType into your own programs.

Before you can display anything, however, you'll need a TrueType font. I simply copied arial.ttf from my Windows machine. You'll find all your fonts in C:\WINDOWS\FONTS, assuming you have a standard install.


Hopefully this article helped to clear up the air of mystery surrounding fonts and text in SVGAlib. Once you've written a program or two involving fonts, you'll find that they're just as easy to implement as anything else in console graphics. What's more, you might want to contribute your own bitmapped font to the SVGAlib site! Just send it to, and you'll get full credit. See, isn't Open Source fun?

Related Resources

  1. SVGAlib home page Web-based resource to download the most recent version of SVGAlib, ask for help and read tutorials.
  2. Brion Vibber's FAQ More help for SVGAlib developers.
  3. SVGAlib mailing list The Rutgers mailing list. Very helpful.
  4. SVGAlib development site Matan Ziv-Av's home page. You'll find the latest beta version of SVGAlib here.
  5. FreeType A Free, Quality, and Portable Font Engine.

Jay Link is twenty-something and lives in Springfield, IL. He administrates InterLink BBS - an unintentionally nonprofit Internet service provider - in his fleeting spare moments as well as working various odd jobs to pay the rent.

Page 2 of 2

Previous Page
1 2

0 Comments (click to add your comment)
Comment and Contribute


(Maximum characters: 1200). You have characters left.



IT Management Daily
Don't miss an article. Subscribe to our newsletter below.