• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT)
2tool to store its hinting source data.
3
4TSI5 contains the VTT character groups.
5"""
6from fontTools.misc.textTools import safeEval
7from . import DefaultTable
8import sys
9import array
10
11
12class table_T_S_I__5(DefaultTable.DefaultTable):
13
14	def decompile(self, data, ttFont):
15		numGlyphs = ttFont['maxp'].numGlyphs
16		assert len(data) == 2 * numGlyphs
17		a = array.array("H")
18		a.frombytes(data)
19		if sys.byteorder != "big": a.byteswap()
20		self.glyphGrouping = {}
21		for i in range(numGlyphs):
22			self.glyphGrouping[ttFont.getGlyphName(i)] = a[i]
23
24	def compile(self, ttFont):
25		glyphNames = ttFont.getGlyphOrder()
26		a = array.array("H")
27		for i in range(len(glyphNames)):
28			a.append(self.glyphGrouping.get(glyphNames[i], 0))
29		if sys.byteorder != "big": a.byteswap()
30		return a.tobytes()
31
32	def toXML(self, writer, ttFont):
33		names = sorted(self.glyphGrouping.keys())
34		for glyphName in names:
35			writer.simpletag("glyphgroup", name=glyphName, value=self.glyphGrouping[glyphName])
36			writer.newline()
37
38	def fromXML(self, name, attrs, content, ttFont):
39		if not hasattr(self, "glyphGrouping"):
40			self.glyphGrouping = {}
41		if name != "glyphgroup":
42			return
43		self.glyphGrouping[attrs["name"]] = safeEval(attrs["value"])
44