[glifLib] Hard-require x and y coordinates
This commit is contained in:
parent
e4b0486b31
commit
04e1269b41
@ -1416,10 +1416,10 @@ def _validateAndMassagePointStructures(contour, pointAttributes, openContourOffC
|
|||||||
raise GlifLibError("Unknown child elements in point element.")
|
raise GlifLibError("Unknown child elements in point element.")
|
||||||
# x and y are required
|
# x and y are required
|
||||||
for attr in ("x", "y"):
|
for attr in ("x", "y"):
|
||||||
value = element.get(attr)
|
try:
|
||||||
if validate and value is None:
|
point[attr] = _number(point[attr])
|
||||||
raise GlifLibError("Required %s attribute is missing in point element." % attr)
|
except KeyError as e:
|
||||||
point[attr] = _number(value)
|
raise GlifLibError(f"Required {attr} attribute is missing in point element.") from e
|
||||||
# segment type
|
# segment type
|
||||||
pointType = point.pop("type", "offcurve")
|
pointType = point.pop("type", "offcurve")
|
||||||
if validate and pointType not in pointTypeOptions:
|
if validate and pointType not in pointTypeOptions:
|
||||||
|
@ -10,6 +10,7 @@ from fontTools.ufoLib.glifLib import (
|
|||||||
)
|
)
|
||||||
from fontTools.ufoLib.errors import GlifLibError, UnsupportedGLIFFormat, UnsupportedUFOFormat
|
from fontTools.ufoLib.errors import GlifLibError, UnsupportedGLIFFormat, UnsupportedUFOFormat
|
||||||
from fontTools.misc.etree import XML_DECLARATION
|
from fontTools.misc.etree import XML_DECLARATION
|
||||||
|
from fontTools.pens.recordingPen import RecordingPointPen
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
GLYPHSETDIR = getDemoFontGlyphSetPath()
|
GLYPHSETDIR = getDemoFontGlyphSetPath()
|
||||||
@ -250,6 +251,27 @@ class ReadWriteFuncTest:
|
|||||||
with pytest.raises(GlifLibError, match="Forbidden GLIF format version"):
|
with pytest.raises(GlifLibError, match="Forbidden GLIF format version"):
|
||||||
readGlyphFromString(s, _Glyph(), formatVersions=[1])
|
readGlyphFromString(s, _Glyph(), formatVersions=[1])
|
||||||
|
|
||||||
|
def test_read_ensure_x_y(self):
|
||||||
|
"""Ensure that a proper GlifLibError is raised when point coordinates are
|
||||||
|
missing, regardless of validation setting."""
|
||||||
|
|
||||||
|
s = """<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<glyph name="A" format="2">
|
||||||
|
<outline>
|
||||||
|
<contour>
|
||||||
|
<point x="545" y="0" type="line"/>
|
||||||
|
<point x="638" type="line"/>
|
||||||
|
</contour>
|
||||||
|
</outline>
|
||||||
|
</glyph>
|
||||||
|
"""
|
||||||
|
pen = RecordingPointPen()
|
||||||
|
|
||||||
|
with pytest.raises(GlifLibError, match="Required y attribute"):
|
||||||
|
readGlyphFromString(s, _Glyph(), pen)
|
||||||
|
|
||||||
|
with pytest.raises(GlifLibError, match="Required y attribute"):
|
||||||
|
readGlyphFromString(s, _Glyph(), pen, validate=False)
|
||||||
|
|
||||||
def test_GlyphSet_unsupported_ufoFormatVersion(tmp_path, caplog):
|
def test_GlyphSet_unsupported_ufoFormatVersion(tmp_path, caplog):
|
||||||
with pytest.raises(UnsupportedUFOFormat):
|
with pytest.raises(UnsupportedUFOFormat):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user