Merge pull request #159 from anthrotype/xml-declaration-dbl-quotes
use double quotes in XML declaration like old ufoLib
This commit is contained in:
commit
1a2eb08de5
@ -549,6 +549,12 @@ def readGlyphFromString(aString, glyphObject=None, pointPen=None, formatVersions
|
||||
_readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions, validate=validate)
|
||||
|
||||
|
||||
# we use a custom XML declaration for backward compatibility with older
|
||||
# ufoLib versions which would write it using double quotes.
|
||||
# https://github.com/unified-font-object/ufoLib/issues/158
|
||||
XML_DECLARATION = b"""<?xml version="1.0" encoding="UTF-8"?>\n"""
|
||||
|
||||
|
||||
def _writeGlyphToBytes(
|
||||
glyphName, glyphObject=None, drawPointsFunc=None, writer=None,
|
||||
formatVersion=2, validate=True):
|
||||
@ -592,8 +598,8 @@ def _writeGlyphToBytes(
|
||||
if getattr(glyphObject, "lib", None):
|
||||
_writeLib(glyphObject, root, validate)
|
||||
# return the text
|
||||
data = etree.tostring(
|
||||
root, encoding="utf-8", xml_declaration=True, pretty_print=True
|
||||
data = XML_DECLARATION + etree.tostring(
|
||||
root, encoding="utf-8", xml_declaration=False, pretty_print=True
|
||||
)
|
||||
return data
|
||||
|
||||
|
@ -5,7 +5,8 @@ import unittest
|
||||
from io import open
|
||||
from ufoLib.test.testSupport import getDemoFontGlyphSetPath
|
||||
from ufoLib.glifLib import (
|
||||
GlyphSet, glyphNameToFileName, readGlyphFromString, writeGlyphToString
|
||||
GlyphSet, glyphNameToFileName, readGlyphFromString, writeGlyphToString,
|
||||
XML_DECLARATION,
|
||||
)
|
||||
|
||||
GLYPHSETDIR = getDemoFontGlyphSetPath()
|
||||
@ -137,12 +138,13 @@ class FileNameTests(unittest.TestCase):
|
||||
self.assertEqual(glyphNameToFileName("alt.con", None), "alt._con.glif")
|
||||
|
||||
|
||||
class _Glyph(object):
|
||||
pass
|
||||
|
||||
|
||||
class ReadWriteFuncTest(unittest.TestCase):
|
||||
|
||||
def testRoundTrip(self):
|
||||
class _Glyph(object):
|
||||
pass
|
||||
|
||||
glyph = _Glyph()
|
||||
glyph.name = "a"
|
||||
glyph.unicodes = [0x0061]
|
||||
@ -156,6 +158,10 @@ class ReadWriteFuncTest(unittest.TestCase):
|
||||
s2 = writeGlyphToString(glyph2.name, glyph2)
|
||||
self.assertEqual(s1, s2)
|
||||
|
||||
def testXmlDeclaration(self):
|
||||
s = writeGlyphToString("a", _Glyph())
|
||||
self.assertTrue(s.startswith(XML_DECLARATION.decode("utf-8")))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from ufoLib.test.testSupport import runTests
|
||||
|
Loading…
x
Reference in New Issue
Block a user