sextile.viewdata.yaff

Reading a YAFF bitmap font into a mosaic Font.

YAFF is the text bitmap-font format of the monobit toolkit, and the form the hoard-of-bitfonts collection ships in (github.com/robhagemans/hoard-of-bitfonts). A YAFF pixel is one mosaic block, so a YAFF glyph is a Font glyph already; this reads the subset a Font needs and drops the rest, so a service can set large lettering in a face it did not have to vendor.

What is read: character-cell glyphs labelled by character – a unicode label (u+0041) or a quoted character ('A') – their ./@ bitmaps, and the cell-size. A glyph’s blank side columns are trimmed, the left becoming its bearing and the right its advance, so a loaded face sets proportionally like a native one; fixed keeps the cell width for anyone setting fixed. copyright, notice and author become the font’s terms and a source-* its source, so a loaded font’s licence travels with it.

A YAFF glyph also carries a device codepoint label (0x23) which is the font’s own character set, not ASCII – 0x23 is £ in the SAA5050 set – so a glyph is keyed by its unicode or character label and the bare codepoint is ignored.

What is ignored: vertical metrics, kerning tables, shift-up, tag and multi-codepoint labels, and metadata beyond the licence. Greyscale (levels above two) and a glyph whose height is not the cell’s are refused with FontError rather than read wrongly.

sextile.viewdata.yaff.read_yaff(text)[source]

Parse a YAFF font into a Font. Raises FontError, naming what is wrong.

Parameters:

text (str) – The contents of a YAFF file.

Return type:

Font

Returns:

A Font of the character-cell glyphs the file labels by character.

Example

>>> from pathlib import Path
>>> font = read_yaff(Path("saa5050-uk.yaff").read_text("utf-8"))