[ttLib] when importing XML, only set sfntVersion if the font has no reader and is empty (#2376)
* Only set sfntVersion if the font has no reader and is empty * test that sfntVersion is only set if the TTFont instance is new/empty
This commit is contained in:
parent
c96c3ef8fa
commit
b01ea60e9e
@ -93,11 +93,12 @@ class XMLReader(object):
|
|||||||
if not stackSize:
|
if not stackSize:
|
||||||
if name != "ttFont":
|
if name != "ttFont":
|
||||||
raise TTXParseError("illegal root tag: %s" % name)
|
raise TTXParseError("illegal root tag: %s" % name)
|
||||||
sfntVersion = attrs.get("sfntVersion")
|
if self.ttFont.reader is None and not self.ttFont.tables:
|
||||||
if sfntVersion is not None:
|
sfntVersion = attrs.get("sfntVersion")
|
||||||
if len(sfntVersion) != 4:
|
if sfntVersion is not None:
|
||||||
sfntVersion = safeEval('"' + sfntVersion + '"')
|
if len(sfntVersion) != 4:
|
||||||
self.ttFont.sfntVersion = sfntVersion
|
sfntVersion = safeEval('"' + sfntVersion + '"')
|
||||||
|
self.ttFont.sfntVersion = sfntVersion
|
||||||
self.contentStack.append([])
|
self.contentStack.append([])
|
||||||
elif stackSize == 1:
|
elif stackSize == 1:
|
||||||
if subFile is not None:
|
if subFile is not None:
|
||||||
|
@ -46,3 +46,35 @@ def test_registerCustomTableClassStandardName():
|
|||||||
assert font[TABLETAG].compile(font) == b"\x04\x05\x06"
|
assert font[TABLETAG].compile(font) == b"\x04\x05\x06"
|
||||||
finally:
|
finally:
|
||||||
unregisterCustomTableClass(TABLETAG)
|
unregisterCustomTableClass(TABLETAG)
|
||||||
|
|
||||||
|
|
||||||
|
ttxTTF = r"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.9.0">
|
||||||
|
<hmtx>
|
||||||
|
<mtx name=".notdef" width="300" lsb="0"/>
|
||||||
|
</hmtx>
|
||||||
|
</ttFont>
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
ttxOTF = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ttFont sfntVersion="OTTO" ttLibVersion="4.9.0">
|
||||||
|
<hmtx>
|
||||||
|
<mtx name=".notdef" width="300" lsb="0"/>
|
||||||
|
</hmtx>
|
||||||
|
</ttFont>
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def test_sfntVersionFromTTX():
|
||||||
|
# https://github.com/fonttools/fonttools/issues/2370
|
||||||
|
font = TTFont()
|
||||||
|
assert font.sfntVersion == "\x00\x01\x00\x00"
|
||||||
|
ttx = io.StringIO(ttxOTF)
|
||||||
|
# Font is "empty", TTX file will determine sfntVersion
|
||||||
|
font.importXML(ttx)
|
||||||
|
assert font.sfntVersion == "OTTO"
|
||||||
|
ttx = io.StringIO(ttxTTF)
|
||||||
|
# Font is not "empty", sfntVersion in TTX file will be ignored
|
||||||
|
font.importXML(ttx)
|
||||||
|
assert font.sfntVersion == "OTTO"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user