Code Monkey home page Code Monkey logo

Comments (12)

RoelN avatar RoelN commented on September 1, 2024 1

Thanks very much! I'll implement this in the Fondue a.s.a.p. as 6.1 is now broken 😅

from lib-font.

RoelN avatar RoelN commented on September 1, 2024 1

Of course, thanks!

how opentype GSUB works, in all its insane glory =D

This might be my commit message when I fix it!

from lib-font.

RoelN avatar RoelN commented on September 1, 2024

Related error (not finding input coverage for lookup type 6) can also be observed in:

https://github.com/google/fonts/blob/main/ofl/abyssinicasil/AbyssinicaSIL-Regular.ttf

Which will return undefined for all counts when loaded in the example code above.

from lib-font.

Pomax avatar Pomax commented on September 1, 2024

nice finds! I'll have to dig into this over the weekend.

from lib-font.

RoelN avatar RoelN commented on September 1, 2024

Another font with an undefined inputGlyphCount: https://github.com/google/fonts/blob/main/ofl/akayakanadaka/AkayaKanadaka-Regular.ttf

from lib-font.

RoelN avatar RoelN commented on September 1, 2024

Another one likely getting bitten by the same bug: https://github.com/google/fonts/blob/main/ofl/alice/Alice-Regular.ttf

from lib-font.

Pomax avatar Pomax commented on September 1, 2024

I rewrote your original example code a little to output a treeish structure to see what we're dealing with, which for the original font shows:

script id 0
|--lang id 0
| |--feature id 0
| | |--lookup id 0
| | | |--subtable id 0 (type 1, substFormat 2)
| |--feature id 1
| | |--lookup id 0
| | | |--subtable id 0 (type 1, substFormat 2)
| |--feature id 2
| | |--lookup id 0
| | | |--subtable id 0 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 1 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 2 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 3 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | |--lookup id 1
| | | |--subtable id 0 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 1 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| |--feature id 3
| | |--lookup id 0
| | | |--subtable id 0 (type 4, substFormat 1)
| |--feature id 4
| | |--lookup id 0
| | | |--subtable id 0 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 1 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| |--feature id 5
| | |--lookup id 0
| | | |--subtable id 0 (type 1, substFormat 1)
script id 1
|--lang id 0
| |--feature id 0
| | |--lookup id 0
| | | |--subtable id 0 (type 1, substFormat 2)
| |--feature id 1
| | |--lookup id 0
| | | |--subtable id 0 (type 1, substFormat 2)
| |--feature id 2
| | |--lookup id 0
| | | |--subtable id 0 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 1 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 2 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 3 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | |--lookup id 1
| | | |--subtable id 0 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 1 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| |--feature id 3
| | |--lookup id 0
| | | |--subtable id 0 (type 4, substFormat 1)
| |--feature id 4
| | |--lookup id 0
| | | |--subtable id 0 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| | | |--subtable id 1 (type 6, substFormat 3)
| | | | |--subtable glyph count: 1
| |--feature id 5
| | |--lookup id 0
| | | |--subtable id 0 (type 1, substFormat 1)
|--lang id 1
| |--feature id 0
| | |--lookup id 0
| | | |--subtable id 0 (type 6, substFormat 1)
| | | | |--subtable glyph count: undefined

So it looks like this only affects GSUB lookup type 6, subtable format 1, which is the Chained Sequence Context. Looking at its table structure, this format does not expose the inputGlyphCount at the subtable level, but encodes a list of chainSubRuleSets, which in turn encode a set of chainSubRule objects, and each of those have an inputGlyphCount record.

from lib-font.

Pomax avatar Pomax commented on September 1, 2024

Updating the code to this:

            // ...

            if (lookup.lookupType === 6) {
              const inputGlyphCount = subtable.inputGlyphCount;

              console.log(
                `| | | | |--subtable glyph count: ${inputGlyphCount}`
              );

              const chainSubRuleSetCount = subtable.chainSubRuleSetCount;
              console.log(
                `| | | | |--chainSubRuleSetCount: ${chainSubRuleSetCount}`
              );

              for (let css = 0; css < chainSubRuleSetCount; css++) {
                const chainSubRuleSet = subtable.getChainSubRuleSet(css);
                const chainSubRuleCount = chainSubRuleSet.chainSubRuleCount;
                console.log(
                  `| | | | | |--chainSubRuleCount for set ${css}: ${chainSubRuleCount}`
                );

                for (let csr = 0; csr < chainSubRuleCount; csr++) {
                  const chainSubRule = chainSubRuleSet.getSubRule(csr);
                  const inputGlyphCount = chainSubRule.inputGlyphCount;
                  console.log(
                    `| | | | | | |--inputGlyphCount for rule ${csr}: ${inputGlyphCount}`
                  );
                }
              }
            }

            // ...

Shows:

script id 1
|--lang id 0
| |--feature id 0
| | |--lookup id 0
| | | |--subtable id 0 (type 1, substFormat 2)
...
|--lang id 1
| |--feature id 0
| | |--lookup id 0
| | | |--subtable id 0 (type 6, substFormat 1)
| | | | |--subtable glyph count: undefined
| | | | |--chainSubRuleSetCount: 2
| | | | | |--chainSubRuleCount for set 0: 1
| | | | | | |--inputGlyphCount for rule 0: 2
| | | | | |--chainSubRuleCount for set 1: 1
| | | | | | |--inputGlyphCount for rule 0: 2

from lib-font.

Pomax avatar Pomax commented on September 1, 2024

@RoelN this feels like it's just part of the GSUB insanity rather than a bug: the values are there, but lookup 6.1 just encodes them in a much deeper spot than 6.3

(the master lookuptype list, linking through to each separate subtable format, can be found here)

from lib-font.

RoelN avatar RoelN commented on September 1, 2024

@Pomax Thanks for looking into it. What does this mean for when you want to get the 6.1 lookups? I'd like to show these features plus their input in Wakamai Fondue! :-)

from lib-font.

Pomax avatar Pomax commented on September 1, 2024

You can check for the substFormat value to determine which flavour of lookup type 6 you're handling, and if it's 1, iterate over the ChainSubRuleSets using the code above:

let inputGlyphCount = 0;

for (let css = 0; css < chainSubRuleSetCount; css++) {
  const chainSubRuleSet = subtable.getChainSubRuleSet(css);
  const chainSubRuleCount = chainSubRuleSet.chainSubRuleCount;

  for (let csr = 0; csr < chainSubRuleCount; csr++) {
    const chainSubRule = chainSubRuleSet.getSubRule(csr);
    // and then, for example:
    inputGlyphCount += chainSubRule.inputGlyphCount;
  }
}

// inputGlyphCount is now the total tally of all input counts spanned by this 6.1 lookup

from lib-font.

Pomax avatar Pomax commented on September 1, 2024

(closing as not actually a bug but just "how opentype GSUB works, in all its insane glory =D")

from lib-font.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.