opentype.js
opentype.js copied to clipboard
Format not yet supported error when trying to render Noto Nastaliq Urdu
I'm trying to generate a font path with Noto Nastaliq Urdu for some Urdu text: اردو
let chars = 'اردو'
parsedFont.getPath(chars, 0, 0, 1200)
But I get the following error:
Uncaught (in promise) Error: lookupType: 7 - substFormat: 1 is not yet supported
at FeatureQuery.getLookupMethod (opentype.js:12342:20)
at FeatureQuery.lookupFeature (opentype.js:12396:32)
at opentype.js:12753:43
at Array.forEach (<anonymous>)
at Bidi.arabicRequiredLigatures (opentype.js:12751:28)
at opentype.js:12993:34
at Array.forEach (<anonymous>)
at Bidi.applyArabicRequireLigatures (opentype.js:12992:13)
at Bidi.applyFeaturesToContexts (opentype.js:13028:38)
at Bidi.processText (opentype.js:13046:15)
I'd be happy to try to contribute to fix this, but I'm not sure what this means / where to begin :)
Your Environment
- Version used: opentype v1.3.4
- Font used: Noto Nastaliq Urdu
- Browser Name and version: Chrome 118.0.5993.70
- Operating System and version (desktop or mobile): mac os 13.4
Type 7 format 1 support has been added with #486, but there hasn't been a new release since then. Please try with the state of the current master.
Aha. Using master, I get a different error. This time it's Type 5 format 1:
Uncaught (in promise) Error: lookupType: 5 - substFormat: 1 is not yet supported
at FeatureQuery.getLookupMethod (opentype.js:11871:15)
at FeatureQuery.lookupFeature (opentype.js:11898:25)
at Bidi.arabicRequiredLigatures (opentype.js:12194:38)
at Bidi.applyArabicRequireLigatures (opentype.js:12510:39)
at Bidi.applyFeaturesToContexts (opentype.js:12549:35)
at Bidi.processText (opentype.js:12571:12)
at Bidi.getTextGlyphs (opentype.js:12579:10)
at Font.stringToGlyphIndexes (opentype.js:12688:17)
at Font.stringToGlyphs (opentype.js:12691:26)
at Font.forEachGlyph (opentype.js:12744:25)
Congratulations, you found another not yet supported feature. 😉
If I wanted to work on adding support for this, how would I start? Can you outline the path?
More helping hands would be great! In your case the message stems from src/features/featureQuery.js
All in all it's "just" a matter of reading the OpenType specification and handling the binary font data and the information within according to it. Mind you though that font feature implementation is probably the most complicated place to get your hands dirty.
I would take a look at how other features are implemented, comparing that to the specification in parallel. Sometimes it's also helpful to write the test cases first and work your way back from that.
Thank you! I've been poking around today on a long train ride. Keeping track here of what I've learned so far.
The substitution spec is here: https://learn.microsoft.com/en-us/typography/opentype/spec/gsub
I need to implement lookup type 5.1 Contextual Substitution Format 1
I think the steps are something like:
- add a
contextSubstitutionFormat1tofeatureQuery.js. This piece is responsible for determining which glyphs in which positions get substituted or deleted - add case
51togetLookupMethod()(referencing thecontextSubstitutionFormat1above) - add case
51tolookupFeature()(seems to be mostly boilerplate) - add case
51toapplySubstitution.jsfor actually executing the substitution
This substitution uses a Sequence Context Format 1. I don't think this format has been implemented anywhere else yet (I haven't come across it anywhere in the code). It is the same format used in GPOS 7.1, but I don't think that's implemented either.
I'm going to look into what the tests look like next.
So great seeing someone new getting involved! You could also have a look at the outstanding PRs, some things might already have been implemented. Let us know if you have any questions.