From 5ad27dfb40a9c51c10cf167945bed4005e80e120 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Mon, 8 Oct 2018 21:56:11 +0200 Subject: [PATCH] [Snippets] Handle post table overflow in otf2ttf.py Fixes https://github.com/fonttools/fonttools/issues/1329 --- Snippets/otf2ttf.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Snippets/otf2ttf.py b/Snippets/otf2ttf.py index abb02de9d..45c49f6f6 100755 --- a/Snippets/otf2ttf.py +++ b/Snippets/otf2ttf.py @@ -43,6 +43,7 @@ def otf_to_ttf(ttFont, post_format=POST_FORMAT, **kwargs): glyf.glyphOrder = glyphOrder glyf.glyphs = glyphs_to_quadratic(ttFont.getGlyphSet(), **kwargs) del ttFont["CFF "] + glyf.compile(ttFont) ttFont["maxp"] = maxp = newTable("maxp") maxp.tableVersion = 0x00010000 @@ -56,12 +57,19 @@ def otf_to_ttf(ttFont, post_format=POST_FORMAT, **kwargs): maxp.maxComponentElements = max( len(g.components if hasattr(g, 'components') else []) for g in glyf.glyphs.values()) + maxp.compile(ttFont) post = ttFont["post"] post.formatType = post_format post.extraNames = [] post.mapping = {} post.glyphOrder = glyphOrder + try: + post.compile(ttFont) + except OverflowError: + post.formatType = 3 + print("Glyph names do not fit in 'post' table format 2, using format 3 instead.") + ttFont.sfntVersion = "\000\001\000\000"