Merge pull request #1 from anthrotype/xml-indent

PR819 fixes: don't write empty <assembly> elements
This commit is contained in:
Jens Kutilek 2017-01-24 15:37:23 +01:00 committed by GitHub
commit 5b40c4f257
4 changed files with 12 additions and 14 deletions

View File

@ -358,7 +358,6 @@ class Glyph(object):
writer.begintag("instructions") writer.begintag("instructions")
writer.newline() writer.newline()
self.program.toXML(writer, ttFont) self.program.toXML(writer, ttFont)
writer.newline()
writer.endtag("instructions") writer.endtag("instructions")
writer.newline() writer.newline()
else: else:
@ -379,7 +378,6 @@ class Glyph(object):
writer.begintag("instructions") writer.begintag("instructions")
writer.newline() writer.newline()
self.program.toXML(writer, ttFont) self.program.toXML(writer, ttFont)
writer.newline()
writer.endtag("instructions") writer.endtag("instructions")
writer.newline() writer.newline()

View File

@ -246,7 +246,10 @@ class Program(object):
writer.newline() writer.newline()
writer.dumphex(self.getBytecode()) writer.dumphex(self.getBytecode())
writer.endtag("bytecode") writer.endtag("bytecode")
writer.newline()
else: else:
if not assembly:
return
writer.begintag("assembly") writer.begintag("assembly")
writer.newline() writer.newline()
i = 0 i = 0
@ -279,11 +282,16 @@ class Program(object):
if _indentRE.match(instr): if _indentRE.match(instr):
indent += 1 indent += 1
writer.endtag("assembly") writer.endtag("assembly")
writer.newline()
else: else:
bytecode = self.getBytecode()
if not bytecode:
return
writer.begintag("bytecode") writer.begintag("bytecode")
writer.newline() writer.newline()
writer.dumphex(self.getBytecode()) writer.dumphex(bytecode)
writer.endtag("bytecode") writer.endtag("bytecode")
writer.newline()
def fromXML(self, name, attrs, content, ttFont): def fromXML(self, name, attrs, content, ttFont):
if name == "assembly": if name == "assembly":
@ -295,7 +303,7 @@ class Program(object):
self.fromBytecode(readHex(content)) self.fromBytecode(readHex(content))
def _assemble(self): def _assemble(self):
assembly = self.assembly assembly = getattr(self, 'assembly', [])
if isinstance(assembly, type([])): if isinstance(assembly, type([])):
assembly = ' '.join(assembly) assembly = ' '.join(assembly)
bytecode = [] bytecode = []
@ -420,7 +428,7 @@ class Program(object):
def _disassemble(self, preserve=False): def _disassemble(self, preserve=False):
assembly = [] assembly = []
i = 0 i = 0
bytecode = self.bytecode bytecode = getattr(self, 'bytecode', [])
numBytecode = len(bytecode) numBytecode = len(bytecode)
while i < numBytecode: while i < numBytecode:
op = bytecode[i] op = bytecode[i]

View File

@ -37,8 +37,6 @@
<pt x="334" y="0" on="0"/> <pt x="334" y="0" on="0"/>
</contour> </contour>
<instructions> <instructions>
<assembly>
</assembly>
</instructions> </instructions>
</TTGlyph> </TTGlyph>
@ -64,8 +62,6 @@
<pt x="347" y="770" on="0"/> <pt x="347" y="770" on="0"/>
</contour> </contour>
<instructions> <instructions>
<assembly>
</assembly>
</instructions> </instructions>
</TTGlyph> </TTGlyph>
@ -111,8 +107,6 @@
<pt x="320" y="430" on="0"/> <pt x="320" y="430" on="0"/>
</contour> </contour>
<instructions> <instructions>
<assembly>
</assembly>
</instructions> </instructions>
</TTGlyph> </TTGlyph>
@ -178,8 +172,6 @@
<pt x="320" y="430" on="0"/> <pt x="320" y="430" on="0"/>
</contour> </contour>
<instructions> <instructions>
<assembly>
</assembly>
</instructions> </instructions>
</TTGlyph> </TTGlyph>