Skip to content

Outlines, subsets, and portable data

Glyph geometry

glyph = layout.lines[0].runs[0].glyphs[0]
outline = library.outline(glyph)
print(outline.units_per_em, outline.bounds, outline.commands[:3])

FontLibrary.outline(glyph) → GlyphOutline
glyphPositionedGlyph

A glyph from a layout. Its face and glyph id select the outline.

Returns the exact outline of a positioned glyph. It is in font units, so scale it by the run's size / outline.units_per_em and add the glyph's position.

GlyphOutline(glyph_id, commands, bounds, units_per_em, variation_coordinates=())

An exact glyph outline: ordered path commands, bounds and the units per em.

MoveTo(point)

Starts a new contour at the given point in font space.

LineTo(point)

Adds a straight segment from the current point to its end point.

QuadraticTo(control, point)

Adds a quadratic Bézier segment with one control point and one end point.

CubicTo(control1, control2, point)

Adds a cubic Bézier segment with two control points and one end point.

Closes the current contour by connecting it to its start.

flatten(outline, *, tolerance) → tuple[Polyline, ...]

Approximates curved commands with line segments at a tolerance that you choose, in font units.

Polyline(points, closed)

One open or closed sequence of points returned by flattening.

The exact outline of a glyph. Squares are on-curve points, circles are control points, and dashed lines are control polygons.

The exact outline of a glyph. Squares are on-curve points, circles are control points, and dashed lines are control polygons.

Permission-aware subsets

FontLibrary.subset(layout, *, embedding_use, container=..., allow_unknown=False) → FontSubsetBundle
layoutTextLayout

The layout whose glyphs the subset must cover.

embedding_useEmbeddingUse

Why the subset will be embedded. The permission check depends on it.

containerFontContainerDefault: FontContainer.SFNT

The font container: SFNT or WOFF2.

allow_unknownboolDefault: False

Accept unknown permissions. The decision is recorded.

Builds a font subset that covers a layout, and returns bytes and metadata. It never writes markup or a file.

EmbeddingUse(*values)

Declares why the subset will be embedded, so the font's permissions are enforced for that use.

FontContainer(*values)

Chooses the container of the returned font: SFNT (OpenType) or WOFF2.

FontSubsetBundle(fonts, diagnostics=())

The complete subsetting result: the portable fonts, diagnostics and metadata.

PortableFont(
    face_id,
    family,
    subset_tag,
    glyph_ids,
    permission,
    container,
    mime_type,
    data,
    variation_coordinates=(),
)

One permission-checked font payload with family, subset tag, glyph ids, permission and the bytes.

from glyphkit.embedding import EmbeddingUse, FontContainer

bundle = library.subset(layout, embedding_use=EmbeddingUse.WEB, container=FontContainer.WOFF2)

WOFF2 needs the portable extra. The permission rules are on the Reproducibility and font safety page.

Serialization

to_data(value) → dict[str, JSONValue]

Converts a supported immutable public value into versioned plain data that is ready for JSON-like storage.

from_data(kind, data) → object

Validates versioned data and rebuilds the public value within the configured limits.

Comments