Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the calculation of maxComponentDepth really correct? #62

Open
be5invis opened this issue Oct 21, 2017 · 12 comments
Open

Is the calculation of maxComponentDepth really correct? #62

be5invis opened this issue Oct 21, 2017 · 12 comments

Comments

@be5invis
Copy link

Since FV is always complaining about maxComponentDepth being too small for Iosevka I walked into its source to see how it analyzes the component depth of a particular glyph. And the logic in GetCompositeGlyphStats (https://github.com/Microsoft/Font-Validator/blob/master/OTFontFileVal/val_maxp.cs#L371) seems that, every time you recurse DOWN you increase a counter, which may perform incorrect number in a complex glyph like this:

2785 [
  2665 [        <- trigger nComponentDepth++
    2601 [      <- trigger nComponentDepth++
      2597 [    <- trigger nComponentDepth++
        2595    <- trigger nComponentDepth++
        2595
      ]
      2595
    ]
    2595
  ]
  2601 [
    2597 [       <- trigger nComponentDepth++
      2595       <- trigger nComponentDepth++ 
      2595
    ]
    2595
  ]
]

The recursion depth of glyph 2785 is 4 (2785 → 2665 → 2601 → 2597 → 2595) but FV increased the counter by two more times when looking inside its second reference.

@be5invis
Copy link
Author

cc. @HinTak

@HinTak
Copy link

HinTak commented Oct 21, 2017

@be5invis : I think you are making assumptions about the rendering engine(s) behaving in a certain idealized way ( namely, de-allocating nested component glyphs when they go out of scope) which may not necessarily be true in general, or historically. You cannot make such assumptions about all engines current and past. Therefore, it is prudent to err on the generous side - i.e. the current behavior. I don't think the curent code should be changed, if that's what you are suggesting.

@be5invis
Copy link
Author

be5invis commented Oct 21, 2017 via email

@HinTak
Copy link

HinTak commented Oct 21, 2017 via email

@be5invis
Copy link
Author

be5invis commented Oct 21, 2017 via email

@HinTak
Copy link

HinTak commented Oct 21, 2017

i.e. if the spec says the value should be such and such, then engine implmentations should be corrected to behave that way. If the spec did not say, then engines are allowed to behave differently. In that case, validator should use the maximum value from all such engines.

@HinTak
Copy link

HinTak commented Oct 21, 2017

You really mean the current windows rasterizer can handle a tight value. Anyway, if there is any argument on such max* values, the larger value should be used, which is again, the current code.

@be5invis
Copy link
Author

be5invis commented Oct 21, 2017 via email

@HinTak
Copy link

HinTak commented Oct 21, 2017

@be5invis well, if you can find the former maintainer of FV, then you should just get him to issue a pull and explain his reasoning himself, and get his changes merged...

@be5invis
Copy link
Author

be5invis commented May 4, 2018

@HinTak Sorry for late reply.
Per Greg Hitchcock:

It should be the deepest leaf. That is what the TrueType rasterizer assumes.
If the Validator doesn't represent the deepest leaf, then yes, it is wrong.

@HinTak
Copy link

HinTak commented May 4, 2018

@be5invis : Can you prepare a patch?

@santhoshtr
Copy link

In case if it is relevant here, fonttools recently fixed a 21 year old bug about the calculation of maxComponentDepth. fonttools/fonttools#2044

It would be helpful to cross check the calculations so that fonts using fontools using build chain and later validating the fonts using MS FontValidator not affected by this mismatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants