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

exception against Behdad's 'tofu' font #497

Closed
jbreiden opened this issue Feb 1, 2016 · 6 comments
Closed

exception against Behdad's 'tofu' font #497

jbreiden opened this issue Feb 1, 2016 · 6 comments

Comments

@jbreiden
Copy link

jbreiden commented Feb 1, 2016

wget https://raw.githubusercontent.com/behdad/tofudetector/master/tofu.ttx
ttx /tmp/tofu.ttx
Compiling "/tmp/tofu.ttx" to "/tmp/tofu.ttf"...
Parsing 'GlyphOrder' table...
Parsing 'head' table...
Parsing 'hhea' table...
Parsing 'maxp' table...
Parsing 'OS/2' table...
Parsing 'hmtx' table...
Parsing 'loca' table...
Parsing 'glyf' table...
Parsing 'cmap' table...
ERROR: Unhandled exception has occurred
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/ttx.py", line 374, in main
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/ttx.py", line 347, in process
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/misc/loggingTools.py", line 421, in wrapper
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/ttx.py", line 267, in ttCompile
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/ttLib/__init__.py", line 216, in save
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/ttLib/__init__.py", line 646, in _writeTable
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/ttLib/__init__.py", line 657, in getTableData
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/ttLib/tables/O_S_2f_2.py", line 126, in compile
  File "/usr/local/lib/python2.7/dist-packages/FontTools/fontTools/ttLib/tables/O_S_2f_2.py", line 198, in updateFirstAndLastCharIndex
AttributeError: 'DefaultTable' object has no attribute 'tables'
@behdad
Copy link
Member

behdad commented Feb 1, 2016

Reproduced. Looking into it.

@anthrotype
Copy link
Member

Yeah, that's because in that tofu.ttx file, the cmap table has raw=1 attribute (it's written as raw hex data), and so the XMLReader uses DefaultTable as a table class instead of the regular cmap table class. DefaultTable doesn't have a 'tables' attribute and that updateFirstAndLastCharIndex function fails.

I'll make sure it checks that the instance does have the attribute before accessing it.

@anthrotype
Copy link
Member

@behdad I'd just skip it in this case. WDYT?

diff --git a/Lib/fontTools/ttLib/tables/O_S_2f_2.py b/Lib/fontTools/ttLib/tables/O_S_2f_2.py
index e6bc4bc..821dabc 100644
--- a/Lib/fontTools/ttLib/tables/O_S_2f_2.py
+++ b/Lib/fontTools/ttLib/tables/O_S_2f_2.py
@@ -194,6 +194,11 @@ class table_O_S_2f_2(DefaultTable.DefaultTable):
            setattr(self, name, safeEval(attrs["value"]))

    def updateFirstAndLastCharIndex(self, ttFont):
+       if not hasattr(ttFont['cmap'], 'tables'):
+           # skip if the cmap table class is DefaultTable -- e.g. because of decompile
+           # errors, or because it's written as hex data in the TTX file (with 'raw=1')
+           # https://github.com/behdad/fonttools/issues/497
+           return
        codes = set()
        for table in ttFont['cmap'].tables:
            if table.isUnicode():

@anthrotype
Copy link
Member

Alternatively, I could check if table.__class__ == DefaultTable. That's what TTFont._tableToXML does when deciding if setting attrs['raw'] = True.

@anthrotype
Copy link
Member

@jbreiden you should now be able to compile the tofu.ttx file.

@jbreiden
Copy link
Author

jbreiden commented Feb 2, 2016

successfully ran ttx on tofu.ttx, thank you very much

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

3 participants