From b0ae563d4d9424b2737d3a7750c4ccff0408eb89 Mon Sep 17 00:00:00 2001 From: Martin Hosken Date: Fri, 15 Sep 2017 11:18:44 +0700 Subject: [PATCH] Add Graphite table tests --- Lib/fontTools/ttLib/tables/F__e_a_t.py | 4 + Lib/fontTools/ttLib/tables/G__l_o_c.py | 6 -- Lib/fontTools/ttLib/tables/S__i_l_f.py | 11 ++- .../tables/data/graphite/graphite_tests.ttf | Bin 0 -> 2260 bytes .../data/graphite/graphite_tests.ttx.Feat | 18 ++++ .../data/graphite/graphite_tests.ttx.Glat | 29 +++++++ .../graphite/graphite_tests.ttx.Glat.setup | 48 +++++++++++ .../data/graphite/graphite_tests.ttx.Silf | 79 ++++++++++++++++++ .../graphite/graphite_tests.ttx.Silf.setup | 48 +++++++++++ .../data/graphite/graphite_tests.ttx.Sill | 12 +++ Tests/ttLib/tables/tables_test.py | 6 ++ 11 files changed, 249 insertions(+), 12 deletions(-) create mode 100644 Tests/ttLib/tables/data/graphite/graphite_tests.ttf create mode 100644 Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat create mode 100644 Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat create mode 100644 Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat.setup create mode 100644 Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf create mode 100644 Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf.setup create mode 100644 Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Sill diff --git a/Lib/fontTools/ttLib/tables/F__e_a_t.py b/Lib/fontTools/ttLib/tables/F__e_a_t.py index 50eb3531d..9e74ebae1 100644 --- a/Lib/fontTools/ttLib/tables/F__e_a_t.py +++ b/Lib/fontTools/ttLib/tables/F__e_a_t.py @@ -58,9 +58,13 @@ class table_F__e_a_t(DefaultTable.DefaultTable): vdat = "" offset = 0 for f, v in sorted(self.features.items()): + fnum = grUtils.tag2num(f) if self.version >= 2.0: fdat += struct.pack(">LHHLHH", grUtils.tag2num(f), len(v.settings), 0, offset * 4 + 12 + 16 * len(self.features), v.flags, v.label) + elif fnum > 65535: # self healing for alphabetic ids + self.version = 2.0 + return self.compile(ttFont) else: fdat += struct.pack(">HHLHH", grUtils.tag2num(f), len(v.settings), offset * 4 + 12 + 12 * len(self.features), v.flags, v.label) diff --git a/Lib/fontTools/ttLib/tables/G__l_o_c.py b/Lib/fontTools/ttLib/tables/G__l_o_c.py index 451904115..d77c4837a 100644 --- a/Lib/fontTools/ttLib/tables/G__l_o_c.py +++ b/Lib/fontTools/ttLib/tables/G__l_o_c.py @@ -2,14 +2,8 @@ from __future__ import print_function, division, absolute_import from fontTools.misc.py23 import * from fontTools.misc import sstruct from fontTools.misc.textTools import safeEval -from itertools import * -from functools import partial from . import DefaultTable import array -import struct -import operator -import warnings -from _ast import Num Gloc_header = ''' > # big endian diff --git a/Lib/fontTools/ttLib/tables/S__i_l_f.py b/Lib/fontTools/ttLib/tables/S__i_l_f.py index 285c7b160..c71712581 100644 --- a/Lib/fontTools/ttLib/tables/S__i_l_f.py +++ b/Lib/fontTools/ttLib/tables/S__i_l_f.py @@ -3,7 +3,6 @@ from fontTools.misc.py23 import * from fontTools.misc import sstruct from fontTools.misc.textTools import safeEval from itertools import * -from functools import partial from . import DefaultTable from . import grUtils from array import array @@ -487,7 +486,7 @@ class Silf(object): writer.newline() writer.endtag('justifications') writer.newline() - if self.numCritFeatures: + if len(self.critFeatures): writer.begintag('critFeatures') writer.newline() writer.write(" ".join(map(str, self.critFeatures))) @@ -510,7 +509,7 @@ class Silf(object): writer.endtag('pseudoMap') writer.newline() self.classes.toXML(writer, ttFont, version) - if self.numPasses: + if len(self.passes): writer.begintag('passes') writer.newline() for i, p in enumerate(self.passes): @@ -723,12 +722,12 @@ class Pass(object): data = data[self.numTransitional * self.numColumns * 2 + 1:] self.passConstraints = data[:pConstraint] data = data[pConstraint:] - for i in range(len(oConstraints)-1,0,-1): + for i in range(len(oConstraints)-2,-1,-1): if oConstraints[i] == 0 : oConstraints[i] = oConstraints[i+1] self.ruleConstraints = [(data[s:e] if (e-s > 1) else "") for (s,e) in izip(oConstraints, oConstraints[1:])] data = data[oConstraints[-1]:] - for i in range(len(oActions)-1,0,-1): + for i in range(len(oActions)-2,-1,-1): if oActions[i] == 0: oActions[i] = oActions[i+1] self.actions = [(data[s:e] if (e-s > 1) else "") for (s,e) in izip(oActions, oActions[1:])] @@ -798,7 +797,7 @@ class Pass(object): writer.newline() writer.begintag('rules') writer.newline() - for i in range(self.numRules): + for i in range(len(self.actions)): writer.begintag('rule', index=i, precontext=self.rulePreContexts[i], sortkey=self.ruleSortKeys[i]) writer.newline() diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttf b/Tests/ttLib/tables/data/graphite/graphite_tests.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ab6a79b5758660e56bbf2d23fce99b4ede597e5c GIT binary patch literal 2260 zcmb`I&ud&&6vw~!y_v}*grqG&8V&W8#F}7!H)f0!X-S&4FpZMLrb0oc$s`$=UnUbt zsEe-M=pP`3x>68YcOouzBVx6nbf*Qy;>t~Th4FLVeQ8p)D&l?Id(QdZbHDeTb7$_A zlhmoJ3RRyi78+|m+*^|}cR=%J%7sSoN_bIf>BH_jQ?4!RdCg&;#qN4}VPt$>mqsPG zjeTLER9>B^{Q3*?m%tXW%X9hJK+4{<^~;q)-3_=E=6<3-u~yz$1*e5s8`q14m7fPz z@~98!lj{KC$8HGU3GBZ0N@F|ot!A*l!R{iQ0+JS(e|x2{U3b&&AoIkms9LBLFTZr< z4bLCGU$1R8nqTS~`F+Ivpe%QK7+zm_z4OF<1>rpq-8??@mdWpay#JfYq=h1rxY?Q; z&8OKnjvLIF_P2D5q#r_ovO1|Y9G}yz7WUOpt9pK=uN~jL4oO(isqA?O~gKWCrQT57uTAJ5r(9 zY~F2NPyEf}Hn_y;{izv~wO#40$BqBa>v6094?H0IedSFkJN2nmCDlqI9bjH}dJ@a) zfjV4&qK8^{lZl?%=abeQcP+s)Iu^W{=q;S|dtRpi?GJUgPY-k;_#p8K)fIe_=qY7_ zuM$12RB$`dGddJ}uL~+_Lz^n8rm7+x*RV#BAJY4^tO4XSb9L?DSJIl+)c_mQ6yJn~ z5-kU|peXNp!dAkLG>ct@y#~t$NS!+RI!%zt z*kA6M|Ib`g8X^0UIAec)R>cz0TSSpAbDEJBsqZ4+Fq!80BC6w0e+a!1N4Q&yi0V|y zt48#8lDql*k=;&ylzm6w$}#%W93z?+sr4wMRo>V6pQ=2^ZgbSi>X=9R-%NoD7WEo^ zlf5c2zQtH3C&Q}osv2{45>?L3=J*5oe`@oJx|09wqr&dnkV>2;H}l=S_4aP26IbPe zYON9_TxMr>ikp?hp2237yZHZG0?sw<<_W@-pYS6{hJKRHE$hxAeRJ?;VN5AaSOL|MKHt}ET^ii(v%^Sh zMrrXmP%K<&)Z$^t$50YHgzy<6T5};%VdufEzM(blr`N^_gIg*$CSp?ajJ69 z?)7-FF&lq7(#K-YnY}Q6cLcM%hDkdb&lvU;g=`)RoO%xqWYn7-Xi;zLAX+$xmSR`W UVWU}=>Px# literal 0 HcmV?d00001 diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat new file mode 100644 index 000000000..d3e2b71cf --- /dev/null +++ b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat new file mode 100644 index 000000000..978853095 --- /dev/null +++ b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat.setup b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat.setup new file mode 100644 index 000000000..8eac7d3d9 --- /dev/null +++ b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat.setup @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf new file mode 100644 index 000000000..01d3be5e3 --- /dev/null +++ b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + c + + + + + + + + + + + .notdef=0 space=0 a=1 b=2 c=0 + + + + + + + + + + + + + PUT_GLYPH_8BIT_OBS(0) + NEXT + RET_ZERO + + + + + 0 1 + 1 1 2 + 0 3 0 + 0 4 0 + 0 0 5 + 0 0 5 + + + + + + + a=0 c=1 + + + + + + + + + + + + 0 + 1 0 + 0 2 + + + + + + + diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf.setup b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf.setup new file mode 100644 index 000000000..8eac7d3d9 --- /dev/null +++ b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf.setup @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Sill b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Sill new file mode 100644 index 000000000..410705950 --- /dev/null +++ b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Sill @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Tests/ttLib/tables/tables_test.py b/Tests/ttLib/tables/tables_test.py index f02c373db..9d03814e1 100644 --- a/Tests/ttLib/tables/tables_test.py +++ b/Tests/ttLib/tables/tables_test.py @@ -229,6 +229,7 @@ TESTS = { "aots/lookupflag_ignore_combination_f1.otf": ('GDEF', 'GSUB'), "aots/lookupflag_ignore_ligatures_f1.otf": ('GDEF', 'GSUB'), "aots/lookupflag_ignore_marks_f1.otf": ('GDEF', 'GSUB'), + "graphite/graphite_tests.ttf": ('Silf', 'Glat', 'Feat', 'Sill'), } @@ -303,6 +304,11 @@ def test_xml_from_xml(testfile, tableTag): xml_expected = read_expected_ttx(testfile, tableTag) font = load_ttx(xml_expected) + name = os.path.splitext(testfile)[0] + setupfile = getpath("%s.ttx.%s.setup" % (name, tagToXML(tableTag))) + if os.path.exists(setupfile): +# import pdb; pdb.set_trace() + font.importXML(setupfile) xml_from_xml = dump_ttx(font, tableTag) assert xml_expected == xml_from_xml