Use glyph names not glyph ids
This commit is contained in:
parent
860a8e0522
commit
eb9eebf972
@ -85,13 +85,9 @@ class table_G__l_a_t(DefaultTable.DefaultTable):
|
|||||||
|
|
||||||
gloc = ttFont['Gloc']
|
gloc = ttFont['Gloc']
|
||||||
self.attributes = {}
|
self.attributes = {}
|
||||||
glyphorder = ttFont.getGlyphOrder()
|
|
||||||
count = 0
|
count = 0
|
||||||
numg = len(glyphorder)
|
|
||||||
for s,e in zip(gloc,gloc[1:]):
|
for s,e in zip(gloc,gloc[1:]):
|
||||||
if count >= len(glyphorder):
|
self.attributes[ttFont.getGlyphName(count)] = decoder(data[s:e])
|
||||||
glyphorder.append('pseudo_{}'.format(count - numg + 1))
|
|
||||||
self.attributes[glyphorder[count]] = decoder(data[s:e])
|
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
def decompileAttributes12(self, data, fmt):
|
def decompileAttributes12(self, data, fmt):
|
||||||
@ -131,16 +127,9 @@ class table_G__l_a_t(DefaultTable.DefaultTable):
|
|||||||
encoder = self.compileAttributes3
|
encoder = self.compileAttributes3
|
||||||
|
|
||||||
glocs = []
|
glocs = []
|
||||||
glyphorder = ttFont.getGlyphOrder()
|
for n in range(len(self.attributes)):
|
||||||
count = 1
|
|
||||||
gname = "pseudo_{}".format(count)
|
|
||||||
while gname in self.attributes :
|
|
||||||
glyphorder.append(gname)
|
|
||||||
count += 1
|
|
||||||
gname = "pseudo_{}".format(count)
|
|
||||||
for n in glyphorder :
|
|
||||||
glocs.append(len(data))
|
glocs.append(len(data))
|
||||||
data += encoder(self.attributes[n])
|
data += encoder(self.attributes[ttFont.getGlyphName(n)])
|
||||||
glocs.append(len(data))
|
glocs.append(len(data))
|
||||||
ttFont['Gloc'].set(glocs)
|
ttFont['Gloc'].set(glocs)
|
||||||
|
|
||||||
@ -169,7 +158,7 @@ class table_G__l_a_t(DefaultTable.DefaultTable):
|
|||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
writer.simpletag('version', version=self.version, compressionScheme=self.scheme)
|
writer.simpletag('version', version=self.version, compressionScheme=self.scheme)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
for n, a in sorted(self.attributes.items()):
|
for n, a in sorted(self.attributes.items(), key=lambda x:ttFont.getGlyphID(x[0])):
|
||||||
writer.begintag('glyph', name=n)
|
writer.begintag('glyph', name=n)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
if hasattr(a, 'octabox'):
|
if hasattr(a, 'octabox'):
|
||||||
|
@ -372,7 +372,7 @@ class Silf(object):
|
|||||||
(numPseudo,) = struct.unpack(">H", data[:2])
|
(numPseudo,) = struct.unpack(">H", data[:2])
|
||||||
for i in range(numPseudo):
|
for i in range(numPseudo):
|
||||||
pseudo = sstruct.unpack(Silf_pseudomap_format, data[8+6*i:14+6*i], _Object())
|
pseudo = sstruct.unpack(Silf_pseudomap_format, data[8+6*i:14+6*i], _Object())
|
||||||
self.pMap[pseudo.unicode] = pseudo.nPseudo
|
self.pMap[pseudo.unicode] = ttFont.getGlyphName(pseudo.nPseudo)
|
||||||
data = data[8 + 6 * numPseudo:]
|
data = data[8 + 6 * numPseudo:]
|
||||||
currpos = sstruct.calcsize(Silf_part1_format) + sstruct.calcsize(Silf_justify_format) * self.numJLevels + \
|
currpos = sstruct.calcsize(Silf_part1_format) + sstruct.calcsize(Silf_justify_format) * self.numJLevels + \
|
||||||
sstruct.calcsize(Silf_part2_format) + 2 * self.numCritFeatures + 1 + 1 + 4 * numScriptTag + \
|
sstruct.calcsize(Silf_part2_format) + 2 * self.numCritFeatures + 1 + 1 + 4 * numScriptTag + \
|
||||||
@ -413,7 +413,7 @@ class Silf(object):
|
|||||||
currpos = hdroffset + len(data) + 4 * (self.numPasses + 1)
|
currpos = hdroffset + len(data) + 4 * (self.numPasses + 1)
|
||||||
self.pseudosOffset = currpos + len(data1)
|
self.pseudosOffset = currpos + len(data1)
|
||||||
for u, p in sorted(self.pMap.items()):
|
for u, p in sorted(self.pMap.items()):
|
||||||
data1 += struct.pack(">LH", u, p)
|
data1 += struct.pack(">LH", u, ttFont.getGlyphID(p))
|
||||||
data1 += self.classes.compile(ttFont, version)
|
data1 += self.classes.compile(ttFont, version)
|
||||||
currpos += len(data1)
|
currpos += len(data1)
|
||||||
data2 = ""
|
data2 = ""
|
||||||
@ -520,7 +520,7 @@ class Silf(object):
|
|||||||
(tag, attrs, subcontent) = element
|
(tag, attrs, subcontent) = element
|
||||||
if tag == 'pseudo':
|
if tag == 'pseudo':
|
||||||
k = int(attrs['unicode'], 16)
|
k = int(attrs['unicode'], 16)
|
||||||
v = int(safeEval(attrs['pseudo']))
|
v = attrs['pseudo']
|
||||||
self.pMap[k] = v
|
self.pMap[k] = v
|
||||||
elif name == 'classes':
|
elif name == 'classes':
|
||||||
self.classes = Classes()
|
self.classes = Classes()
|
||||||
@ -553,10 +553,9 @@ class Classes(object):
|
|||||||
else:
|
else:
|
||||||
oClasses = struct.unpack((">%dH" % (self.numClass+1)), data[4:6+2*self.numClass])
|
oClasses = struct.unpack((">%dH" % (self.numClass+1)), data[4:6+2*self.numClass])
|
||||||
for s,e in zip(oClasses[:self.numLinear], oClasses[1:self.numLinear+1]):
|
for s,e in zip(oClasses[:self.numLinear], oClasses[1:self.numLinear+1]):
|
||||||
self.linear.append(struct.unpack((">%dH" % ((e-s)/2)), data[s:e]))
|
self.linear.append(map(ttFont.getGlyphName, struct.unpack((">%dH" % ((e-s)/2)), data[s:e])))
|
||||||
for s,e in zip(oClasses[self.numLinear:self.numClass], oClasses[self.numLinear+1:self.numClass+1]):
|
for s,e in zip(oClasses[self.numLinear:self.numClass], oClasses[self.numLinear+1:self.numClass+1]):
|
||||||
nonLin = sstruct.unpack(Silf_lookupclass_format, data[s:s+8], _Object())
|
nonLin = dict([map(ttFont.getGlyphName, struct.unpack(">HH", data[x:x+4])) for x in range(s+8, e, 4)])
|
||||||
nonLin.lookups = [struct.unpack(">HH", data[x:x+4]) for x in range(s+8, e, 4)]
|
|
||||||
self.nonLinear.append(nonLin)
|
self.nonLinear.append(nonLin)
|
||||||
|
|
||||||
def compile(self, ttFont, version=2.0):
|
def compile(self, ttFont, version=2.0):
|
||||||
@ -565,11 +564,13 @@ class Classes(object):
|
|||||||
offset = 8 + 4 * (len(self.linear) + len(self.nonLinear))
|
offset = 8 + 4 * (len(self.linear) + len(self.nonLinear))
|
||||||
for l in self.linear:
|
for l in self.linear:
|
||||||
oClasses.append(len(data) + offset)
|
oClasses.append(len(data) + offset)
|
||||||
data += struct.pack((">%dH" % len(l)), *l)
|
gs = map(ttFont.getGlyphID, l)
|
||||||
|
data += struct.pack((">%dH" % len(l)), *gs)
|
||||||
for l in self.nonLinear:
|
for l in self.nonLinear:
|
||||||
oClasses.append(len(data) + offset)
|
oClasses.append(len(data) + offset)
|
||||||
data += grUtils.bininfo(len(l.lookups))
|
gs = [map(ttFont.getGlyphID, x) for x in l.items()]
|
||||||
data += "".join([struct.pack(">HH", *x) for x in l.lookups])
|
data += grUtils.bininfo(len(gs))
|
||||||
|
data += "".join([struct.pack(">HH", *x) for x in sorted(gs)])
|
||||||
oClasses.append(len(data) + offset)
|
oClasses.append(len(data) + offset)
|
||||||
self.numClass = len(oClasses) - 1
|
self.numClass = len(oClasses) - 1
|
||||||
self.numLinear = len(self.linear)
|
self.numLinear = len(self.linear)
|
||||||
@ -585,7 +586,7 @@ class Classes(object):
|
|||||||
for i,l in enumerate(self.linear):
|
for i,l in enumerate(self.linear):
|
||||||
writer.begintag('linear', index=i)
|
writer.begintag('linear', index=i)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
writer.write(" ".join(map(str, l)))
|
writer.write(" ".join(l))
|
||||||
writer.newline()
|
writer.newline()
|
||||||
writer.endtag('linear')
|
writer.endtag('linear')
|
||||||
writer.newline()
|
writer.newline()
|
||||||
@ -593,11 +594,11 @@ class Classes(object):
|
|||||||
writer.newline()
|
writer.newline()
|
||||||
writer.begintag('nonLinearClasses')
|
writer.begintag('nonLinearClasses')
|
||||||
writer.newline()
|
writer.newline()
|
||||||
for i,l in enumerate(self.nonLinear):
|
for i, l in enumerate(self.nonLinear):
|
||||||
writer.begintag('nonLinear', index=i + self.numLinear)
|
writer.begintag('nonLinear', index=i + self.numLinear)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
for o in l.lookups:
|
for inp, outp in l.items():
|
||||||
writer.simpletag('map', gid=o[0], index=o[1])
|
writer.simpletag('map', match=inp, result=outp)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
writer.endtag('nonLinear')
|
writer.endtag('nonLinear')
|
||||||
writer.newline()
|
writer.newline()
|
||||||
@ -612,22 +613,19 @@ class Classes(object):
|
|||||||
if not isinstance(element, tuple): continue
|
if not isinstance(element, tuple): continue
|
||||||
tag, attrs, subcontent = element
|
tag, attrs, subcontent = element
|
||||||
if tag == 'linear':
|
if tag == 'linear':
|
||||||
e = content_string(subcontent)
|
l = content_string(subcontent).split()
|
||||||
l = [int(x) for x in e.split() if x]
|
|
||||||
self.linear.append(l)
|
self.linear.append(l)
|
||||||
elif name == 'nonLinearClasses':
|
elif name == 'nonLinearClasses':
|
||||||
for element in content:
|
for element in content:
|
||||||
if not isinstance(element, tuple): continue
|
if not isinstance(element, tuple): continue
|
||||||
tag, attrs, subcontent = element
|
tag, attrs, subcontent = element
|
||||||
if tag =='nonLinear':
|
if tag =='nonLinear':
|
||||||
l = _Object()
|
l = {}
|
||||||
l.lookups = []
|
|
||||||
for e in subcontent:
|
for e in subcontent:
|
||||||
if not isinstance(e, tuple): continue
|
if not isinstance(e, tuple): continue
|
||||||
tag, attrs, subsubcontent = e
|
tag, attrs, subsubcontent = e
|
||||||
if tag == 'map':
|
if tag == 'map':
|
||||||
l.lookups.append((int(safeEval(attrs['gid'])), int(safeEval(attrs['index']))))
|
l[attrs['match']] = attrs['result']
|
||||||
l.lookups.sort(key=lambda x: x[0])
|
|
||||||
self.nonLinear.append(l)
|
self.nonLinear.append(l)
|
||||||
|
|
||||||
class Pass(object):
|
class Pass(object):
|
||||||
@ -650,7 +648,7 @@ class Pass(object):
|
|||||||
for i in range(numRange):
|
for i in range(numRange):
|
||||||
(first, last, col) = struct.unpack(">3H", data[6*i:6*i+6])
|
(first, last, col) = struct.unpack(">3H", data[6*i:6*i+6])
|
||||||
for g in range(first, last+1):
|
for g in range(first, last+1):
|
||||||
self.colMap[g] = col
|
self.colMap[ttFont.getGlyphName(g)] = col
|
||||||
data = data[6*numRange:]
|
data = data[6*numRange:]
|
||||||
oRuleMap = struct.unpack_from((">%dH" % (self.numSuccess + 1)), data)
|
oRuleMap = struct.unpack_from((">%dH" % (self.numSuccess + 1)), data)
|
||||||
data = data[2+2*self.numSuccess:]
|
data = data[2+2*self.numSuccess:]
|
||||||
@ -703,7 +701,8 @@ class Pass(object):
|
|||||||
self.startStates = [0]
|
self.startStates = [0]
|
||||||
oRuleMap = reduce(lambda (a,b), x: (a+len(x), b+[a]), self.rules+[[]], (0, []))[1]
|
oRuleMap = reduce(lambda (a,b), x: (a+len(x), b+[a]), self.rules+[[]], (0, []))[1]
|
||||||
passRanges = []
|
passRanges = []
|
||||||
for e in grUtils.entries(self.colMap, sameval = True):
|
gidcolmap = dict([(ttFont.getGlyphID(x[0]), x[1]) for x in self.colMap.items()])
|
||||||
|
for e in grUtils.entries(gidcolmap, sameval = True):
|
||||||
if e[1]:
|
if e[1]:
|
||||||
passRanges.append((e[0], e[0]+e[1]-1, e[2][0]))
|
passRanges.append((e[0], e[0]+e[1]-1, e[2][0]))
|
||||||
self.numRules = len(self.actions)
|
self.numRules = len(self.actions)
|
||||||
@ -737,7 +736,7 @@ class Pass(object):
|
|||||||
writer.begintag('colmap')
|
writer.begintag('colmap')
|
||||||
writer.newline()
|
writer.newline()
|
||||||
currline = ""
|
currline = ""
|
||||||
for (g, c) in sorted(self.colMap.items()):
|
for (g, c) in sorted(self.colMap.items(), key=lambda x:ttFont.getGlyphID(x[0])):
|
||||||
s = "{}={} ".format(g, c)
|
s = "{}={} ".format(g, c)
|
||||||
if len(s) + len(currline) > 80:
|
if len(s) + len(currline) > 80:
|
||||||
writer.write(currline)
|
writer.write(currline)
|
||||||
@ -796,7 +795,7 @@ class Pass(object):
|
|||||||
for w in e.split():
|
for w in e.split():
|
||||||
x = w.split('=')
|
x = w.split('=')
|
||||||
if len(x) != 2 or x[0] == '' or x[1] == '': continue
|
if len(x) != 2 or x[0] == '' or x[1] == '': continue
|
||||||
self.colMap[int(x[0])] = int(x[1])
|
self.colMap[x[0]] = int(x[1])
|
||||||
elif name == 'staterulemap':
|
elif name == 'staterulemap':
|
||||||
for e in content:
|
for e in content:
|
||||||
if not isinstance(e, tuple): continue
|
if not isinstance(e, tuple): continue
|
||||||
|
@ -1326,16 +1326,6 @@ otData = [
|
|||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Feat
|
|
||||||
#
|
|
||||||
|
|
||||||
('Feat', [
|
|
||||||
('Version', 'Version', None, None, 'Version of the feat table-initially set to 0x00010000.'),
|
|
||||||
('FeatureNames', 'FeatureNames', None, None, 'The feature names.'),
|
|
||||||
]),
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# lcar
|
# lcar
|
||||||
#
|
#
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user