Cosimo Lupo f171719e05 TSI5: set group to 0 (i.e. "AnyGroup") when compiling if glyph name is missing
This is also what VTT does when one does "Prepare font..." and a character is not present in the character groups template file ("CharGrp.txt"): it gets assigned to the default "AnyGroup" group, or 0.

Note that the TSI1 and TSI3 tables do not raise when a glyph name is in the glyphOrder but is missing in their internal mapping; they instead write an empty entry.

This makes easier to merge TSI* tables from different fonts or from earlier revision of the same font containing only a subset of the glyphs.
2016-09-26 16:15:29 +01:00

43 lines
1.2 KiB
Python

from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.misc.textTools import safeEval
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.fromstring(data)
if sys.byteorder != "big":
a.byteswap()
self.glyphGrouping = {}
for i in range(numGlyphs):
self.glyphGrouping[ttFont.getGlyphName(i)] = a[i]
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.tostring()
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()
def fromXML(self, name, attrs, content, ttFont):
if not hasattr(self, "glyphGrouping"):
self.glyphGrouping = {}
if name != "glyphgroup":
return
self.glyphGrouping[attrs["name"]] = safeEval(attrs["value"])