• 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 __future__ import print_function, division, absolute_import
7from fontTools.misc.py23 import *
8from fontTools.misc.textTools import safeEval
9from . import DefaultTable
10import sys
11import array
12
13
14class table_T_S_I__5(DefaultTable.DefaultTable):
15
16	def decompile(self, data, ttFont):
17		numGlyphs = ttFont['maxp'].numGlyphs
18		assert len(data) == 2 * numGlyphs
19		a = array.array("H")
20		a.fromstring(data)
21		if sys.byteorder != "big": a.byteswap()
22		self.glyphGrouping = {}
23		for i in range(numGlyphs):
24			self.glyphGrouping[ttFont.getGlyphName(i)] = a[i]
25
26	def compile(self, ttFont):
27		glyphNames = ttFont.getGlyphOrder()
28		a = array.array("H")
29		for i in range(len(glyphNames)):
30			a.append(self.glyphGrouping.get(glyphNames[i], 0))
31		if sys.byteorder != "big": a.byteswap()
32		return a.tostring()
33
34	def toXML(self, writer, ttFont):
35		names = sorted(self.glyphGrouping.keys())
36		for glyphName in names:
37			writer.simpletag("glyphgroup", name=glyphName, value=self.glyphGrouping[glyphName])
38			writer.newline()
39
40	def fromXML(self, name, attrs, content, ttFont):
41		if not hasattr(self, "glyphGrouping"):
42			self.glyphGrouping = {}
43		if name != "glyphgroup":
44			return
45		self.glyphGrouping[attrs["name"]] = safeEval(attrs["value"])
46