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