Homebrew, open source, repurposed, hacked, software defined, open hardware

Monday, 27 June 2016

Outline font to centreline defined font and SVG conversion for gEDA PCB

Donald Knuth spent around a decade crafting a solution to the problem of reproducing fonts on different systems with varying screen resolutions and printer resolutions, and came up with Metafont.

Metafont enables glyphs to be compactly defined with strokes with various brush sizes and shapes, and an output file produced containing the necessary information to render the glyph at the selected resolution as a bitmap, whether it be on screen, or on a printer.

Metafont is therefore a stroked font, and differs to outline fonts such as those described by truetype or postscript fonts, which define the outline of the glyph, and fill the central portions.

Metafont glyphs can be hard to describe in terms of outlines, and various people have ported Metafont defined fonts to Truetype and Postscript, with some difficulty, owing to the complexity of converting a path describing the movement of a pen's shape, into a path defining the envelope of its travel.

Outline defined fonts lend themselves well to rendering on screen at various scales, but are not as useful for plotters, engraving or pcb design, where the pen, cutting bit or silkscreen line has a finite minimum size.

So, for PCB design, the output file of choice is the Gerber file, which defines features as lines, polygons and flashed apertures. A font used for copper or silkscreen lines must use these design elements to reproduce the text. The Gerber file was originally created to work with photo-plotters, and it's feature set reflects this.

Accordingly, the choices available for depicting text on a PCB are a bitmapped raster, lines, or polygons, with any of these needing to be equal to or larger than the minimum silk screen line size that can be reliably reproduced, typically in the order of 6-10mil, where 1 "mil" is a thousandth of an inch, or 25.4 microns.

Tools for font design such as FontForge are eminently suited to outline defined font creation, but less suited to centreline defined font creation. The only vaguely useful suggestions to be found on the internet for this conversion were the use of CorelDraw's centreline filter/function; not exactly a FOSS solution.

The brief, then, was how to convert existing outline defined fonts, such as the open source CAD font:


to a stroked format suited to plotters, Gerbers, and engravers, and related devices such as the Eggbot.

Fonts such as the free, GPL CAD font osifont can be readily obtained in Truetype (ttf) format.

The first task was to convert this to a format easily parsed. It turns out that this can be done with the Apache Batik utility ttf2svg:


Custom code has been written to convert the SVG font file created by ttf2svg into line elements within footprints for gEDA PCB. This is an example of the Hebrew Aleph, Unicode x5d0, converted from Maxim Iorsh's GPL 2.0 Miriam-CLM font:


Here is a direct conversion of the outline to a gEDA PCB footprint

This SVG path parsing code will also be added to translate2geda in due course, to allow custom board outlines and vector graphics to be turned into footprints. Each quadratic bezier is drawn with six lines, which seems to give pretty smooth results.

This particular font was chosen for experimentation since the limbs of the font are of fairly uniform thickness, and the font is sans serif, simplifying conversion to a stroked font.

It turns out that gEDA PCB is a convenient tool for viewing converted stroked font glyphs, as well as being a target for the converted fonts.

The utility can be used to suppress endcaps, serifs, fillets and small degenerate vertical lines, and here is the output for Aleph with these filters enabled:

If the above filters are combined with centreline generation, the following output results: 

The utility will automatically analyse a group of glyphs to establish the limb width, allowing the centreline to be generated accurately. The limb width can be specified manually, however, with a suitable command line flag. The utility also extracts the font ascent and descent values to automatically scale the output consistently for all glyphs processed in an SVG font file.

With some minor hand tweaking of the design elements in the output file, the following results:

At this stage, most of the work has been done by the utility to create a centreline defined glyph.

Some additional work is needed for the utility to automatically connect isolated limbs to other limbs, and censor the redundant lines automatically.

The next step will be to convert the footprint into a format suited to font use within gEDA PCB or the footprintTextForPCB utility, or as a set of vector paths.

The utility is still a work in progress, and can be found at:


If this seems like a lot of work, font designers spend many hours slaving over FontForge and the like to create aesthetically pleasing fonts. This utility leverages this design work and allows conversion into centreline defined formats to be achieved quite quickly and accurately by comparison.

In closing, this approach would also work to automatically create a gerber/plotter compatible font from a truetype source without determining the centreline, by simply following the outlines with a suitable offset inwards and stroke width, but would make for a less compact glyph, and more bloated gerber or gcode, as each limb or loop of the glyph would include endcaps, and the two edges of any given limb or loop.