From c6ccaa5f1d5aff225d1934ca7df855c6f80cedb2 Mon Sep 17 00:00:00 2001 From: Tal Leming Date: Wed, 28 Sep 2011 18:14:13 +0000 Subject: [PATCH] Support contour identifiers. git-svn-id: http://svn.robofab.com/branches/ufo3k@321 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c --- Lib/ufoLib/glifLib.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Lib/ufoLib/glifLib.py b/Lib/ufoLib/glifLib.py index 3d3189e5b..eb7522a8a 100755 --- a/Lib/ufoLib/glifLib.py +++ b/Lib/ufoLib/glifLib.py @@ -664,7 +664,22 @@ pointTypeOptions = ("move", "line", "offcurve", "curve", "qcurve") def buildOutline(pen, xmlNodes, formatVersion, identifiers): for element, attrs, children in xmlNodes: if element == "contour": - pen.beginPath() + # identifier is not required but it is not part of format 1 + identifier = attrs.get("identifier") + if identifier is not None and formatVersion == 1: + raise GlifLibError("The contour identifier attribute is not allowed in GLIF format 1.") + if identifier is not None: + if identifier in identifiers: + raise GlifLibError("The identifier %s is used more than once." % identifier) + if not identifierValidator(identifier): + raise GlifLibError("The contour identifier %s is not valid." % identifier) + identifiers.add(identifier) + # try to pass the identifier attribute + try: + pen.beginPath(identifier) + except TypeError: + raise DeprecationWarning("The beginPath method now needs an identifier kwarg. The contours identifier value has been discarded.") + # points for subElement, attrs, dummy in children: if subElement != "point": raise GlifLibError("Unknown child element (%s) of contour element." % subElement) @@ -694,12 +709,11 @@ def buildOutline(pen, xmlNodes, formatVersion, identifiers): # identifier is not required but it is not part of format 1 identifier = attrs.get("identifier") if identifier is not None and formatVersion == 1: - raise GlifLibError("The identifier attribute is not allowed in GLIF format 1.") + raise GlifLibError("The point identifier attribute is not allowed in GLIF format 1.") if identifier is not None: if identifier in identifiers: raise GlifLibError("The identifier %s is used more than once." % identifier) - isValid = identifierValidator(identifier) - if not isValid: + if not identifierValidator(identifier): raise GlifLibError("The identifier %s is not valid." % identifier) identifiers.add(identifier) # write to a point pen