fonttools / fontbakery

🧁 A font quality assurance tool for everyone
https://fontbakery.readthedocs.io
Apache License 2.0
534 stars 99 forks source link

Suspicious function changes GPOS data in-place, messes up other checks #4671

Closed belluzj closed 2 months ago

belluzj commented 2 months ago

I tried debugging a failure on the check com.google.fonts/check/varfont/duplexed_axis_reflow that looks like this:

ERROR Failed with AttributeError: Coverage

            File ".../venv/lib/python3.11/site-packages/fontbakery/checkrunner.py", line 213, in _run_check
              subresults = list(subresults)
                           ^^^^^^^^^^^^^^^^
            File ".../venv/lib/python3.11/site-packages/fontbakery/checks/googlefonts/varfont.py", line 447, in
          com_google_fonts_check_varfont_duplexed_axis_reflow
              kerning = all_kerning(ttFont)
                        ^^^^^^^^^^^^^^^^^^^
            File ".../venv/lib/python3.11/site-packages/fontbakery/utils.py", line 514, in all_kerning
              for g, pair in zip(subtable.Coverage.glyphs, subtable.PairSet):
                                 ^^^^^^^^^^^^^^^^^
            File ".../venv/lib/python3.11/site-packages/fontTools/ttLib/tables/otBase.py", line 893, in __getattr__
              raise AttributeError(attr)

When running only that single check, the error doesn't happen, and the font data looks alright in the debugger. However, when looking at the same data as part of running a full Fontbakery profile, it looked like the kerning subtables had surprising data, and I think this other function iterate_lookup_list_with_extensions might be the culprit:

https://github.com/fonttools/fontbakery/blob/739244419f0940439f8448b6aef6f7662a1d8a2b/Lib/fontbakery/utils.py#L545-L546

It modifies the subtables in place, and I suspect that messes up other checks that happen later. Would it be possible to perform the intended iteration without changing the data in place?

I can look into a fix if my suggestion makes sense.

felipesanches commented 2 months ago

Thanks for reporting this! Yes, I'd be glad to review your fix.