font module#

A single-stroke font for legend text, ported from the ODB++ exporter.

Gerber has no native text (5.7), so a reference designator on the silkscreen is a run of D01 draws with a small circular aperture. A stroke font is the natural fit: Gerber draws already have round caps and joins, so a polyline maps onto draws with no region or outline handling at all.

The glyphs are jitxlib-odb’s format/font.py taken as they stand. They are honest placeholder work - crude, hand-authored, lowercase reusing the uppercase strokes - and taking them as-is is deliberate: a legend with crude reference designators is assembly documentation and a legend with none is not. Replacing them with a real single-stroke font is self-contained and touches nothing outside this module.

Glyph coordinates live in a cell with x in [L, R] and y in [B, T], which is 0.1 wide by 0.3 tall. strokes scales that cell so the glyph height is the text size, and lays the characters out left to right.

CELL_HEIGHT = 0.30000000000000004#

Glyph height in glyph units. One text size maps onto this.

CELL_WIDTH = 0.1#

Glyph width in glyph units.

ADVANCE = 0.18#

the glyph plus its right gap.

Wider than the glyph on purpose - 0.1 of ink and 0.08 of air - so adjacent characters do not touch once the stroke aperture is added on both sides.

Type:

Pen advance per character in glyph units

STROKE_RATIO = 0.1#

Stroke width as a fraction of the text size.

The aperture diameter, not a glyph property, which is why it is not the _W the ODB font carries: that value is an ODB++ line width in the font file’s own units. A tenth of the cap height is legible at silkscreen resolution and stays above the 0.1 mm line width fabs typically floor at for the text sizes a board actually uses.

GLYPHS: dict[str, list[list[tuple[float, float]]]] = {' ': [], '!': [[(0, 0.2), (0, 0)], [(0, -0.1), (0, -0.1)]], '"': [[(-0.03, 0.2), (-0.03, 0.13)], [(0.03, 0.2), (0.03, 0.13)]], '#': [[(-0.025, -0.1), (-0.025, 0.2)], [(0.025, -0.1), (0.025, 0.2)], [(-0.05, 0), (0.05, 0)], [(-0.05, 0.1), (0.05, 0.1)]], '$': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, 0.05), (0.05, 0.05), (0.05, -0.1), (-0.05, -0.1)], [(0, -0.12), (0, 0.22)]], '%': [[(-0.05, -0.1), (0.05, 0.2)], [(-0.05, 0.2), (-0.05, 0.2)], [(0.05, -0.1), (0.05, -0.1)]], '&': [[(0.05, -0.1), (-0.05, 0.1), (0, 0.2), (0.03, 0.1), (-0.05, -0.02), (0, -0.1), (0.05, 0.02)]], "'": [[(0, 0.2), (0, 0.13)]], '(': [[(0.03, 0.2), (-0.03, 0.05), (0.03, -0.1)]], ')': [[(-0.03, 0.2), (0.03, 0.05), (-0.03, -0.1)]], '*': [[(-0.05, 0), (0.05, 0.1)], [(-0.05, 0.1), (0.05, 0)], [(0, -0.02), (0, 0.12)]], '+': [[(-0.05, 0.05), (0.05, 0.05)], [(0, -0.02), (0, 0.12)]], ',': [[(0.01, -0.08), (-0.01, -0.13)]], '-': [[(-0.05, 0.05), (0.05, 0.05)]], '.': [[(0, -0.1), (0, -0.1)]], '/': [[(-0.05, -0.1), (0.05, 0.2)]], '0': [[(-0.05, -0.1), (0.05, -0.1), (0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1)], [(-0.05, -0.1), (0.05, 0.2)]], '1': [[(-0.03, 0.15), (0, 0.2), (0, -0.1)]], '2': [[(-0.05, 0.2), (0.05, 0.2), (0.05, 0.05), (-0.05, 0.05), (-0.05, -0.1), (0.05, -0.1)]], '3': [[(-0.05, 0.2), (0.05, 0.2), (0.05, -0.1), (-0.05, -0.1)], [(-0.05, 0.05), (0.05, 0.05)]], '4': [[(-0.05, 0.2), (-0.05, 0.05), (0.05, 0.05)], [(0.05, 0.2), (0.05, -0.1)]], '5': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, 0.05), (0.05, 0.05), (0.05, -0.1), (-0.05, -0.1)]], '6': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1), (0.05, 0.05), (-0.05, 0.05)]], '7': [[(-0.05, 0.2), (0.05, 0.2), (0, -0.1)]], '8': [[(-0.05, -0.1), (0.05, -0.1), (0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1)], [(-0.05, 0.05), (0.05, 0.05)]], '9': [[(-0.05, -0.1), (0.05, -0.1), (0.05, 0.2), (-0.05, 0.2), (-0.05, 0.05), (0.05, 0.05)]], ':': [[(0, 0.1), (0, 0.1)], [(0, -0.05), (0, -0.05)]], ';': [[(0, 0.1), (0, 0.1)], [(0.01, -0.05), (-0.01, -0.1)]], '<': [[(0.05, 0.2), (-0.05, 0.05), (0.05, -0.1)]], '=': [[(-0.05, 0.08), (0.05, 0.08)], [(-0.05, 0), (0.05, 0)]], '>': [[(-0.05, 0.2), (0.05, 0.05), (-0.05, -0.1)]], '?': [[(-0.05, 0.15), (0, 0.2), (0.05, 0.15), (0.05, 0.1), (0, 0.05), (0, 0)], [(0, -0.1), (0, -0.1)]], '@': [[(0.05, -0.1), (-0.05, -0.1), (-0.05, 0.2), (0.05, 0.2), (0.05, 0), (0, 0), (0, 0.1)]], 'A': [[(-0.05, -0.1), (0, 0.2), (0.05, -0.1)], [(-0.03, 0), (0.03, 0)]], 'B': [[(-0.05, -0.1), (-0.05, 0.2), (0.05, 0.2), (0.05, 0.05), (-0.05, 0.05), (0.05, 0.05), (0.05, -0.1), (-0.05, -0.1)]], 'C': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1)]], 'D': [[(-0.05, -0.1), (-0.05, 0.2), (0.02, 0.2), (0.05, 0.13), (0.05, -0.03), (0.02, -0.1), (-0.05, -0.1)]], 'E': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1)], [(-0.05, 0.05), (0.02, 0.05)]], 'F': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1)], [(-0.05, 0.05), (0.02, 0.05)]], 'G': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1), (0.05, 0.05), (0, 0.05)]], 'H': [[(-0.05, 0.2), (-0.05, -0.1)], [(0.05, 0.2), (0.05, -0.1)], [(-0.05, 0.05), (0.05, 0.05)]], 'I': [[(0, 0.2), (0, -0.1)], [(-0.05, 0.2), (0.05, 0.2)], [(-0.05, -0.1), (0.05, -0.1)]], 'J': [[(0.05, 0.2), (0.05, -0.1), (-0.05, -0.1), (-0.05, -0.02)]], 'K': [[(-0.05, 0.2), (-0.05, -0.1)], [(0.05, 0.2), (-0.05, 0.05), (0.05, -0.1)]], 'L': [[(-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1)]], 'M': [[(-0.05, -0.1), (-0.05, 0.2), (0, 0.05), (0.05, 0.2), (0.05, -0.1)]], 'N': [[(-0.05, -0.1), (-0.05, 0.2), (0.05, -0.1), (0.05, 0.2)]], 'O': [[(-0.05, -0.1), (0.05, -0.1), (0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1)]], 'P': [[(-0.05, -0.1), (-0.05, 0.2), (0.05, 0.2), (0.05, 0.05), (-0.05, 0.05)]], 'Q': [[(-0.05, -0.1), (0.05, -0.1), (0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1)], [(0, -0.02), (0.06, -0.1)]], 'R': [[(-0.05, -0.1), (-0.05, 0.2), (0.05, 0.2), (0.05, 0.05), (-0.05, 0.05)], [(0, 0.05), (0.05, -0.1)]], 'S': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, 0.05), (0.05, 0.05), (0.05, -0.1), (-0.05, -0.1)]], 'T': [[(-0.05, 0.2), (0.05, 0.2)], [(0, 0.2), (0, -0.1)]], 'U': [[(-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1), (0.05, 0.2)]], 'V': [[(-0.05, 0.2), (0, -0.1), (0.05, 0.2)]], 'W': [[(-0.05, 0.2), (-0.025, -0.1), (0, 0.05), (0.025, -0.1), (0.05, 0.2)]], 'X': [[(-0.05, 0.2), (0.05, -0.1)], [(0.05, 0.2), (-0.05, -0.1)]], 'Y': [[(-0.05, 0.2), (0, 0.05), (0.05, 0.2)], [(0, 0.05), (0, -0.1)]], 'Z': [[(-0.05, 0.2), (0.05, 0.2), (-0.05, -0.1), (0.05, -0.1)]], '\\': [[(-0.05, 0.2), (0.05, -0.1)]], '_': [[(-0.05, -0.1), (0.05, -0.1)]], 'a': [[(-0.05, -0.1), (0, 0.2), (0.05, -0.1)], [(-0.03, 0), (0.03, 0)]], 'b': [[(-0.05, -0.1), (-0.05, 0.2), (0.05, 0.2), (0.05, 0.05), (-0.05, 0.05), (0.05, 0.05), (0.05, -0.1), (-0.05, -0.1)]], 'c': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1)]], 'd': [[(-0.05, -0.1), (-0.05, 0.2), (0.02, 0.2), (0.05, 0.13), (0.05, -0.03), (0.02, -0.1), (-0.05, -0.1)]], 'e': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1)], [(-0.05, 0.05), (0.02, 0.05)]], 'f': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1)], [(-0.05, 0.05), (0.02, 0.05)]], 'g': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1), (0.05, 0.05), (0, 0.05)]], 'h': [[(-0.05, 0.2), (-0.05, -0.1)], [(0.05, 0.2), (0.05, -0.1)], [(-0.05, 0.05), (0.05, 0.05)]], 'i': [[(0, 0.2), (0, -0.1)], [(-0.05, 0.2), (0.05, 0.2)], [(-0.05, -0.1), (0.05, -0.1)]], 'j': [[(0.05, 0.2), (0.05, -0.1), (-0.05, -0.1), (-0.05, -0.02)]], 'k': [[(-0.05, 0.2), (-0.05, -0.1)], [(0.05, 0.2), (-0.05, 0.05), (0.05, -0.1)]], 'l': [[(-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1)]], 'm': [[(-0.05, -0.1), (-0.05, 0.2), (0, 0.05), (0.05, 0.2), (0.05, -0.1)]], 'n': [[(-0.05, -0.1), (-0.05, 0.2), (0.05, -0.1), (0.05, 0.2)]], 'o': [[(-0.05, -0.1), (0.05, -0.1), (0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1)]], 'p': [[(-0.05, -0.1), (-0.05, 0.2), (0.05, 0.2), (0.05, 0.05), (-0.05, 0.05)]], 'q': [[(-0.05, -0.1), (0.05, -0.1), (0.05, 0.2), (-0.05, 0.2), (-0.05, -0.1)], [(0, -0.02), (0.06, -0.1)]], 'r': [[(-0.05, -0.1), (-0.05, 0.2), (0.05, 0.2), (0.05, 0.05), (-0.05, 0.05)], [(0, 0.05), (0.05, -0.1)]], 's': [[(0.05, 0.2), (-0.05, 0.2), (-0.05, 0.05), (0.05, 0.05), (0.05, -0.1), (-0.05, -0.1)]], 't': [[(-0.05, 0.2), (0.05, 0.2)], [(0, 0.2), (0, -0.1)]], 'u': [[(-0.05, 0.2), (-0.05, -0.1), (0.05, -0.1), (0.05, 0.2)]], 'v': [[(-0.05, 0.2), (0, -0.1), (0.05, 0.2)]], 'w': [[(-0.05, 0.2), (-0.025, -0.1), (0, 0.05), (0.025, -0.1), (0.05, 0.2)]], 'x': [[(-0.05, 0.2), (0.05, -0.1)], [(0.05, 0.2), (-0.05, -0.1)]], 'y': [[(-0.05, 0.2), (0, 0.05), (0.05, 0.2)], [(0, 0.05), (0, -0.1)]], 'z': [[(-0.05, 0.2), (0.05, 0.2), (-0.05, -0.1), (0.05, -0.1)]]}#

Every glyph, with the lowercase letters reusing the uppercase strokes.

stroke_width(size)[source]#

The aperture diameter legend text of this size is stroked with.

Return type:

float

Parameters:

size (float)

extents(text, size)[source]#

The (width, height) of the box text occupies at this size.

The box is the ink, not the cells: the inter-character gap after the last character is not part of it. That matters because the anchor is measured against this box, and a centred reference designator built from cell widths sits visibly off-centre by half a gap.

Return type:

tuple[float, float]

Parameters:
strokes(text, size, origin=(0.0, 0.0))[source]#

The polylines that draw text, in the text shape’s own frame.

Parameters:
  • size (float) – the cap height. Glyphs scale uniformly, so the aspect ratio the font was drawn at is preserved.

  • origin (tuple[float, float]) – the lower-left corner of the box extents describes.

  • text (str)

Return type:

list[list[tuple[float, float]]]

Characters the font has no glyph for are skipped rather than substituted, and the pen still advances, so a missing glyph leaves a gap instead of shifting the rest of the string.