Skip to content

paint: shape required-ligature ("rlig") text so icon web fonts paint - #241

Merged
tannevaled merged 1 commit into
mainfrom
font-rlig-shaping
Sep 28, 2026
Merged

tannevaled merged 1 commit into
mainfrom
font-rlig-shaping

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

  • go.dev/blog's own nav dropdown carets are Google's Material Icons ligature words (<i class="material-icons">arrow_drop_down</i>), substituted by the font's OpenType GSUB rlig (Required Ligatures) feature into one pictogram glyph. @font-face now loads that real font (css: named font families, and @font-face (1/3) #233/Fetch and register a document's own @font-face files (2/3) #234/@font-face reaches a font service at last (WOFF2) #236), but Measure/drawText only ever did a per-rune cmap+advance lookup — so the word's individual, real (non-.notdef) letter glyphs painted nothing at all, instead of the one substituted icon a real browser shows.
  • Measure (paint/fonts.go) and drawText (paint/paint.go) now shape each run through Face.Shape(text, "rlig") and walk the resulting glyph indices (AdvanceIndexUnits/GlyphMaskIndex) instead of raw runes. rlig is the OpenType-spec-mandated always-on ligature feature (its own registry entry: "Control of this feature should not generally be exposed to the user"), unlike liga, which a real browser disables under non-zero letter-spacing — confirmed via MDN, and deliberately not modeled this round (see FIDELITY.md's "Known gaps").
  • Verified none of the four bundled prose fonts (Inter, Lora, Go Mono, DejaVu Sans) declare any rlig lookups, so this is isolated to fonts that actually require it — zero risk to existing bundled-font text.
  • Corrects FIDELITY.md's own stale "Known gaps" entry, which had said a fix would be "genuinely comparable in scope to Shadow DOM" based on a @font-face-fetching capability and a go-opentype/shape package that don't reflect the current code (@font-face shipped separately; the shaping API landed directly on opentype.Face, no separate package).

Test plan

  • go build ./..., go vet ./..., go test ./... all green
  • Coverage floors held (paint back to its 100.0% ratchet floor)
  • New tests in paint/ligature_test.go, using the real Material Icons WOFF2 (Google, Apache License 2.0) as a fixture: Measure("arrow_drop_down") collapses to one glyph's advance; drawText paints visible ink for it; an uncovered rune still measures/paints nothing (the .notdef guard)
  • Git-stash-confirmed: reverting paint/fonts.go/paint/paint.go makes the two new positive tests fail exactly as expected (unshaped 15-glyph width; no ink painted)
  • Full 10-page bench comparison run: all pages within the same small run-to-run noise band already established for this live comparison; the fix's real effect (a few dozen pixels of one icon glyph) is too small a share of a full page to move aggregate SSIM outside that noise — confirmed instead by direct visual inspection of the isolated repro and a live re-render of go.dev/blog itself, both now showing a real triangle glyph where the nav previously rendered nothing

🤖 Generated with Claude Code

go.dev/blog's own nav dropdown carets are Material Icons ligatures —
<i class="material-icons">arrow_drop_down</i>, substituted by the font's
GSUB "rlig" feature into one pictogram glyph. @font-face now loads that
font (engine#233/#234/#236), but Measure/drawText only ever did a
per-rune cmap+advance lookup, so the word's individual (real, non-.notdef)
letter glyphs painted nothing at all instead of the substituted icon.

Measure and drawText now shape each run through Face.Shape(text, "rlig")
and walk the resulting glyph indices (AdvanceIndexUnits/GlyphMaskIndex)
instead of raw runes. rlig is the OpenType-spec-mandated always-on
ligature feature (unlike liga, which a real browser disables under
non-zero letter-spacing), and none of the four bundled prose fonts
declare any rlig lookups, so this is isolated to fonts that actually
require it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit d11edf9 into main Sep 28, 2026
7 checks passed
@tannevaled
tannevaled deleted the font-rlig-shaping branch September 28, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant