Break the read function into smaller chunks.
git-svn-id: http://svn.robofab.com/branches/ufo3k@405 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
This commit is contained in:
parent
9042825ed5
commit
a2895df22f
@ -840,10 +840,7 @@ def _readGlyphFromTree(tree, glyphObject=None, pointPen=None, formatVersions=(1,
|
|||||||
if haveSeenAdvance:
|
if haveSeenAdvance:
|
||||||
raise GlifLibError("The advance element occurs more than once.")
|
raise GlifLibError("The advance element occurs more than once.")
|
||||||
haveSeenAdvance = True
|
haveSeenAdvance = True
|
||||||
width = _number(attrs.get("width", 0))
|
_readAdvance(glyphObject, attrs)
|
||||||
_relaxedSetattr(glyphObject, "width", width)
|
|
||||||
height = _number(attrs.get("height", 0))
|
|
||||||
_relaxedSetattr(glyphObject, "height", height)
|
|
||||||
elif element == "unicode":
|
elif element == "unicode":
|
||||||
try:
|
try:
|
||||||
v = attrs.get("hex", "undefined")
|
v = attrs.get("hex", "undefined")
|
||||||
@ -878,35 +875,17 @@ def _readGlyphFromTree(tree, glyphObject=None, pointPen=None, formatVersions=(1,
|
|||||||
if len(children):
|
if len(children):
|
||||||
raise GlifLibError("Unknown children in image element.")
|
raise GlifLibError("Unknown children in image element.")
|
||||||
haveSeenImage = True
|
haveSeenImage = True
|
||||||
imageData = attrs
|
_readImage(glyphObject, attrs)
|
||||||
for attr, default in _transformationInfo:
|
|
||||||
value = default
|
|
||||||
if attr in imageData:
|
|
||||||
value = imageData[attr]
|
|
||||||
imageData[attr] = _number(value)
|
|
||||||
if not imageValidator(imageData):
|
|
||||||
raise GlifLibError("The image element is not properly formatted.")
|
|
||||||
_relaxedSetattr(glyphObject, "image", imageData)
|
|
||||||
elif element == "note":
|
elif element == "note":
|
||||||
if haveSeenNote:
|
if haveSeenNote:
|
||||||
raise GlifLibError("The note element occurs more than once.")
|
raise GlifLibError("The note element occurs more than once.")
|
||||||
haveSeenNote = True
|
haveSeenNote = True
|
||||||
rawNote = "\n".join(children)
|
_readNote(glyphObject, children)
|
||||||
lines = rawNote.split("\n")
|
|
||||||
lines = [line.strip() for line in lines]
|
|
||||||
note = "\n".join(lines)
|
|
||||||
_relaxedSetattr(glyphObject, "note", note)
|
|
||||||
elif element == "lib":
|
elif element == "lib":
|
||||||
if haveSeenLib:
|
if haveSeenLib:
|
||||||
raise GlifLibError("The lib element occurs more than once.")
|
raise GlifLibError("The lib element occurs more than once.")
|
||||||
haveSeenLib = True
|
haveSeenLib = True
|
||||||
from plistFromTree import readPlistFromTree
|
_readLib(glyphObject, children)
|
||||||
assert len(children) == 1
|
|
||||||
lib = readPlistFromTree(children[0])
|
|
||||||
valid, message = libValidator(lib)
|
|
||||||
if not valid:
|
|
||||||
raise GlifLibError(message)
|
|
||||||
_relaxedSetattr(glyphObject, "lib", lib)
|
|
||||||
else:
|
else:
|
||||||
raise GlifLibError("Unknown element in GLIF: %s" % element)
|
raise GlifLibError("Unknown element in GLIF: %s" % element)
|
||||||
# set the collected unicodes
|
# set the collected unicodes
|
||||||
@ -923,6 +902,39 @@ def _readGlyphFromTree(tree, glyphObject=None, pointPen=None, formatVersions=(1,
|
|||||||
raise GlifLibError("The anchors are improperly formatted.")
|
raise GlifLibError("The anchors are improperly formatted.")
|
||||||
_relaxedSetattr(glyphObject, "anchors", anchors)
|
_relaxedSetattr(glyphObject, "anchors", anchors)
|
||||||
|
|
||||||
|
def _readAdvance(glyphObject, attrs):
|
||||||
|
width = _number(attrs.get("width", 0))
|
||||||
|
_relaxedSetattr(glyphObject, "width", width)
|
||||||
|
height = _number(attrs.get("height", 0))
|
||||||
|
_relaxedSetattr(glyphObject, "height", height)
|
||||||
|
|
||||||
|
def _readImage(glyphObject, attrs):
|
||||||
|
imageData = attrs
|
||||||
|
for attr, default in _transformationInfo:
|
||||||
|
value = default
|
||||||
|
if attr in imageData:
|
||||||
|
value = imageData[attr]
|
||||||
|
imageData[attr] = _number(value)
|
||||||
|
if not imageValidator(imageData):
|
||||||
|
raise GlifLibError("The image element is not properly formatted.")
|
||||||
|
_relaxedSetattr(glyphObject, "image", imageData)
|
||||||
|
|
||||||
|
def _readNote(glyphObject, children):
|
||||||
|
rawNote = "\n".join(children)
|
||||||
|
lines = rawNote.split("\n")
|
||||||
|
lines = [line.strip() for line in lines]
|
||||||
|
note = "\n".join(lines)
|
||||||
|
_relaxedSetattr(glyphObject, "note", note)
|
||||||
|
|
||||||
|
def _readLib(glyphObject, children):
|
||||||
|
from plistFromTree import readPlistFromTree
|
||||||
|
assert len(children) == 1
|
||||||
|
lib = readPlistFromTree(children[0])
|
||||||
|
valid, message = libValidator(lib)
|
||||||
|
if not valid:
|
||||||
|
raise GlifLibError(message)
|
||||||
|
_relaxedSetattr(glyphObject, "lib", lib)
|
||||||
|
|
||||||
# ----------------
|
# ----------------
|
||||||
# GLIF to PointPen
|
# GLIF to PointPen
|
||||||
# ----------------
|
# ----------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user