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

cfflib - conversion to version 2 throws an exception #3293

Open
acbellini opened this issue Oct 9, 2023 · 4 comments
Open

cfflib - conversion to version 2 throws an exception #3293

acbellini opened this issue Oct 9, 2023 · 4 comments

Comments

@acbellini
Copy link

In this line:

del fontDict.rawDict[key]

The code changes the collection it's iterating on, causing an exception.

@acbellini acbellini changed the title cfflib - conversion to version 2 throws and exception cfflib - conversion to version 2 throws an exception Oct 9, 2023
@anthrotype
Copy link
Member

thanks, yes that looks wrong. Have you got a test font that exposes the bug?
I believe this occurs only when the font that is being converted to CFF2 has a CID-keyed CFF 1.0 table, i.e. one which has a FDArray attribute

@acbellini
Copy link
Author

Yes, I hadn't added it because I am not 100% sure I'm doing things right, but here it is with a code snippet.

The font is extracted from a PDF file, it's a subset of HelveticaNeueLTStd-Thin:

ff3.cff.zip

And this is the code I'm using:
I don't have a parent TT font really, so I'm creating one and setting its glyphorder in order to proceed.

import fontTools.cffLib as cff
import fontTools.ttLib as tt

with open("ff3.cff", "rb") as file:

    otFont = tt.TTFont()
    cFont = cff.CFFFontSet()
    cFont.decompile(file, otFont)
    font0: cff.TopDict = cFont[cFont.fontNames[0]]
    otFont.setGlyphOrder(font0.getGlyphOrder())
    cff2 = cFont.convertCFFToCFF2(otFont)

If incidentally you can point me in the right direction (I need to extract glyphs so that I can draw them with an svgPen) it would be great :D

@anthrotype
Copy link
Member

I need to extract glyphs so that I can draw them with an svgPen

in that case, there's no need to convert the CFF to CFF2 first. But the fact that you only have a CFF table without the font containing it makes it a bit tricky to decompile the table properly.. It may be possible to hack your way around that, but I have never tried.

@acbellini
Copy link
Author

But the fact that you only have a CFF table without the font containing it makes it a bit tricky to decompile the table properly.. It may be possible to hack your way around that, but I have never tried.

Yes, I'm realising that. I may end up converting the file from the command line with fontforge, it worked for this file... not sure for others :) Thanks anyway!

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