[_g_l_y_f] factor out code for writing instructions in toXML

This commit is contained in:
Cosimo Lupo 2017-01-24 17:33:53 +00:00
parent 0aa086a94b
commit 0918f7cf3e
No known key found for this signature in database
GPG Key ID: B61AAAD0B53A6419

View File

@ -354,12 +354,7 @@ class Glyph(object):
if self.isComposite(): if self.isComposite():
for compo in self.components: for compo in self.components:
compo.toXML(writer, ttFont) compo.toXML(writer, ttFont)
if hasattr(self, "program"): haveInstructions = hasattr(self, "program")
writer.begintag("instructions")
writer.newline()
self.program.toXML(writer, ttFont)
writer.endtag("instructions")
writer.newline()
else: else:
last = 0 last = 0
for i in range(self.numberOfContours): for i in range(self.numberOfContours):
@ -374,12 +369,13 @@ class Glyph(object):
last = self.endPtsOfContours[i] + 1 last = self.endPtsOfContours[i] + 1
writer.endtag("contour") writer.endtag("contour")
writer.newline() writer.newline()
if self.numberOfContours: haveInstructions = self.numberOfContours > 0
writer.begintag("instructions") if haveInstructions:
writer.newline() writer.begintag("instructions")
self.program.toXML(writer, ttFont) writer.newline()
writer.endtag("instructions") self.program.toXML(writer, ttFont)
writer.newline() writer.endtag("instructions")
writer.newline()
def fromXML(self, name, attrs, content, ttFont): def fromXML(self, name, attrs, content, ttFont):
if name == "contour": if name == "contour":