KeyError: 'post' on some fonts that have the 'post' table
See original GitHub issueI initially reported this as https://github.com/rosettatype/hyperglot/issues/24, but it seems to be a fonttools bug:
I’m seeing KeyError: 'post'
on some fonts that have the ‘post’ table.
The attached ZIP contains two test fonts and a simple test script to reproduce the problem.
Here’s the script:
from fontTools.ttLib import TTFont
def process_font(path):
print('processing: %s' % path)
font = TTFont(path, lazy=False)
cmap = font["cmap"]
font.close()
return [chr(c) for c in cmap.getBestCmap().keys()]
filename = 'NotoSansDevanagari-Regular.ttf'
c = process_font(filename)
print(len(c))
filename = 'NotoSansMalayalam-Regular.ttf'
c = process_font(filename)
print(len(c))
…and here’s what I get:
$ python3 fonttools_test.py
processing: NotoSansDevanagari-Regular.ttf
270
processing: NotoSansMalayalam-Regular.ttf
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/fontTools/ttLib/ttFont.py", line 372, in __getitem__
return self.tables[tag]
KeyError: 'post'
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
KeyError: 'post' on some fonts that have the 'post' table #24
I see crashes on some fonts (e.g. some of the Noto Fonts) with KeyError: post, e.g: $ hyperglot NotoSansMalayalam-Regular.ttf Traceback ...
Read more >KeyError: -1 when appending new tag to soup in bs4
Each file I iterate over adds a new column to the table in the template. This works fine for the first file. I...
Read more >Python KeyError Exceptions and How to Handle Them
In this tutorial, you'll learn how to handle Python KeyError exceptions. They are often caused by a bad key lookup in a dictionary,...
Read more >KeyError in Python Code - Refinitiv Developer Community
When I run the code, I get the error message: KeyError: 'daily_return_AZN.L'. Fairly new to using Python and Refinitiv ...
Read more >"KeyError: 'body'" Error sending email using "New ... - Odoo
Hi, I am running a Odoo10 community. I get an error when I try to send emails to contacts. Sending online proposals work...
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
The error message I got was: “ValueError: I/O operation on a closed file”. But it was reported as an error occurring during the handling of KeyError: ‘post’, which was confusing. (#2251 takes away the KeyError in this case, so it’s more obvious that there’s an I/O problem happening.)
FWIW, I figured out why the one font failed and the other succeeded:
cmap
subtables are loaded lazily, and usually a subtable get decompiled only once you access itssubtable.cmap
Ergo, in the hyperglot scenario / test script in this issue, if the source font has two unicode cmap subtables that share their data (which is common: (0, 3) and (3, 1) subtables are frequently both present, sharing their data) the cmap is loaded eagerly, and the premature
font.close()
doesn’t cause any trouble. But if the font does not share subtable data, cmap subtables are indeed loaded lazily, in which case the prematurefont.close()
does cause trouble, as the glyph order has then not yet been loaded, and for that, thepost
table is needed.Working font: two unicode cmap subtables Failing font: one unicode cmap subtable