Skip to content

[cffLib] read CFF font names as latin-1, like the compiler writes them - #4253

Merged
anthrotype merged 1 commit into
fonttools:mainfrom
RavSinghChandan:cff-font-name-latin1
Oct 7, 2026
Merged

anthrotype merged 1 commit into
fonttools:mainfrom
RavSinghChandan:cff-font-name-latin1

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

A CFF font whose name has a non-ASCII byte can be saved but not read back.

CFFFontSet.decompile decodes the Name INDEX with tostr(s), i.e. ASCII, while IndexCompiler writes str items with tobytes(item, encoding="latin1"), and the String INDEX is already read as latin1 (IndexedStrings). So

font["CFF "].cff.fontNames = ["CaféSans"]
font.save(buf)
TTFont(buf)["CFF "]

saves fine and then fails with "UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9", which makes the whole CFF table unreadable.

The names are now decoded as latin1, matching the compiler. Added a test that saves a font with a non-ASCII name and reads it back.

@anthrotype
anthrotype merged commit 8b82255 into fonttools:main Oct 7, 2026
13 checks passed
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

Successfully merging this pull request may close these issues.

2 participants