diff --git a/Lib/fontTools/misc/xmlReader.py b/Lib/fontTools/misc/xmlReader.py
index a893f33fe..438549d7d 100644
--- a/Lib/fontTools/misc/xmlReader.py
+++ b/Lib/fontTools/misc/xmlReader.py
@@ -76,10 +76,12 @@ class XMLReader(object):
def _startElementHandler(self, name, attrs):
if self.stackSize == 1 and self.contentOnly:
- # We already know the table we're parsing, move to
+ # We already know the table we're parsing, skip
+ # parsing the table tag and continue to
# stack '2' which begins parsing content
self.contentStack.append([])
self.stackSize = 2
+ return
stackSize = self.stackSize
self.stackSize = stackSize + 1
subFile = attrs.get("src")
diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py
index ab5fa3d27..6170113e0 100644
--- a/Lib/fontTools/ttLib/__init__.py
+++ b/Lib/fontTools/ttLib/__init__.py
@@ -300,7 +300,7 @@ class TTFont(object):
if progress:
progress.set(i)
tag = tables[i]
- if splitTables or splitGlyphs:
+ if splitTables or (splitGlyphs and (tag == 'glyf')):
tablePath = fileNameTemplate % tagToIdentifier(tag)
else:
tablePath = None
@@ -314,8 +314,7 @@ class TTFont(object):
writer.newline()
else:
tableWriter = writer
- self._tableToXML(tableWriter, tag, progress, tablePath, ttLibVersion=version,
- idlefunc=idlefunc, newlinestr=newlinestr, splitGlyphs=splitGlyphs)
+ self._tableToXML(tableWriter, tag, progress, splitGlyphs=splitGlyphs)
if splitTables:
tableWriter.endtag("ttFont")
tableWriter.newline()
@@ -329,8 +328,7 @@ class TTFont(object):
if not hasattr(fileOrPath, "write") and fileOrPath != "-":
writer.close()
- def _tableToXML(self, writer, tag, progress, tablePath, ttLibVersion=None,
- idlefunc=None, newlinestr=None, splitGlyphs=None, quiet=None):
+ def _tableToXML(self, writer, tag, progress, splitGlyphs=False, quiet=None):
if quiet is not None:
deprecateArgument("quiet", "configure logging instead")
if tag in self:
@@ -352,9 +350,9 @@ class TTFont(object):
attrs['raw'] = True
writer.begintag(xmlTag, **attrs)
writer.newline()
- if tag in ("glyf"):
- table.toXML(writer, self, progress, tablePath, ttLibVersion, idlefunc, newlinestr, splitGlyphs)
- elif tag in ("CFF "):
+ if tag == "glyf":
+ table.toXML(writer, self, progress, splitGlyphs)
+ elif tag == "CFF ":
table.toXML(writer, self, progress)
else:
table.toXML(writer, self)
@@ -894,17 +892,9 @@ def nameToIdentifier(name):
return ident
def tagToIdentifier(tag):
- """Convert a table tag to a valid (but UGLY) python identifier,
- as well as a filename that's guaranteed to be unique even on a
- caseless file system. Each character is mapped to two characters.
- Lowercase letters get an underscore before the letter, uppercase
- letters get an underscore after the letter. Trailing spaces are
- trimmed. Illegal characters are escaped as two hex bytes. If the
- result starts with a number (as the result of a hex escape), an
- extra underscore is prepended. Examples:
- 'glyf' -> '_g_l_y_f'
- 'cvt ' -> '_c_v_t'
- 'OS/2' -> 'O_S_2f_2'
+ """This performs the same conversion which nameToIdentifiier does
+ with the additional assertion that the source tag is 4 characters
+ long which is criteria for a valid tag name.
"""
if tag == "GlyphOrder":
return tag
diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
index 4904700c9..edae61e7b 100644
--- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py
+++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
@@ -5,6 +5,7 @@ from collections import namedtuple
from fontTools.misc.py23 import *
from fontTools.misc import sstruct
from fontTools import ttLib
+from fontTools import version
from fontTools.misc.textTools import safeEval, pad
from fontTools.misc.arrayTools import calcBounds, calcIntBounds, pointInRect
from fontTools.misc.bezierTools import calcQuadraticBounds
@@ -22,6 +23,11 @@ from fontTools.ttLib import nameToIdentifier
log = logging.getLogger(__name__)
+# We compute the version the same as is computed in ttlib/__init__
+# so that we can write 'ttLibVersion' attribute of the glyf TTX files
+# when glyf is written to separate files.
+version = ".".join(version.split('.')[:2])
+
#
# The Apple and MS rasterizers behave differently for
# scaled composite components: one does scale first and then translate
@@ -112,9 +118,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
ttFont['maxp'].numGlyphs = len(self.glyphs)
return data
- def toXML(self, writer, ttFont, progress=None, tablePath=None,
- ttLibVersion=None, idlefunc=None, newlinestr=None, splitGlyphs=None):
-
+ def toXML(self, writer, ttFont, progress=None, splitGlyphs=False):
+
writer.newline()
glyphNames = ttFont.getGlyphNames()
writer.comment("The xMin, yMin, xMax and yMax values\nwill be recalculated by the compiler.")
@@ -131,12 +136,15 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
glyph = self[glyphName]
if glyph.numberOfContours:
if splitGlyphs:
- path, ext = os.path.splitext(tablePath)
+ path, ext = os.path.splitext(writer.file.name)
fileNameTemplate = path + ".%s" + ext
glyphPath = fileNameTemplate % nameToIdentifier(glyphName)
- glyphWriter = xmlWriter.XMLWriter(glyphPath, idlefunc=idlefunc,
- newlinestr=newlinestr)
- glyphWriter.begintag("ttFont", ttLibVersion=ttLibVersion)
+ glyphWriter = xmlWriter.XMLWriter(glyphPath, idlefunc=writer.idlefunc,
+ newlinestr=writer.newlinestr)
+ glyphWriter.begintag("ttFont", ttLibVersion=version)
+ glyphWriter.newline()
+ glyphWriter.newline()
+ glyphWriter.begintag("glyf")
glyphWriter.newline()
glyphWriter.newline()
writer.simpletag("TTGlyph", src=os.path.basename(glyphPath))
@@ -155,6 +163,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
glyphWriter.endtag('TTGlyph')
glyphWriter.newline()
if splitGlyphs:
+ glyphWriter.endtag("glyf")
+ glyphWriter.newline()
glyphWriter.endtag("ttFont")
glyphWriter.newline()
glyphWriter.close()
diff --git a/Tests/misc/data/xmlSubFile.xml b/Tests/misc/data/xmlSubFile.xml
new file mode 100644
index 000000000..b0e89903b
--- /dev/null
+++ b/Tests/misc/data/xmlSubFile.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Tests/misc/xmlReader_test.py b/Tests/misc/xmlReader_test.py
index e45720d40..93afd8956 100644
--- a/Tests/misc/xmlReader_test.py
+++ b/Tests/misc/xmlReader_test.py
@@ -153,9 +153,11 @@ class TestXMLReader(unittest.TestCase):
subFileData = (
''
- ''
- '%s'
- ''
+ ''
+ ''
+ '%s'
+ ''
+ ''
''
)%(expectedNameID, expectedPlatform, expectedLangId, expectedContent)
tmp.write(subFileData.encode("utf-8"))