opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.
https://opentype.js.org/
MIT License
4.43k stars 474 forks source link

Format not yet supported error when trying to render Noto Nastaliq Urdu #627

Open bennlich opened 11 months ago

bennlich commented 11 months ago

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

Connum commented 11 months ago

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.

bennlich commented 11 months ago

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)
Connum commented 11 months ago

Congratulations, you found another not yet supported feature. 😉

bennlich commented 11 months ago

If I wanted to work on adding support for this, how would I start? Can you outline the path?

Connum commented 11 months ago

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.

bennlich commented 11 months ago

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:

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.

Connum commented 11 months ago

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.