diff --git a/Lib/fontTools/ttLib/tables/_f_p_g_m.py b/Lib/fontTools/ttLib/tables/_f_p_g_m.py index f7cc8a3d7..6f7beee8d 100644 --- a/Lib/fontTools/ttLib/tables/_f_p_g_m.py +++ b/Lib/fontTools/ttLib/tables/_f_p_g_m.py @@ -1,14 +1,26 @@ import DefaultTable import array +import ttProgram class table__f_p_g_m(DefaultTable.DefaultTable): def decompile(self, data, ttFont): - self.fpgm = data + program = ttProgram.Program() + program.fromBytecode(data) + self.program = program def compile(self, ttFont): - return self.fpgm + return self.program.getBytecode() + + def toXML(self, writer, ttFont): + self.program.toXML(writer, ttFont) + writer.newline() + + def fromXML(self, (name, attrs, content), ttFont): + program = ttProgram.Program() + program.fromXML((name, attrs, content), ttFont) + self.program = program def __len__(self): - return len(self.fpgm) - + return len(self.program) + diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index a801c6c85..31d9868e3 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -18,6 +18,7 @@ import struct, sstruct import DefaultTable from fontTools import ttLib from fontTools.misc.textTools import safeEval, readHex +import ttProgram import array import Numeric import types @@ -244,10 +245,9 @@ class Glyph: if self.isComposite(): for compo in self.components: compo.toXML(writer, ttFont) - if hasattr(self, "instructions"): + if hasattr(self, "program"): writer.begintag("instructions") - writer.newline() - writer.dumphex(self.instructions) + self.program.toXML(writer, ttFont) writer.endtag("instructions") writer.newline() else: @@ -266,8 +266,7 @@ class Glyph: writer.newline() if self.numberOfContours: writer.begintag("instructions") - writer.newline() - writer.dumphex(self.instructions) + self.program.toXML(writer, ttFont) writer.endtag("instructions") writer.newline() @@ -306,7 +305,11 @@ class Glyph: self.components.append(component) component.fromXML((name, attrs, content), ttFont) elif name == "instructions": - self.instructions = readHex(content) + self.program = ttProgram.Program() + for element in content: + if type(element) == types.StringType: + continue + self.program.fromXML(element, ttFont) def getCompositeMaxpValues(self, glyfTable, maxComponentDepth=1): assert self.isComposite() @@ -341,7 +344,8 @@ class Glyph: if haveInstructions: numInstructions, = struct.unpack(">h", data[:2]) data = data[2:] - self.instructions = data[:numInstructions] + self.program = ttProgram.Program() + self.program.fromBytecode(data[:numInstructions]) data = data[numInstructions:] assert len(data) in (0, 1), "bad composite data" @@ -356,7 +360,8 @@ class Glyph: instructionLength, = struct.unpack(">h", data[:2]) data = data[2:] - self.instructions = data[:instructionLength] + self.program = ttProgram.Program() + self.program.fromBytecode(data[:instructionLength]) data = data[instructionLength:] nCoordinates = self.endPtsOfContours[-1] + 1 flags, xCoordinates, yCoordinates = \ @@ -450,12 +455,13 @@ class Glyph: haveInstructions = 0 for i in range(len(self.components)): if i == lastcomponent: - haveInstructions = hasattr(self, "instructions") + haveInstructions = hasattr(self, "program") more = 0 compo = self.components[i] data = data + compo.compile(more, haveInstructions, glyfTable) if haveInstructions: - data = data + struct.pack(">h", len(self.instructions)) + self.instructions + instructions = self.program.getBytecode() + data = data + struct.pack(">h", len(instructions)) + instructions return data @@ -466,8 +472,8 @@ class Glyph: if ttLib.endian <> "big": endPtsOfContours.byteswap() data = data + endPtsOfContours.tostring() - data = data + struct.pack(">h", len(self.instructions)) - data = data + self.instructions + instructions = self.program.getBytecode() + data = data + struct.pack(">h", len(instructions)) + instructions nCoordinates = len(self.coordinates) # make a copy @@ -608,7 +614,7 @@ class Glyph: return 1 return ( cmp(self.endPtsOfContours, other.endPtsOfContours) or - cmp(self.instructions, other.instructions) + cmp(self.program, other.instructions) ) diff --git a/Lib/fontTools/ttLib/tables/_p_r_e_p.py b/Lib/fontTools/ttLib/tables/_p_r_e_p.py index 005c8eee4..fc92665dc 100644 --- a/Lib/fontTools/ttLib/tables/_p_r_e_p.py +++ b/Lib/fontTools/ttLib/tables/_p_r_e_p.py @@ -1,14 +1,7 @@ -import DefaultTable -import array +from fontTools import ttLib + +superclass = ttLib.getTableClass("fpgm") + +class table__p_r_e_p(superclass): + pass -class table__p_r_e_p(DefaultTable.DefaultTable): - - def decompile(self, data, ttFont): - self.prep = data - - def compile(self, ttFont): - return self.prep - - def __len__(self): - return len(self.prep) -