tituli.shaping

Optional engine: HarfBuzz shaping + FreeType rendering (pip install tituli[shaping]).

The Pillow default handles Latin text well and rotates glyph bitmaps. This engine shapes the run with HarfBuzz (kerning, ligatures, Arabic/Devanagari joining) and asks FreeType to apply the rotation to the outline before rasterising, which is the typographically correct order. Same Run in, same canvas out — it is the engine= seam of tituli.render.render().

Import cost is paid only when constructed; the module itself imports nothing optional at top level.

Functions

shape(text, path, index, size, *[, ...])

[(glyph_id, x_advance, y_advance, x_offset, y_offset), ...] in pixels.

Classes

HarfBuzzEngine()

Draw runs through HarfBuzz + FreeType.

class tituli.shaping.HarfBuzzEngine[source]

Bases: object

Draw runs through HarfBuzz + FreeType. Falls back to Pillow for the embedded font.

draw_run(canvas, run, opacity)[source]

Draw run onto canvas at the given opacity.

Return type:

None

length(face, text)[source]

Advance of text as this engine shapes it (kerning, ligatures).

Return type:

float

measurer(face)[source]

The engine that measures and draws face: Pillow for the embedded font (it has no file to shape), this one otherwise.

tituli.shaping.shape(text, path, index, size, *, features=None, variations=None)[source]

[(glyph_id, x_advance, y_advance, x_offset, y_offset), ...] in pixels.

variations are variable-font axis values by tag ({"wght": 700}).

Return type:

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