Repository navigation
fix(plugin-print): don't throw on fonts opentype.js can't shape - #1573
Merged
Merged
Conversation
opentype.js throws on GSUB lookups it doesn't implement, and applies ccmp to every line whatever features it's given. With Hanken Grotesk, whose ccmp has a chained-context substitution (lookup type 6, format 2), every line threw, so print, measureText and @jimp/layout's Text couldn't use the font. When stringToGlyphs throws, shapeLine now maps each code point to its glyph with charToGlyph (dropping variation selectors, as opentype.js does), keeping kerning and letter spacing. Measuring, wrapping and drawing all go through shapeLine, so they fall back the same way. The font isn't changed. Adds a subset of Hanken Grotesk (OFL) as a test fixture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
🚀 PR was released in |
hipstersmoothie
added a commit
to hipstersmoothie/roomy
that referenced
this pull request
Nov 27, 2026
jimp 2.2.1 (jimp-dev/jimp#1573) falls back to per-character glyphs when opentype.js can't shape a line, so Hanken Grotesk renders without renaming its `ccmp` GSUB feature after loading. The only visible change is that ligatures (the "ffi" in "official") draw as separate letters until opentype.js ships type 6 format 2 (opentypejs/opentype.js#861). Co-Authored-By: Claude Opus 5.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.
The bug
print,measureTextand@jimp/layout'sTextshape each line with opentype.js'sstringToGlyphs. opentype.js applies the font's GSUB substitutions there, and it throws on lookup kinds it doesn't implement. One such lookup in an otherwise fine font made that font unusable for text.Repro font: Hanken Grotesk (OFL, on Google Fonts). Its
ccmpfeature has a class-based chained-context substitution (lookup type 6, format 2), so any line of two or more characters throws:Turning features off doesn't help: opentype.js applies
ccmpto every line regardless of thefeaturesoption, which only filtersliga/rligfor Latin.The fix
shapeLine(invector-layout.ts) still callsstringToGlyphsfirst. If that throws, the line falls back to one glyph per code point viacharToGlyph, without substitutions. Variation selectors are dropped, as opentype.js does. Kerning (GPOS orkern) and letter spacing are applied the same way as before, so the text is drawn without ligatures but still kerned.splitLines) and drawing all go throughshapeLine, so wrapped lines and drawn widths agree.Tests
New fixture
fixtures/HankenGrotesk-Regular.ttf: a 20 KB subset of Hanken Grotesk Regular, plus itsHankenGrotesk-OFL.txt(OFL 1.1, no Reserved Font Name). It's generated byscripts/subset-fonts.shlike the other fixtures. The subset keeps the combining marks and dotless i/j so the offendingccmplookup survives subsetting. Checked that opentype.js still throws on it.vector-font.test.ts(Node and browser) checks:features: {};printcallback's end position match measurement;printdraws ink inside the measured width.Without the fix, 5 of these fail with the error above.
New image snapshot of wrapped Hanken text in
vector-font.node.test.ts.Also checked by hand with the full, unsubsetted Hanken Grotesk Regular.
@jimp/plugin-print: 134 Node tests and 45 browser tests pass.@jimp/layout: 103 tests pass. Build, lint and typecheck ofsrcare clean for both.Docs
The README has a new "Substitutions" section and lists the new test font. The
loadTTFdocs page notes the fallback.Not included: a
featuresoptionI left out an option to choose shaping features. opentype.js's
featuresoption only togglesliga/rligfor Latin and can't turn offccmp, so it wouldn't help with this bug. That makes it a separate, smaller feature. It could be a follow-up if there's demand. It would thread throughVectorTextLayoutSchematostringToGlyphs.🤖 Generated with Claude Code