text

Mon, 02 Oct 2006 22:05:43 -0700

Revisiting Childhood's Text

Recall that the main goal of the twin window system is to fit in no more than 50KB. For text, that meant that I couldn't just take an existing TrueType font and use the FreeType rasterizer to scanconvert each glyph. (FreeType weighs in at over 400KB on an x86 machine)

Instead, some significantly smaller solution was needed. One easy solution was to just take outlines from some font, convert them to a compact format and rasterize them with the existing twin drawing code. I gave this a whirl with the Bitstream Vera Sans Roman type face. The results of that experiment are available here. As you can see, the lack of hinting makes the glyphs very fuzzy all over. It's a long ways from the quality available on my laptop screen, but it is workable and provides access to a huge set of fonts.

Converting the outlines was easy enough, and without any compression, the ASCII subset of vera fits in about 7KB of memory, using 1-byte for each coordinate. Increasing coverage to Latin-1 and it uses 16KB.

So, that's a workable solution, but not ideal because of the poor readability of the text. I had another idea, but needed to google for some really old data...

In 1979, I built a graphics library for an atmospheric sciences group that I worked with. The goal was to provide an interactive graphing environment on our VAX 11/780 which included a 512x512 8-bit color display, as well as produce hard-copy plots for publication on an HP pen plotter. Drawing the images on the screen was simple enough, but I needed a way to get text on the screen. I found some stroke fonts, originally developed in the 1960s by Dr. A. V. Hershey at the US Naval Weapons Laboratory. These worked just fine for my little graphics application.

Fortunately, it wasn't hard to locate the original Hershey data set. Armed with that, it was a short nickle script from there to C structures containing the entire repertoire of glyphs.

You can see most of the Hershey glyph set here

I was surprised to realize that the simple sans serif face didn't include all of the symbols from ASCII. So, I borrowed a few from other face and built the remaining from pieces of other glyphs.

Just drawing the glyphs and convolving them with a circular pen produced quite reasonable results. However, any significant scaling produced lots of fuzzy bits again. Because the glyph data consists of strokes, I thought I could try to 'snap' positions to the pixel grid and eliminate a lot of the gray matter at glyph edges.

Integerizing the glyph coordinates yielded a surprisingly readable result as seen here. Of course, the letter forms are badly distorted in places, but at least the horizontal and vertical elements are nice and sharp

Armed with that encouraging result, I set out to snap only the elements which would actually benefit from pixel alignment -- those horizontal and vertical edges. That turned out to be quite easy; stretching and shrinking the character in each direction between the various fixed alignment points. The initial results for that test are here.

With simple stroke data, it's easy to change the pen width to make the glyphs 'bolder', and easy enough to slant the text to make it appear oblique. Neither of these changes require any additional glyph data. The final set of glyphs can be seen here.

There is still some issue with glyph widths that I haven't quite solved; I think it has to do with normalizing the space from the right-most point in the glyph to the next glyph origin.