MCPcopy Create free account
hub / github.com/coldtype/st2 / decompile

Method decompile

ST2/meshtable.py:154–186  ·  view source on GitHub ↗
(self, ttFont)

Source from the content-addressed store, hash-verified

152 self.glyphs = {}
153
154 def decompile(self, ttFont):
155 if self.data is None:
156 from fontTools import ttLib
157 raise ttLib.TTLibError
158 if len(self.data) < meshStrikeHeaderFormatSize:
159 from fontTools import ttLib
160 raise(ttLib.TTLibError, "Strike header too short: Expected %x, got %x.") \
161 % (meshStrikeHeaderFormatSize, len(self.data))
162
163 # read Strike header from raw data
164 sstruct.unpack(meshStrikeHeaderFormat, self.data[:meshStrikeHeaderFormatSize], self)
165
166 # calculate number of glyphs
167 firstGlyphDataOffset, = struct.unpack(">L", \
168 self.data[meshStrikeHeaderFormatSize:meshStrikeHeaderFormatSize + meshGlyphDataOffsetFormatSize])
169 self.numGlyphs = (firstGlyphDataOffset - meshStrikeHeaderFormatSize) // meshGlyphDataOffsetFormatSize - 1
170 # ^ -1 because there's one more offset than glyphs
171
172 # build offset list for single glyph data offsets
173 self.glyphDataOffsets = []
174 for i in range(self.numGlyphs + 1): # + 1 because there's one more offset than glyphs
175 start = i * meshGlyphDataOffsetFormatSize + meshStrikeHeaderFormatSize
176 current_offset, = struct.unpack(">L", self.data[start:start + meshGlyphDataOffsetFormatSize])
177 self.glyphDataOffsets.append(current_offset)
178
179 # iterate through offset list and slice raw data into glyph data records
180 for i in range(self.numGlyphs):
181 current_glyph = Glyph(rawdata=self.data[self.glyphDataOffsets[i]:self.glyphDataOffsets[i+1]], gid=i)
182 current_glyph.decompile(ttFont)
183 self.glyphs[current_glyph.glyphName] = current_glyph
184 del self.glyphDataOffsets
185 del self.numGlyphs
186 del self.data
187
188 def compile(self, ttFont):
189 self.glyphDataOffsets = b""

Callers 1

decompileMethod · 0.95

Calls 2

decompileMethod · 0.95
GlyphClass · 0.85

Tested by

no test coverage detected