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.newline()
self.program.toXML(writer, ttFont)
writer.newline()
writer.endtag("instructions")
writer.newline()
else:
@ -379,7 +378,6 @@ class Glyph(object):
writer.begintag("instructions")
writer.newline()
self.program.toXML(writer, ttFont)
writer.newline()
writer.endtag("instructions")
writer.newline()

View File

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

View File

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

View File

@ -1624,4 +1624,4 @@
IP[ ] /* InterpolatePts */
MDAP[1] /* MoveDirectAbsPt */
ENDF[ ] /* EndFunctionDefinition */
</assembly>
</assembly>