Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.5 KiB
Python
Raw Normal View History

""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT)
tool to store its hinting source data.
TSI5 contains the VTT character groups.
"""
2024-02-06 15:47:35 +02:00
from fontTools.misc.textTools import safeEval
2013-11-27 02:34:11 -05:00
from . import DefaultTable
import sys
import array
class table_T_S_I__5(DefaultTable.DefaultTable):
def decompile(self, data, ttFont):
numGlyphs = ttFont["maxp"].numGlyphs
assert len(data) == 2 * numGlyphs
a = array.array("H")
a.frombytes(data)
if sys.byteorder != "big":
a.byteswap()
self.glyphGrouping = {}
for i in range(numGlyphs):
self.glyphGrouping[ttFont.getGlyphName(i)] = a[i]
2015-04-26 02:01:01 -04:00
def compile(self, ttFont):
glyphNames = ttFont.getGlyphOrder()
a = array.array("H")
for i in range(len(glyphNames)):
a.append(self.glyphGrouping.get(glyphNames[i], 0))
if sys.byteorder != "big":
a.byteswap()
return a.tobytes()
2015-04-26 02:01:01 -04:00
def toXML(self, writer, ttFont):
names = sorted(self.glyphGrouping.keys())
for glyphName in names:
writer.simpletag(
"glyphgroup", name=glyphName, value=self.glyphGrouping[glyphName]
)
writer.newline()
2015-04-26 02:01:01 -04:00
def fromXML(self, name, attrs, content, ttFont):
if not hasattr(self, "glyphGrouping"):
self.glyphGrouping = {}
2013-11-27 02:40:30 -05:00
if name != "glyphgroup":
return
self.glyphGrouping[attrs["name"]] = safeEval(attrs["value"])