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