defnotmid

Projects / 03

oglyph

Fonts and text shaping in native Odin. It reads TrueType and OpenType fonts and shapes text with them the way HarfBuzz does, and is tested against HarfBuzz.

  • Odin
  • MIT
  • core: only
  • HarfBuzz 14.6
  • Unicode 17.0.0
31 seconds of oglyph at 60 fps, on Arabic electronica in D Hijaz at 124 BPM: السلام عليكم typed key by key, each letter taking its joining form as the next arrives; हिंदी, धर्म and क्षमा with a vowel sign drawn before its consonant, a reph and the क्ष conjunct; ligatures, fractions, a slashed zero and small caps switched on; Adwaita Sans from weight 100 to 900 and back as 97 real instances, outlined and shaped by oglyph from the font's deltas and drawn live (onimite's text{ variations }); and HarfBuzz 14.6's glyphs for three lines laid over oglyph's, the same glyph ids within 0.001 font units. oglyph's demo/ at v0.0.8, rendered by onimite v0.0.59. Darbuka samples: the Versilian Community Sample Library by Versilian Studios (CC0).
Five lines of text on paper: Office waffles, ½ off in DM Sans; مرحبا بالعالم in Noto Naskh Arabic; नमस्ते दुनिया in Noto Sans Devanagari; สวัสดีชาวโลก in Noto Sans Thai; שלום עולם in Noto Sans Hebrew.
Text shaped by oglyph v0.0.1 and drawn by ovg, as onimite v0.0.54 renders it: DM Sans's fi and fl ligatures and its fraction feature, Arabic joined right to left, Devanagari's vowel sign moved ahead of its consonant, Thai's stacked marks and Hebrew.

Where it came from

oglyph was ovg's font and shape packages until ovg v0.0.23, and their history is in ovg's repository. ovg draws its text through oglyph, so onimite does too. Bidi and line breaking are left to the caller (ovg orders right-to-left runs itself).

By the numbers

differences from HarfBuzz
0
glyphs, clusters, advances and offsets: 1,043 curated, 27,118 feature-set, 24,400 random and 384 variable-instance cases
random strings over 40 downloaded fonts
51,600
Google and SIL fonts for Arabic, Indic, Myanmar, Khmer, Korean and more; 0 differences
HarfBuzz's time
0.96×
on the 1,043 curated cases, one core; Arabic sentences alone take 1.06–1.10×
of HarfBuzz's shapers
9
Arabic, Hebrew, Thai, Hangul, Indic, Khmer, Myanmar, USE and the default

tools/shape_corpus at v0.0.5 against the system libharfbuzz 14.6.0 (its OpenType shaper) on Arch Linux, re-run 2026-10-24; the curated count depends on which of the tool's fonts are installed. Time: its -bench (each a median of 15 alternating runs) at v0.0.5, 0.96–0.97× in four runs alternated with v0.0.4 (0.98–0.99× in the same runs), at -o:speed on one core of a Ryzen 9 9900X3D; the sentence figures are the README's, on a busy machine.

What's in it

  1. 01Fonts

    A face's tables, the character map (cmap formats 0, 4, 6, 12 and 13, and variation sequences), metrics, kerning from the kern table and GPOS pairs, glyf outlines with composites, CFF and CFF2 charstrings, names (family, subfamily, and a variable font's axis and instance names) and glyph names, and the characters a face maps.

  2. 02Variable fonts

    fvar's axes and named instances, avar versions 1 and 2, gvar, HVAR and CFF2 blends. set_variations or set_coords picks an instance, and outlines, advances and shaping follow it; ovg draws a chosen instance since v0.0.24.

  3. 03HarfBuzz's shapers

    The default, Arabic, Hebrew, Thai, Hangul, Indic, Khmer and Myanmar shapers and the Universal Shaping Engine, with HarfBuzz's syllable machines, and Unicode properties, script runs and normalization from the Unicode 17.0.0 character database.

  4. 04GSUB and GPOS

    Substitution and positioning lookups, the legacy kern table, fallback mark positioning, features set over all or part of the text, and variable fonts' FeatureVariations and device deltas.

  5. 05Three owners

    A Layout per face, read-only while shaping; a Plan per script, direction, language and set of features; a Shaper per call at a time. A warm shaper allocates nothing.

  6. 06Only the lookups that can apply

    A plan knows which lookups can start at each glyph, so a shaping call visits only those lookups, and each lookup only the positions where it can start.

  7. 07Untrusted fonts

    Every read is bounds-checked: a corrupt or truncated font gives wrong glyphs or a load error, never a read out of bounds. Work is bounded by the font's own data and by HarfBuzz's limits, and the tests mutate real fonts' tables and shape and draw them.

  8. 08Checked against HarfBuzz

    tools/shape_corpus compares every glyph, cluster, advance and offset with the system libharfbuzz; tools/shape_unicode regenerates the Unicode and syllable tables from HarfBuzz's source. Before v0.0.1's fixes and speed work, an independent verification run of an earlier build agreed with HarfBuzz on every glyph and cluster of 1.45 million random strings in 38 scripts, and its outlines at variable instances with an unrounded fontTools oracle within 0.001 units over 2.4 million glyph instances.

  9. 09About HarfBuzz's speed

    On one core, oglyph shapes the 1,043 curated cases in 0.96× HarfBuzz's time. The README's own timing on Noto fonts, both in one process taking turns: words and random strings 0.66–0.90× and Latin sentences 1.00×, but Arabic sentences 1.06–1.10×, Devanagari sentences 0.99–1.04× and Devanagari words 1.02–1.03×.

Where it differs from HarfBuzz

  • Arabic fonts without GSUB aren't shaped from presentation forms (HarfBuzz's fallback).
  • Mongolian variation selectors in text shaped as Arabic.
  • gvar advances within about 0.0001 of a half unit, which oglyph sums exactly where HarfBuzz rounds in single precision.

Use it

import ft "deps:oglyph/font"   // -collection:deps=.. (the directory holding oglyph)
import sh "deps:oglyph/shape"

face, err := ft.load(font_bytes)  // the bytes are borrowed
layout: sh.Layout                 // the face's tables, prepared once
sh.layout_init(&layout, &face)
plan: sh.Plan                     // per script, direction, language, features
sh.plan_init(&plan, &layout, &face, .Latin, .LTR)
shaper: sh.Shaper                 // the glyph buffer, kept warm
sh.shaper_init(&shaper)
glyphs: [dynamic]sh.Glyph
sh.shape(&shaper, &plan, &face, text_runes, nil, &glyphs)  // visual order

The family