sextile.viewdata.font

Fonts for lettering drawn out of block graphics, and the file they live in.

A mosaic font is a bitmap font measured in blocks rather than pixels: a letter eight blocks tall is two and two-thirds cells tall on the screen, and a banner made of them is drawn with blocks.block_runs like any other picture.

The format is this project’s own, and a text file. A vendored font is third-party material that has to be reviewed and whose terms have to travel with it, which a binary blob makes nobody do; and none of the formats these faces arrive in carries the one thing most needed here, an advance for each glyph. A row is 78 blocks wide and ten letters at a fixed eight blocks do not fit in it, so proportional spacing is a requirement rather than a refinement – and the width to advance by is a property of the face, set once by whoever converts it, not re-derived on every frame. Deriving it would also give a space no width at all.

The file is its own documentation:

name: Acorn source: MDFS ArcNormal (mdfs.net/Apps/Font/Fonts1.zip) terms: Free for public use height: 8 fixed: 8

glyph u+0041 advance 7 bearing 1 A ..##.. .####. ##..## …

Glyphs are named by code point rather than by the character itself, so that a space, a # and a . need no quoting in a file whose other lines are pictures made of # and .. The note at the end is for the reader and is ignored. A glyph with no picture is blank, as a space is.

The picture is the letter and nothing else: the blank columns either side are trimmed away, since proportional setting places the letter and lets the advance supply the gap after it. The bearing keeps fixed-width setting possible – it records how far in from the left the ink sat in the face’s own design width, so a fixed setting can put it back where the designer had it rather than jamming every letter against the left of its cell.

Reading it needs nothing but the standard library, deliberately: a font is loaded when a page is drawn.

class sextile.viewdata.font.Font(name, height, fixed, glyphs, source='', terms='')[source]

Bases: object

A face: its glyphs, its height, and where it came from.

fixed is the advance a fixed-width setting uses – the face’s own design width, before any trimming. Proportional and kerned settings use the glyphs’ own advances instead.

Parameters:
glyph(character)[source]

The glyph for a character, substituting rather than raising.

A font with no question mark of its own leaves a gap of the fixed width, which is at least the shape of a missing letter.

Parameters:

character (str)

Return type:

Glyph

exception sextile.viewdata.font.FontError[source]

Bases: ValueError

A font file that cannot be read or parsed.

class sextile.viewdata.font.Glyph(bitmap, advance, bearing=0)[source]

Bases: object

One letter: the blocks it lights, and how far the next one starts along.

The advance is not the width. It is the width plus the gap the face leaves after this letter, and for a space it is a gap and nothing else. The bearing is where the ink sat within the face’s design width, kept so that a fixed-width setting can put a trimmed glyph back where it belongs.

Parameters:
classmethod of(rows, advance, bearing=0)[source]

A glyph from a picture, # for a lit block; short rows end in blanks.

Parameters:
Return type:

Glyph

sextile.viewdata.font.font_names()[source]

The faces the framework ships, in a fit state to be offered to a caller.

Return type:

tuple[str, ...]

sextile.viewdata.font.load_font(name)[source]

A face shipped with the framework, by name.

Cached: a font is some thousands of lines of picture, and a page that draws a banner should not pay for parsing it twice.

Parameters:

name (str)

Return type:

Font

sextile.viewdata.font.read_font(text)[source]

Parse a font file. Raises FontError, naming the line, on anything odd.

Parameters:

text (str)

Return type:

Font