blob: 8fa801bfb2f7b4ad5f7601fe59576fa87b373293 [file] [log] [blame]
Behdad Esfahbod1ae29592014-01-14 15:07:50 +08001from __future__ import print_function, division, absolute_import
Behdad Esfahbod30e691e2013-11-27 17:27:45 -05002from fontTools.misc.py23 import *
3from fontTools.misc.textTools import safeEval
Behdad Esfahbod2b06aaa2013-11-27 02:34:11 -05004from . import DefaultTable
Behdad Esfahbod7ed91ec2013-11-27 15:16:28 -05005import sys
Just7842e561999-12-16 21:34:53 +00006import array
Just7842e561999-12-16 21:34:53 +00007
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)
Behdad Esfahbod180ace62013-11-27 02:40:30 -050016 if sys.byteorder != "big":
Just7842e561999-12-16 21:34:53 +000017 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]])
Behdad Esfahbod180ace62013-11-27 02:40:30 -050027 if sys.byteorder != "big":
Just7842e561999-12-16 21:34:53 +000028 a.byteswap()
29 return a.tostring()
30
31 def toXML(self, writer, ttFont):
Behdad Esfahbodac1b4352013-11-27 04:15:34 -050032 names = sorted(self.glyphGrouping.keys())
Just7842e561999-12-16 21:34:53 +000033 for glyphName in names:
34 writer.simpletag("glyphgroup", name=glyphName, value=self.glyphGrouping[glyphName])
35 writer.newline()
36
Behdad Esfahbod3a9fd302013-11-27 03:19:32 -050037 def fromXML(self, name, attrs, content, ttFont):
Just7842e561999-12-16 21:34:53 +000038 if not hasattr(self, "glyphGrouping"):
39 self.glyphGrouping = {}
Behdad Esfahbod180ace62013-11-27 02:40:30 -050040 if name != "glyphgroup":
Just7842e561999-12-16 21:34:53 +000041 return
42 self.glyphGrouping[attrs["name"]] = safeEval(attrs["value"])
43