From c97956672e7cd4be16b23524ad31ee3bf729da93 Mon Sep 17 00:00:00 2001 From: David Corbett Date: Fri, 3 Apr 2020 19:40:22 -0400 Subject: [PATCH] [feaLib] Emit CID ranges with CIDs not glyph names --- Lib/fontTools/feaLib/ast.py | 2 +- Tests/feaLib/builder_test.py | 3 +- Tests/feaLib/data/cid_range.fea | 6 + Tests/feaLib/data/cid_range.ttx | 244 ++++++++++++++++++++++++++++++++ 4 files changed, 253 insertions(+), 2 deletions(-) create mode 100644 Tests/feaLib/data/cid_range.fea create mode 100644 Tests/feaLib/data/cid_range.ttx diff --git a/Lib/fontTools/feaLib/ast.py b/Lib/fontTools/feaLib/ast.py index f998e306c..e416c0c62 100644 --- a/Lib/fontTools/feaLib/ast.py +++ b/Lib/fontTools/feaLib/ast.py @@ -197,7 +197,7 @@ class GlyphClass(Expression): def add_cid_range(self, start, end, glyphs): if self.curr < len(self.glyphs): self.original.extend(self.glyphs[self.curr:]) - self.original.append(("cid{:05d}".format(start), "cid{:05d}".format(end))) + self.original.append(("\\{}".format(start), "\\{}".format(end))) self.glyphs.extend(glyphs) self.curr = len(self.glyphs) diff --git a/Tests/feaLib/builder_test.py b/Tests/feaLib/builder_test.py index 04002106a..8120d25c1 100644 --- a/Tests/feaLib/builder_test.py +++ b/Tests/feaLib/builder_test.py @@ -43,6 +43,7 @@ def makeTTFont(): damma hamza sukun kasratan lam_meem_jeem noon.final noon.initial by feature lookup sub table uni0327 uni0328 e.fina """.split() + glyphs.extend("cid{:05d}".format(cid) for cid in range(800, 1001 + 1)) font = TTFont() font.setGlyphOrder(glyphs) return font @@ -51,7 +52,7 @@ def makeTTFont(): class BuilderTest(unittest.TestCase): # Feature files in data/*.fea; output gets compared to data/*.ttx. TEST_FEATURE_FILES = """ - Attach enum markClass language_required + Attach cid_range enum markClass language_required GlyphClassDef LigatureCaretByIndex LigatureCaretByPos lookup lookupflag feature_aalt ignore_pos GPOS_1 GPOS_1_zero GPOS_2 GPOS_2b GPOS_3 GPOS_4 GPOS_5 GPOS_6 GPOS_8 diff --git a/Tests/feaLib/data/cid_range.fea b/Tests/feaLib/data/cid_range.fea new file mode 100644 index 000000000..7a17aede9 --- /dev/null +++ b/Tests/feaLib/data/cid_range.fea @@ -0,0 +1,6 @@ +# A CID range can be valid even if it is invalid as a glyph name range. +# For example, [cid00800 - cid01001] is invalid. + +feature zero { + sub [\800 - \1001] by zero; +} zero; diff --git a/Tests/feaLib/data/cid_range.ttx b/Tests/feaLib/data/cid_range.ttx new file mode 100644 index 000000000..48b502b78 --- /dev/null +++ b/Tests/feaLib/data/cid_range.ttx @@ -0,0 +1,244 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +