-
Notifications
You must be signed in to change notification settings - Fork 452
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
[cffLib.specializer] generalizeProgram returns invalid charstring program? #1975
Comments
This currently fails with AssertionError: CFF2 CharStrings must not have an initial width value possibly related to fonttools#1975
I do see the problem now. When CFF2 was being added to this module, I didn't fully understand the design. I thought they addressed it, but now I see it didn't correctly. What's happening is that in general, the form of |
I wanted to use the
cffLib.specializer
to generalize some CFF2 charstrings, to produce some test fonts.I did something like this:
However, upon saving the font, when the font-bounding-box recalculation tries to call the charstrings' draw() method, it fails with an error like this:
If I try to save the TTFont with recalcBBox=False, then the resulting font does not render at all (it's all blank), and OTS also rejects it (
ERROR: CFF2: Failed validating CharStrings INDEX
).Upon inspecting the original and generalized programs, I see that the number of arguments for the blend operators seems incorrect. I think it's missing the last argument that OT spec calls
numberOfBlends
(ie. the one which tells the operator following blend how may operands that will be left on the stack after blending).E.g. in the glyph below, the first line is the original specialised program, the second is the generalized one after our
generalizeProgram
function:I uploaded a test font (a subsetted copy of SourceSansVariable-Roman.otf, which I had previously run through
fonttools subset --desubroutinize --no-hinting
) and a script to reproduce the issue:generalize-cff-issue.zip
I spent some time poking at the code, and eventually managed to produce a generalized version of the test font that seems to render and passes sanitization. I applied the following patch:
It seems that
_convertToBlendCmds
function puts back the finalnumberOfBlends
argument, that was stripped by_convertBlendOpToArgs
early on insidegeneralizeCommands
function.However, I'm not sure this is the right fix. Also the roundtrip tests fail after this.
It would be nice if @behdad or some of the Adobe folks could have a look.
The text was updated successfully, but these errors were encountered: