adobe-type-tools / cffsubr

Standalone CFF subroutinizer based on AFDKO tx
Apache License 2.0
8 stars 8 forks source link

when converting CFF => CFF2, tx leaves redundant FontMatrix in FontDict #13

Closed anthrotype closed 4 years ago

anthrotype commented 4 years ago

Take an OTF with CFF 1.0 and a non-standard UPEM (i.e. not 1000), and convert it to CFF2 using cffsubr (which uses tx).

You will see a warning upon compiling the OTF from fontTools.cffLib::L2409, saying that:

Some CFF FDArray/FontDict keys were ignored upon compile: FontMatrix

The CFF2 table that is generated by tx seem to contain an extra FontMatrix operator in the FDArray[0].FontDict which fonttools doesn't expect it to be there and removes it while issuing the warning. This is weird since FontMatrix is a TopDict operator, so it should not be there.

I suspect this could be a bug in tx code or some support library elsewhere in afdko which is responsible for the CFF1 to 2 conversion.

Note the warning only happens when FontMatrix is different form the default [0.001 0 0 0.001 0 0], which for CFF is quite rare given most fonts are drawn at 1000 UPEM.

To reproduce, take a UFO, change its unitsPerEm in fontinfo.plist to something different from 1000, compile the font to OTF with CFF 1.0 e.g. with fontmake or ufo2ft. Then pass it through python -m cffsubr --cff-version 2 to convert it to CFF, and you should see the above mentioned warning appear.

To be honest, I actually am not sure what FontMatrix is used for when CFF/CFF2 are embedded in an OpenType font..

khaledhosny commented 4 years ago

AFAIK, if the font does not use 1000 UPEM, FontMatrix must be used otherwise the glyphs will be incorrectly scaled.

khaledhosny commented 4 years ago

See also https://github.com/adobe-type-tools/afdko/issues/137

anthrotype commented 4 years ago

As for CFF2, why is tx adding a FontMatrix to the FontDict (it wasn't there to begin with, it was only in the TopDict of the original CFF 1.0 input table), but then fonttools is dropping from it with a warning?

khaledhosny commented 4 years ago

This looks like a bug indeed, the only operator allowed in CFF2 FontDict is Private, but may be tx was following an old version of the spec (see the note in Font DICT Operator Entries).

anthrotype commented 4 years ago

may be tx was following and old version of the spec (see the note in Font DICT Operator Entries).

thanks @khaledhosny, now it makes sense. For now, i'll just strip it (#14), but will revise if/when this will be fixed upstream in afdko. /cc @josh-hadley

josh-hadley commented 4 years ago

Thanks @anthrotype . We should definitely address this upstream. From discussions with @cjchapman that should be pretty straightforward.

cjchapman commented 4 years ago

@anthrotype & @khaledhosny Josh has fixed this issue in tx in https://github.com/adobe-type-tools/afdko/pull/1165