Error for cmap in saving a subset font: "OverflowError: unsigned short is greater than maximum"
See original GitHub issueI have a script that makes a “trial font” by subsetting a font, then assigning cut-out unicodes to a single glyph.
This has worked well for me many times, but I am currently confused by an error that is triggered when I try to save a modified font in the script:
Traceback (most recent call last):
File "/Users/stephennixon/project/build/helpers/make-trial-font.py", line 234, in <module>
main()
File "/Users/stephennixon/project/build/helpers/make-trial-font.py", line 209, in main
tempFont.save(tempFontPath.replace(f".temporary.{filetype}",f".{nameSuffix}.{filetype}"))
File "/Users/stephennixon/project/venv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 185, in save
writer_reordersTables = self._save(tmp)
File "/Users/stephennixon/project/venv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 225, in _save
self._writeTable(tag, writer, done, tableCache)
File "/Users/stephennixon/project/venv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 658, in _writeTable
tabledata = self.getTableData(tag)
File "/Users/stephennixon/project/venv/lib/python3.10/site-packages/fontTools/ttLib/ttFont.py", line 680, in getTableData
return self.tables[tag].compile(self)
File "/Users/stephennixon/project/venv/lib/python3.10/site-packages/fontTools/ttLib/tables/_c_m_a_p.py", line 184, in compile
chunk = table.compile(ttFont)
File "/Users/stephennixon/project/venv/lib/python3.10/site-packages/fontTools/ttLib/tables/_c_m_a_p.py", line 911, in compile
charCodeArray = array.array("H", endCode + [0] + startCode)
OverflowError: unsigned short is greater than maximum
Other issues suggest that the fix might be something like setting the format of the post table, but this seems to be a problem relating to the cmap table. (Also, setting a format 3 post table doesn’t seem to make a difference, in my initial attempts.)
The cmap table in the current font is version 4, similar to other fonts I’ve successfully run this script on.
Is there anything else I might try to get past this?
Thanks so much for any advice!
Issue Analytics
- State:
- Created a year ago
- Comments:19 (9 by maintainers)
Top Results From Across the Web
otf2ttf OverflowError: unsigned short is greater than maximum
I want to convert the Noto CJK fonts from OTF to TTF (so they work better with Microsoft Word). Here's what happens with ......
Read more >I keep getting overflowError: unsigned short is greater than ...
Sounds like somewhere an integer exceeds the maximum limit that it can hold. Without giving us an exact error code it'll be a...
Read more >comparison of characters in C & python - Stack Overflow
it's actually giving: OverflowError: unsigned byte integer is greater than maximum. and it's because the %c format expects a single byte, ...
Read more >fonttools · PyPI
fontTools is a library for manipulating fonts, written in Python. The project includes the TTX tool, that can convert TrueType and OpenType fonts...
Read more >Diff - platform/external/fonttools - Google Git
TTX now makes more compact + data than in any shipping font I've tested it ... +- Fixed bug where glyphnames were not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Alternatively you could rebuild the cmap from scratch. FontBuilder.setupCharacterMap() makes this fairly trivial, and will add the right subtables depending on the character set. Something like:
glad it worked
up to you; in that case at the very least you’d need to create an subset.Options() passing in as keyword arguments all the options you want, then instantiate a subset.Subsetter(options), call populate method with the set of unicodes or glyphs to keep, and finally call its subset(font) method which will modify the TTFont instance in-place. Something like this