added manual implementation of AlternateSubst to get nicer XML output
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@354 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
a1dfa2b77a
commit
b2486125e9
@ -6,6 +6,7 @@ converter objects from otConverters.py.
|
||||
"""
|
||||
|
||||
from otBase import BaseTable, FormatSwitchingBaseTable
|
||||
from types import TupleType
|
||||
|
||||
|
||||
class LookupOrder(BaseTable):
|
||||
@ -227,6 +228,65 @@ class ClassDef(FormatSwitchingBaseTable):
|
||||
classDefs[attrs["glyph"]] = int(attrs["class"])
|
||||
|
||||
|
||||
class AlternateSubst(FormatSwitchingBaseTable):
|
||||
|
||||
def postRead(self, rawTable, font):
|
||||
alternates = {}
|
||||
if self.Format == 1:
|
||||
input = rawTable["Coverage"].glyphs
|
||||
alts = rawTable["AlternateSet"]
|
||||
assert len(input) == len(alts)
|
||||
for i in range(len(input)):
|
||||
alternates[input[i]] = alts[i].Alternate
|
||||
else:
|
||||
assert 0, "unknown format: %s" % self.Format
|
||||
self.alternates = alternates
|
||||
|
||||
def preWrite(self, font):
|
||||
self.Format = 1
|
||||
items = self.alternates.items()
|
||||
for i in range(len(items)):
|
||||
glyphName, set = items[i]
|
||||
items[i] = font.getGlyphID(glyphName), glyphName, set
|
||||
items.sort()
|
||||
cov = Coverage()
|
||||
glyphs = []
|
||||
alternates = []
|
||||
cov.glyphs = glyphs
|
||||
for glyphID, glyphName, set in items:
|
||||
glyphs.append(glyphName)
|
||||
alts = AlternateSet()
|
||||
alts.Alternate = set
|
||||
alternates.append(alts)
|
||||
return {"Coverage": cov, "AlternateSet": alternates}
|
||||
|
||||
def toXML2(self, xmlWriter, font):
|
||||
items = self.alternates.items()
|
||||
items.sort()
|
||||
for glyphName, alternates in items:
|
||||
xmlWriter.begintag("AlternateSet", glyph=glyphName)
|
||||
xmlWriter.newline()
|
||||
for alt in alternates:
|
||||
xmlWriter.simpletag("Alternate", glyph=alt)
|
||||
xmlWriter.newline()
|
||||
xmlWriter.endtag("AlternateSet")
|
||||
xmlWriter.newline()
|
||||
|
||||
def fromXML(self, (name, attrs, content), font):
|
||||
alternates = getattr(self, "alternates", None)
|
||||
if alternates is None:
|
||||
alternates = {}
|
||||
self.alternates = alternates
|
||||
glyphName = attrs["glyph"]
|
||||
set = []
|
||||
alternates[glyphName] = set
|
||||
for element in content:
|
||||
if type(element) != TupleType:
|
||||
continue
|
||||
name, attrs, content = element
|
||||
set.append(attrs["glyph"])
|
||||
|
||||
|
||||
#
|
||||
# For each subtable format there is a class. However, we don't really distinguish
|
||||
# between "field name" and "format name": often these are the same. Yet there's
|
||||
|
Loading…
x
Reference in New Issue
Block a user