Skip to content
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

varLib merger dies on CFF->CFF2 conversion #3488

Open
simoncozens opened this issue Apr 26, 2024 · 4 comments
Open

varLib merger dies on CFF->CFF2 conversion #3488

simoncozens opened this issue Apr 26, 2024 · 4 comments

Comments

@simoncozens
Copy link
Collaborator

I'm trying to merge some OTFs to VF because reasons. The first thing that varLib.merge does is convert the default master CFF table to a CFF2. With this font:

from fontTools.ttLib import TTFont
from fontTools.varLib.cff import convertCFFtoCFF2

f = TTFont("NotoSansCJKjp-Light.otf")
f.ensureDecompiled()
convertCFFtoCFF2(f)

dies with

  File "/Users/simon/others-repos/fonttools/Lib/fontTools/cffLib/__init__.py", line 1549, in _read
    return SubrsIndex(file, isCFF2=isCFF2)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/others-repos/fonttools/Lib/fontTools/cffLib/__init__.py", line 878, in __init__
    super(GlobalSubrsIndex, self).__init__(file, isCFF2=isCFF2)
  File "/Users/simon/others-repos/fonttools/Lib/fontTools/cffLib/__init__.py", line 784, in __init__
    assert offSize <= 4, "offSize too large: %s" % offSize
           ^^^^^^^^^^^^
AssertionError: offSize too large: 7
@simoncozens
Copy link
Collaborator Author

The problem seems to be coming when calling .Subrs on a PrivateDict object as part of this little dance:

# At this point, the Subrs and Charstrings are all still T2Charstring class
# easiest to fix this by compiling, then decompiling again
cff.major = 2
file = BytesIO()
cff.compile(file, otFont, isCFF2=True)
file.seek(0)
cff.decompile(file, otFont, isCFF2=True)

@simoncozens
Copy link
Collaborator Author

The problem seems related to the presence of multiple FontDicts in an FDArray. I wonder if we're not descending into the FDArray properly when doing some conversion somewhere. (This is a guess, I know very little about CFF fonts.)

@simoncozens
Copy link
Collaborator Author

Here's an interesting thing. If I change the code in cff.py (line 95) to:

        for fontDict in fdArray:
            fontDict.setCFF2(True)
            print(fontDict.Private, fontDict.Private.rawDict.keys())

it dies. But if I say:

        for fontDict in fdArray:
            print(fontDict.Private, fontDict.Private.rawDict.keys())
            fontDict.setCFF2(True)

it succeeds.

@behdad
Copy link
Member

behdad commented Apr 26, 2024

That suggest some lazy-loading is not happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants