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.

Tuesday, 3 May 2016

Adding images to the silkscreen in gEDA PCB

There are a few ways to add images to the silkscreen layer in gEDA PCB.

On method is to use potrace or Inkscape to create a postscript file, and then use pstoedit to generate PCB layout data to insert into a layout; this is well described at:


and at:



using potrace to convert an image to eps:

potrace -o picture.eps -H .4 -W .5 picture.bmp

Or save a picture as eps from Inkscape...

Then use pstoedit to turn it into PCB layout data:

pstoedit -f pcbfill picture.eps picture.pcb -ssp

Another option is to turn an image into a footprint.

I have written a small utility to convert jpeg or png images into a gEDA PCB footprint which has dots in the silkscreen layer of the footprint.

The size of each dot is based on the luminosity of each corresponding pixel in the original image.

The utility can be found at:


It is assumed that the pixels will be white silkscreen dots on a dark background soldermask on the manufactured PCB.

Unwanted features or transparent layers should be coloured black with a graphics editor like the gimp before conversion with the utility.

An additional use is to convert a photograph of a PCB into a footprint. Use of a graphic editor like the GIMP in such a scenario can be used to increase the contrast between the tracks and surrounding fibreglass, and provide an image against which tracks can be laid in gEDA PCB to duplicate the original PCB. Manually highlighting pads with white dots in the image before conversion would also simplify snapping elements to the PCB features. Ensuring the source image is sized to match the original PCB, and that a suitable dot pitch is selected to ensure the footprint width and height equal the PCB's width or height should allow for relatively accurate and rapid duplication of an existing PCB from a photograph or scan.

A source image

The footprint in PCB:

A rendered gerber of the exported footprint:

Saturday, 30 April 2016

Importing or converting gerber files into gEDA PCB layouts

Being able to convert gerber files into pcb layouts can be useful for a couple of reasons, namely:

- acquiring exotic footprints
- modifying existing designs
- reverse engineering designs
- snatching previous design efforts from the jaws of obsolescent, closed EDA software products, forced upgrade paths, or cloud based services

Luckily, most of the hard work was done at the turn of the century by Philipp Knirsch, who wrote some gerber parsing code in java that can be used to render gerbers. Philipp licensed his gerber parsing code as GPL2:


The code was modified to play nicely with translate2geda as a conversion option, and now exports gEDA PCB elements in a footprint file.

The footprint file allows new tracks and pads to be snapped to the locations very easily, and since each feature in the footprint file is uniquely numbered, mouse over on the features allows the identifier to be determined, and using the unique identifiers, the element or elements can be copied from the footprint file with a text editor, for example, if a grouping of elements is needed to duplicate a footprint.

I may try to implement layout export with tracks and pads in different layers, but this will be complicated, since some EDA tools paint features such as pads, polygons and tracks, rather than flashing them, making it hard to determine which features are pads vs trackwork.

Only four sided polygons are supported currently, in order to identify rectangular pads which have not been flashed. This may be extended to capture octagonal pads, such as those supported by Eagle and gEDA PCB, and the gEDA PCB fork pcb-rnd.

Ground pour polygons and other complex polygons will not be supported, unless I implement the layout export option, since gEDA footprints do not support arbitrary polygons.

Here's a bottom copper layer gerber viewed in gerbv:

and here's the output from the translate2geda utility being viewed in gEDA PCB

To use the translate2geda utility to convert gerbers like this, you'll need to get yourself on over to github, get the java source and follow the build and use instructions.

I hope to implement Kicad export once the wrinkles have been ironed out and the translate2geda code refactored a bit.

The translate2geda utility will also convert manufacturer agnostic BXL files, Eagle XML libraries, BSDL (.bsd) files, IBIS (.ibs), symdef, LT-Spice and QUCS files into gEDA gschem and gEDA PCB compatible footprint and schematic symbols as well.

The KicadModuleToGEDA and KicadSymbolToGEDA  functionality will be merged into the translate2geda utility in due course, adding Kicad Symbol and Footprint conversion to gEDA gschem and PCB  formats as well.

Thursday, 3 March 2016

Converting IBIS, BXL, BSDL, symdef, Eagle, and Kicad design elements to gEDA

It's turning into something of a compulsion, but after writing the code for converting legacy and s-expression format Kicad footprints (modules) to gEDA PCB compatible footprints:


a converter for Kicad symbols, to convert them to gEDA gschem compatible symbols, seemed like the logical thing to do next:


With the basic software objects written, extending them with additional methods to support additional formats became easier and easier, and I have now put a working version of translate2geda on github:


It currently supports conversion of the following formats into symbols and footprints compatible with the FOSS gEDA EDA suite:

Eagle footprints (in XML .lbr files)
Eagle symbols (in XML .lbr files)
vendor neutral BXL files
BSDL files
IBIS files
symdef files

When time permits, I plan to incorporate the original Kicad module and symbol converter code into the now more modular translate2geda code. Until then, the individual converters can be used by those keen to convert Kicad design elements.

In addition, support for the upverter (.upv) open format is planned, and gerber -> footprint/layout is a work in progress.

Once things are behaving, I intend to implement export to Kicad as well. This should not be hard, since much of the code relies on Kicad flags and dimensions, around  which the original solution was designed.

With that done, export to Eagle is also planned, since they were nice enough to implement an open XML format.

FOSS EDA suites should ideally leverage each other's efforts, rather than reinventing the wheel, and being able to share symbols and footprints is an obvious way to do this.

Stretch goal:

schematic conversion

Here's a simple board intended for use in an eggbot designed in gEDA PCB, using an Arduino nano footprint, TO-220 footprint, electrolytic capacitor footprints, and a DIP16 Pololu footprint imported from Kicad modules.

The schematic used to design the circuit in gschem used symbols also imported from Kicad.

The board has deliberately been designed to be compact, since I aimed to fit it within a 5cm x 5cm layout, one of the sizes that gets preferential pricing with my usual PCB supplier, hackvana.com