Skip to content

glyphkit: renderer-independent typography for Python

A Python typography engine that returns immutable layout data and draws nothing.

GitHub PyPI Python

glyphkit 1.0 is in beta

glyphkit 1.0.0b4 is a pre-release. Each change between pre-releases is recorded in the change history.

from glyphkit import FontLibrary, FontSource, Paragraph, TextSpan, TextStyle

library = FontLibrary.from_sources(
    (
        FontSource.path("fonts/SourceSans3-Regular.ttf"),
        FontSource.path("fonts/NotoSansTC-Regular.otf"),
    ),
    generic_families={"sans-serif": ("Source Sans 3", "Noto Sans TC")},
)

paragraph = Paragraph(
    (TextSpan("效用 U(x₁, x₂)", TextStyle(("sans-serif",), 18)),),
    max_width=360,
)
layout = library.layout(paragraph)
print(layout.logical_bounds)

Features

  • Fonts and shaping

    Explicit font sources, deterministic matching, configured fallback, Unicode scripts, bidirectional text and OpenType shaping.

    Fonts and shaping

  • Paragraph layout

    Wrapped paragraphs with logical and ink bounds, baselines, alignment and indentation, in layout units rather than pixels.

    Text layout and mathematics

  • Structured mathematics

    A defined LaTeX-like grammar laid out by TeX's rules with the constants of the font's OpenType MATH table.

    Math grammar

  • Exact glyph outlines

    Move, line, quadratic, cubic and close commands in font units, with adaptive flattening to a tolerance you choose.

    Outlines and embedding

  • Permission-aware font subsets

    Subset bytes in SFNT or WOFF2 that respect the font's embedding permissions, and plain-data serialization with versions.

    Font safety

  • Coordinates and metrics

    Font units, scale, advances against ink, and which box to use when you align, crop or test for collisions.

    Coordinates and metrics

Install

uv add --prerelease allow glyphkit

Requires Python 3.10 to 3.13. See Installation for the WOFF2 extra.

Examples

Every figure in this documentation comes with the script that draws it. Download them all in one file.

Download all examples

Comments