paint: shape required-ligature ("rlig") text so icon web fonts paint - #241
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 GSUBrlig(Required Ligatures) feature into one pictogram glyph.@font-facenow 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), butMeasure/drawTextonly 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) anddrawText(paint/paint.go) now shape each run throughFace.Shape(text, "rlig")and walk the resulting glyph indices (AdvanceIndexUnits/GlyphMaskIndex) instead of raw runes.rligis the OpenType-spec-mandated always-on ligature feature (its own registry entry: "Control of this feature should not generally be exposed to the user"), unlikeliga, which a real browser disables under non-zeroletter-spacing— confirmed via MDN, and deliberately not modeled this round (see FIDELITY.md's "Known gaps").rliglookups, so this is isolated to fonts that actually require it — zero risk to existing bundled-font text.@font-face-fetching capability and ago-opentype/shapepackage that don't reflect the current code (@font-faceshipped separately; the shaping API landed directly onopentype.Face, no separate package).Test plan
go build ./...,go vet ./...,go test ./...all greenpaintback to its 100.0% ratchet floor)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;drawTextpaints visible ink for it; an uncovered rune still measures/paints nothing (the.notdefguard)paint/fonts.go/paint/paint.gomakes the two new positive tests fail exactly as expected (unshaped 15-glyph width; no ink painted)🤖 Generated with Claude Code