This required a fix to fontTools/cffLib. When reading a CFF2 variable font (VF) from XML, the VF state in FontDict and PrivateDict does not get set. I made a temporary fix by adding a loop to set PrivateDict.vstore for all the PrivateDict objects after the XML file has been read. This should not be necessary, and in the near future I will revisit both this issue, and the related use of isCFF2 when compiling/decompiling.
* [subset CFF] Fix bug in de-subroutinizing when subroutines contain hints, issue 1493
The code was skipping executing a subroutine if it had already been desubroutinized. The initial set of vstemhm and hstemhm operators and values may be in a subroutine. If a charstring is being executed which calls such subroutines, they still need to be executed in order to count the number of hint values seen, so that the byte length of the hintmask can be calculated.
I fixed this bug by executing subroutines even if they have already been desubroutinized, as long as (we don't know yet if we are doing hintmasks) or ( we do need a hintmask, but have not yet seen it).
Clean up code per Cosimo's suggestions:
In arg list for stop_hint_count(), use *args to accept unused argument, rather than a dummy positional argument.
Change stop_hintcount_ops to a from a global variable to a class variable in _DesubroutinizingT2Decompiler.
Remove un-needed 'return' at line 387
Remove duplicate assignment of cs at line 437
Add patch for the bug where AttributeError is encountered when remove_hints is run after desubroutinize: remove lines deleting the GlobalSubrs for each FontDict. This always needed to be done only once, and is now in any case done in cff.GlobalSubrs.clear(), at the end of the desubroutinize() function.
Changed test case subset_test.py::'test_no_hinting_desubroutinize_CFF' to reference a font with a non-empty GlobalSubr, in order to trigger AttributeError traceback.
The following test cases are expected to fail because the current implementation of drop_hints
also strips the charstrings' advance widths:
Tests/subset/subset_test.py::SubsetTest::test_no_hinting_CFF
Tests/subset/subset_test.py::SubsetTest::test_no_hinting_desubroutinize_CFF