When a subroutine contains no explicit hint stem operators (has_hint=False),
but it contains a hintmask operator which, in the context of the calling
charstring, would be understood as implying a vstemhm, then we need to set
has_hint=True on the subroutine, and update the last_hint index.
Otherwise, the drop_hints function leaves behind the arguments of the implicit
vstemhm operator.
This case is exemplified in the test font Tests/subset/data/Lobster.subset.ttx,
for charstrings "B" and "B.salt", and subroutine index="2".
--- /Users/cosimolupo/Documents/Github/fonttools/Tests/subset/data/expect_no_hinting_CFF.ttx
+++ /var/folders/jb/rjz76yw92w7144mwqg119jnm0000gn/T/tmpO_XOWh/tmp3.ttx
@@ -47,7 +47,7 @@
107 return
</CharString>
<CharString index="2">
- 230 636 rmoveto
+ 119 230 636 rmoveto
-136 -636 rlineto
144 hlineto
return
@@ -94,7 +94,7 @@
endchar
</CharString>
<CharString name="B">
- 187 -105 callsubr
+ 187 6 93 362 139 -119 101 -101 -105 callsubr
82 383 rlineto
2 18 20 1 8 hhcurveto
73 22 -57 -70 hvcurveto
@@ -109,7 +109,7 @@
endchar
</CharString>
<CharString name="B.salt">
- 185 -105 callsubr
+ 185 6 93 350 149 -119 105 -105 -105 callsubr
6 30 rlineto
-41 39 41 -17 39 hhcurveto
125 110 175 136 72 -32 62 -82 15 hvcurveto
_DehintingT2Decompiler now inherits from T2WidthExtractor, so we can save
the charstring width and insert it back after we dropp the hints.
This avoids the need to do an extra .draw() just for the sake of
extracting the width.
We shall reuse it as base class for the _DehintingT2Decompiler in subset module,
as we need to save the width in order to re-insert it after dropping the hints.
This is the same patch as PR #606
Quoting myself:
```
It seems that the horizontal advance of hinted charstrings gets lost when the CFF hinting is stripped with '--no-hinting' option...
T2CharString objects only get assigned a 'witdh' attribute after their 'draw' method is called.
The subsetter's drop_hints function attempts to insert the width back at the beginning of the de-hinted charstring's program, but can do that only if the charstring does have a 'width' attribute:
c63fea0f8f/Lib/fontTools/subset/__init__.py (L1928)
Hence, we must 'draw' the charstring (with a NullPen) before stripping the hints.
```
Now this method fixes the issue (advances are kept) when doing _both_ --no-hinting and --desubroutinize (the test_no_hinting_desubroutinize should now pass, while it was failing before).
However, when one only does does --no-hinting, this method raises an error:
AttributeError: 'NoneType' object has no attribute 'nominalWidthX'
Lib/fontTools/misc/psCharStrings.py:282: AttributeError
(this is reflected in the failing `test_no_hinting_CFF`)
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
Indentation for TTX XMLF is 2 spaces. I chose 4 spaces for indentation of instructions to make it more noticeable. I hope it’s not a problem, because assembly code lines are usually very short.
Also fixes issues with merging of PairPos.
Trying on Noto Sans Thai still fails, now because of issues in class differences in
PairPosFormat2. :( Investigating.
This is part of fixing https://github.com/fonttools/fonttools/issues/719
though, the changes are currently in interpolate_layout, and need to be ported /
merged with varLib.__init__ variation-font-builder.