A Journey Through Font Rendering

In the wide world of programming, there are a few dark corners that many prefer to avoid and instead leverage the well-vetted libraries that are already there. [Phillip Tennen] is not one of those people, and when the urge came to improve font rendering for his hobby OS, axle, he got to work writing a TrueType font renderer.

For almost a decade, the OS used a map table encoding all characters as 8×8 bitmaps. While scaling works fine, nonfractional scaling values are hard to read, and fractional scaling values are jagged and blocky. TrueType and font rendering, in general, are often considered dark magic. Font files (.ttf) are structured similarly to Mach-O (the binary format for macOS), with sections containing tagged tables. The font has the concept of glyphs and characters. Glyphs show up on the screen, and characters are the UTF/Unicode values that get translated into glyphs by the font. Three critical tables are glyf (the set of points forming the shape for each glyph), hmtx (how to space the characters), and cmap (how to turn Unicode code points into glyphs).

Seeing the curtain pulled back from the format itself makes it seem easy. In reality, there are all sorts of gotchas along the way. There are multiple types of glyphs, such as polygons, blanks, or compound glyphs. Sometimes, control points in the glyphs need to be inferred. Curves need to be interpolated. Enclosed parts of the polygon need to be filled in. And this doesn’t even get to the hinting system.

Inside many fonts are tiny programs that run on the TrueType VM. When a font is rendered at low enough resolutions, the default control points will lose their curves and become blobs. E’s become C, and D’s become O’s. So, the hinting system allows the font to nudge the control points to better fit on the grid. Of course, [Phillip] goes into even more quirks and details in a wonderful write-up about his learnings. Ultimately, axle has a much better-looking renderer, we get a great afternoon read, and fonts seem a little less like forbidden magic.

Maybe someday [Phillip] will implement other font rendering techniques, such as SDF-based text renderers. But for now, it’s quite the upgrade. The source code is available on GitHub.

Little Printer Dispenses Short Stories

We know how it happens. You buy a fancy new label printer, thinking this is the answer to your disorganized space, but soon entropy grabs the printer as well, and it becomes just another item in the pile. When you find such items later, though, they can spark ideas. The idea that struck [Eric Nichols] was to turn his diminutive thermal printer into a dedicated one for short stories.

Inspired by an article about a vending machine that dispenses stories selected by the reader’s time constraints, [Eric] took on the task of getting his Dymo LabelWriter 400 Turbo working in this new capacity. The first task was finding some continuous roll paper that would fit, because the official stock for this thing is all labels. He got lucky on the first try and a roll of 2 7/16″ receipt paper fit the bill perfectly.

The printer itself doesn’t have much brains; it prints bitmaps 672 bits wide, and as long as you care to make them. While the initial experiments succeeded in printing graphics, [Eric] needed a way to convert his stories to bitmapped text to send to the printer. The human-readable font file format known as BDF (glyph Bitmap Distribution Format) was a perfect fit, since a library to render it was readily available. On top of that, the open-source tool otf2bdf will convert a TrueType (TTF) font to BDF, completing his font-rendering chain.

[Eric] has these printers working with both Linux and windows, either one running on a PC where his software resides, and has it all well-documented on his site. With this in place, it’s simply a matter of coming up with the stories to print. We think it would be perfect for Hackaday dailies!

We’ve seen interesting hacks with disused printers before, like this ascii-art generating cartridge.

How To Create TrueType From An Image


[Viacheslav] wanted his virtual terminal to have the look of a DEC VT220. He was unable to find a font set that looked just right so he set out to make his own TrueType font. He managed to find a sample image of the glyphs that the VT220 used as fonts. Using a collection of free software he sliced the image into 256 different parts, resized and converted to one-bit index images, and converted these to vector graphics. This was accomplished with a bit of python, an image tracing program, and font editor called FontForge.

Take some time to dabble with these font tools. With an adequate sample you should be able to reproduce any font set. We won’t achieve anything as sophisticated as the font printed with bacteria, but this will be a start in the right direction.