diff --git a/Lib/fontTools/ttLib/tables/F__e_a_t.py b/Lib/fontTools/ttLib/tables/F__e_a_t.py index 9e74ebae1..22be4f677 100644 --- a/Lib/fontTools/ttLib/tables/F__e_a_t.py +++ b/Lib/fontTools/ttLib/tables/F__e_a_t.py @@ -41,23 +41,27 @@ class table_F__e_a_t(DefaultTable.DefaultTable): if len(data) >= 4 * (i + 1): (val, lid) = struct.unpack(">HH", data[4*i:4*(i+1)]) allsettings.append((val, lid)) - for f in allfeats: + for i,f in enumerate(allfeats): (fid, nums, offset, flags, lid) = f fobj = Feature() fobj.flags = flags fobj.label = lid self.features[grUtils.num2tag(fid)] = fobj fobj.settings = {} + fobj.default = None + fobj.index = i for i in range(offset, offset + nums): if i >= len(allsettings): continue (vid, vlid) = allsettings[i] fobj.settings[vid] = vlid + if fobj.default is None: + fobj.default = vid def compile(self, ttFont): fdat = "" vdat = "" offset = 0 - for f, v in sorted(self.features.items()): + for f, v in sorted(self.features.items(), key=lambda x:x[1].index): fnum = grUtils.tag2num(f) if self.version >= 2.0: fdat += struct.pack(">LHHLHH", grUtils.tag2num(f), len(v.settings), @@ -68,7 +72,7 @@ class table_F__e_a_t(DefaultTable.DefaultTable): else: fdat += struct.pack(">HHLHH", grUtils.tag2num(f), len(v.settings), offset * 4 + 12 + 12 * len(self.features), v.flags, v.label) - for s, l in sorted(v.settings.items()): + for s, l in sorted(v.settings.items(), key=lambda x:(-1, x[1]) if x[0] == v.default else x): vdat += struct.pack(">HH", s, l) offset += len(v.settings) hdr = sstruct.pack(Feat_hdr_format, self) @@ -77,8 +81,9 @@ class table_F__e_a_t(DefaultTable.DefaultTable): def toXML(self, writer, ttFont): writer.simpletag('version', version=self.version) writer.newline() - for f, v in sorted(self.features.items()): - writer.begintag('feature', fid=f, label=v.label, flags=v.flags) + for f, v in sorted(self.features.items(), key=lambda x:x[1].index): + writer.begintag('feature', fid=f, label=v.label, flags=v.flags, + default=(v.default if v.default else 0)) writer.newline() for s, l in sorted(v.settings.items()): writer.simpletag('setting', value=s, label=l) @@ -94,6 +99,8 @@ class table_F__e_a_t(DefaultTable.DefaultTable): fobj = Feature() fobj.flags = int(safeEval(attrs['flags'])) fobj.label = int(safeEval(attrs['label'])) + fobj.default = int(safeEval(attrs.get('default','0'))) + fobj.index = len(self.features) self.features[fid] = fobj fobj.settings = {} for element in content: diff --git a/Lib/fontTools/ttLib/tables/S__i_l_f.py b/Lib/fontTools/ttLib/tables/S__i_l_f.py index 027bd235d..2afd71eaa 100644 --- a/Lib/fontTools/ttLib/tables/S__i_l_f.py +++ b/Lib/fontTools/ttLib/tables/S__i_l_f.py @@ -195,7 +195,7 @@ def disassemble(aCode): pc = 0 res = [] while pc < codelen: - opcode = ord(aCode[pc:pc+1]) + opcode = byteord(aCode[pc:pc+1]) if opcode > len(aCode_info): instr = aCode_info[0] else: @@ -203,7 +203,7 @@ def disassemble(aCode): pc += 1 if instr[1] != 0 and pc >= codelen : return res if instr[1] == -1: - count = ord(aCode[pc]) + count = byteord(aCode[pc]) fmt = "%dB" % count pc += 1 elif instr[1] == 0: @@ -230,7 +230,7 @@ def assemble(instrs): if m.group(2): if parmfmt == 0: continue - parms = map(int, re.split(",\s*", m.group(2))) + parms = [int(x) for x in re.split(",\s*", m.group(2))] if parmfmt == -1: l = len(parms) res.append(struct.pack(("%dB" % (l+1)), l, *parms)) @@ -727,9 +727,6 @@ class Pass(object): oConstraints[i] = oConstraints[i+1] self.ruleConstraints = [(data[s:e] if (e-s > 1) else "") for (s,e) in zip(oConstraints, oConstraints[1:])] data = data[oConstraints[-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 zip(oActions, oActions[1:])] data = data[oActions[-1]:] # not using debug @@ -737,8 +734,8 @@ class Pass(object): def compile(self, ttFont, base, version=2.0): # build it all up backwards oActions = reduce(lambda a, x: (a[0]+len(x), a[1]+[a[0]]), self.actions + [""], (0, []))[1] - oConstraints = reduce(lambda a, x: (a[0]+len(x), a[1]+[a[0]]), self.ruleConstraints + [""], (0, []))[1] - constraintCode = "".join(self.ruleConstraints) + oConstraints = reduce(lambda a, x: (a[0]+len(x), a[1]+[a[0]]), self.ruleConstraints + [""], (1, []))[1] + constraintCode = "\000" + "".join(self.ruleConstraints) transes = [] for t in self.stateTrans: t.byteswap() diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat index d3e2b71cf..9c23f4d78 100644 --- a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat +++ b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat @@ -3,13 +3,13 @@ - + - + - + diff --git a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf index 01d3be5e3..4b82d1c73 100644 --- a/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf +++ b/Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf @@ -32,6 +32,12 @@ + PUT_GLYPH_8BIT_OBS(0) + ASSOC(0, 1) + NEXT + DELETE + NEXT + RET_ZERO @@ -63,6 +69,22 @@ + COPY_NEXT + PUT_COPY(0) + PUSH_BYTE(-1) + ATTR_SET_SLOT(2) + PUSH_BYTE(0) + ATTR_SET(17) + PUSH_GLYPH_ATTR_OBS(6, 0) + ATTR_SET(8) + PUSH_GLYPH_ATTR_OBS(7, 0) + ATTR_SET(9) + PUSH_ATT_TO_GATTR_OBS(6, 0) + ATTR_SET(3) + PUSH_ATT_TO_GATTR_OBS(7, 0) + ATTR_SET(4) + NEXT + RET_ZERO