Update glyphLib.
Update tests. Fix errors. Add documenation.
This commit is contained in:
parent
5f8b600221
commit
a7aa115fd8
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ dist/
|
|||||||
*.py[cod]
|
*.py[cod]
|
||||||
.eggs/
|
.eggs/
|
||||||
.tox/
|
.tox/
|
||||||
|
/.pytest_cache
|
||||||
|
@ -247,14 +247,15 @@ class UFOReader(object):
|
|||||||
|
|
||||||
# metainfo.plist
|
# metainfo.plist
|
||||||
|
|
||||||
def readMetaInfo(self, validate=self._validate):
|
def readMetaInfo(self, validate=None):
|
||||||
"""
|
"""
|
||||||
Read metainfo.plist. Only used for internal operations.
|
Read metainfo.plist. Only used for internal operations.
|
||||||
|
|
||||||
``validate`` will validate the read data, by default it is set
|
``validate`` will validate the read data, by default it is set
|
||||||
to the class's validate value, can be overridden.
|
to the class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
# should there be a blind try/except with a UFOLibError
|
# should there be a blind try/except with a UFOLibError
|
||||||
# raised in except here (and elsewhere)? It would be nice to
|
# raised in except here (and elsewhere)? It would be nice to
|
||||||
# provide external callers with a single exception to catch.
|
# provide external callers with a single exception to catch.
|
||||||
@ -276,12 +277,14 @@ class UFOReader(object):
|
|||||||
def _readGroups(self):
|
def _readGroups(self):
|
||||||
return self._getPlist(GROUPS_FILENAME, {})
|
return self._getPlist(GROUPS_FILENAME, {})
|
||||||
|
|
||||||
def readGroups(self, validate=self._validate):
|
def readGroups(self, validate=None):
|
||||||
"""
|
"""
|
||||||
Read groups.plist. Returns a dict.
|
Read groups.plist. Returns a dict.
|
||||||
``validate`` will validate the read data, by default it is set to the
|
``validate`` will validate the read data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
# handle up conversion
|
# handle up conversion
|
||||||
if self._formatVersion < 3:
|
if self._formatVersion < 3:
|
||||||
self._upConvertKerning(validate)
|
self._upConvertKerning(validate)
|
||||||
@ -295,7 +298,7 @@ class UFOReader(object):
|
|||||||
raise UFOLibError(message)
|
raise UFOLibError(message)
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
def getKerningGroupConversionRenameMaps(self, validate=self._validate):
|
def getKerningGroupConversionRenameMaps(self, validate=None):
|
||||||
"""
|
"""
|
||||||
Get maps defining the renaming that was done during any
|
Get maps defining the renaming that was done during any
|
||||||
needed kerning group conversion. This method returns a
|
needed kerning group conversion. This method returns a
|
||||||
@ -312,6 +315,8 @@ class UFOReader(object):
|
|||||||
``validate`` will validate the groups, by default it is set to the
|
``validate`` will validate the groups, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
if self._formatVersion >= 3:
|
if self._formatVersion >= 3:
|
||||||
return dict(side1={}, side2={})
|
return dict(side1={}, side2={})
|
||||||
# use the public group reader to force the load and
|
# use the public group reader to force the load and
|
||||||
@ -327,7 +332,7 @@ class UFOReader(object):
|
|||||||
raise UFOLibError("fontinfo.plist is not properly formatted.")
|
raise UFOLibError("fontinfo.plist is not properly formatted.")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def readInfo(self, info, validate=self._validate):
|
def readInfo(self, info, validate=None):
|
||||||
"""
|
"""
|
||||||
Read fontinfo.plist. It requires an object that allows
|
Read fontinfo.plist. It requires an object that allows
|
||||||
setting attributes with names that follow the fontinfo.plist
|
setting attributes with names that follow the fontinfo.plist
|
||||||
@ -337,6 +342,8 @@ class UFOReader(object):
|
|||||||
``validate`` will validate the read data, by default it is set to the
|
``validate`` will validate the read data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
infoDict = self._readInfo()
|
infoDict = self._readInfo()
|
||||||
infoDataToSet = {}
|
infoDataToSet = {}
|
||||||
# version 1
|
# version 1
|
||||||
@ -381,13 +388,15 @@ class UFOReader(object):
|
|||||||
data = self._getPlist(KERNING_FILENAME, {})
|
data = self._getPlist(KERNING_FILENAME, {})
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def readKerning(self, validate=self._validate):
|
def readKerning(self, validate=None):
|
||||||
"""
|
"""
|
||||||
Read kerning.plist. Returns a dict.
|
Read kerning.plist. Returns a dict.
|
||||||
|
|
||||||
``validate`` will validate the kerning data, by default it is set to the
|
``validate`` will validate the kerning data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
# handle up conversion
|
# handle up conversion
|
||||||
if self._formatVersion < 3:
|
if self._formatVersion < 3:
|
||||||
self._upConvertKerning(validate)
|
self._upConvertKerning(validate)
|
||||||
@ -409,13 +418,15 @@ class UFOReader(object):
|
|||||||
|
|
||||||
# lib.plist
|
# lib.plist
|
||||||
|
|
||||||
def readLib(self, validate=self._validate):
|
def readLib(self, validate=None):
|
||||||
"""
|
"""
|
||||||
Read lib.plist. Returns a dict.
|
Read lib.plist. Returns a dict.
|
||||||
|
|
||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
data = self._getPlist(LIB_FILENAME, {})
|
data = self._getPlist(LIB_FILENAME, {})
|
||||||
if validate:
|
if validate:
|
||||||
valid, message = fontLibValidator(data)
|
valid, message = fontLibValidator(data)
|
||||||
@ -455,24 +466,28 @@ class UFOReader(object):
|
|||||||
raise UFOLibError(error)
|
raise UFOLibError(error)
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
def getLayerNames(self, validate=self._validate):
|
def getLayerNames(self, validate=None):
|
||||||
"""
|
"""
|
||||||
Get the ordered layer names from layercontents.plist.
|
Get the ordered layer names from layercontents.plist.
|
||||||
|
|
||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
layerContents = self._readLayerContents(validate)
|
layerContents = self._readLayerContents(validate)
|
||||||
layerNames = [layerName for layerName, directoryName in layerContents]
|
layerNames = [layerName for layerName, directoryName in layerContents]
|
||||||
return layerNames
|
return layerNames
|
||||||
|
|
||||||
def getDefaultLayerName(self, validate=self._validate):
|
def getDefaultLayerName(self, validate=None):
|
||||||
"""
|
"""
|
||||||
Get the default layer name from layercontents.plist.
|
Get the default layer name from layercontents.plist.
|
||||||
|
|
||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
layerContents = self._readLayerContents(validate)
|
layerContents = self._readLayerContents(validate)
|
||||||
for layerName, layerDirectory in layerContents:
|
for layerName, layerDirectory in layerContents:
|
||||||
if layerDirectory == DEFAULT_GLYPHS_DIRNAME:
|
if layerDirectory == DEFAULT_GLYPHS_DIRNAME:
|
||||||
@ -480,7 +495,7 @@ class UFOReader(object):
|
|||||||
# this will already have been raised during __init__
|
# this will already have been raised during __init__
|
||||||
raise UFOLibError("The default layer is not defined in layercontents.plist.")
|
raise UFOLibError("The default layer is not defined in layercontents.plist.")
|
||||||
|
|
||||||
def getGlyphSet(self, layerName=None, validate=self._validate):
|
def getGlyphSet(self, layerName=None, validateRead=None, validateWrite=None):
|
||||||
"""
|
"""
|
||||||
Return the GlyphSet associated with the
|
Return the GlyphSet associated with the
|
||||||
glyphs directory mapped to layerName
|
glyphs directory mapped to layerName
|
||||||
@ -488,13 +503,19 @@ class UFOReader(object):
|
|||||||
the name retrieved with getDefaultLayerName
|
the name retrieved with getDefaultLayerName
|
||||||
will be used.
|
will be used.
|
||||||
|
|
||||||
``validate`` will validate the data, by default it is set to the
|
``validateRead`` will validate the read data, by default it is set to the
|
||||||
|
class's validate value, can be overridden.
|
||||||
|
``validateWrte`` will validate the written data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validateRead is None:
|
||||||
|
validateRead = self._validate
|
||||||
|
if validateWrite is None:
|
||||||
|
validateWrite = self._validate
|
||||||
if layerName is None:
|
if layerName is None:
|
||||||
layerName = self.getDefaultLayerName(validate=validate)
|
layerName = self.getDefaultLayerName(validate=validateRead)
|
||||||
directory = None
|
directory = None
|
||||||
layerContents = self._readLayerContents(validate)
|
layerContents = self._readLayerContents(validateRead)
|
||||||
for storedLayerName, storedLayerDirectory in layerContents:
|
for storedLayerName, storedLayerDirectory in layerContents:
|
||||||
if layerName == storedLayerName:
|
if layerName == storedLayerName:
|
||||||
directory = storedLayerDirectory
|
directory = storedLayerDirectory
|
||||||
@ -502,14 +523,16 @@ class UFOReader(object):
|
|||||||
if directory is None:
|
if directory is None:
|
||||||
raise UFOLibError("No glyphs directory is mapped to \"%s\"." % layerName)
|
raise UFOLibError("No glyphs directory is mapped to \"%s\"." % layerName)
|
||||||
glyphsPath = os.path.join(self._path, directory)
|
glyphsPath = os.path.join(self._path, directory)
|
||||||
return GlyphSet(glyphsPath, ufoFormatVersion=self._formatVersion, validate=validate)
|
return GlyphSet(glyphsPath, ufoFormatVersion=self._formatVersion, validateRead=validateRead, validateWrite=validateWrite)
|
||||||
|
|
||||||
def getCharacterMapping(self, layerName=None, validate=self._validate):
|
def getCharacterMapping(self, layerName=None, validate=None):
|
||||||
"""
|
"""
|
||||||
Return a dictionary that maps unicode values (ints) to
|
Return a dictionary that maps unicode values (ints) to
|
||||||
lists of glyph names.
|
lists of glyph names.
|
||||||
"""
|
"""
|
||||||
glyphSet = self.getGlyphSet(layerName, validate=validate)
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
|
glyphSet = self.getGlyphSet(layerName, validateRead=validate, validateWrite=True)
|
||||||
allUnicodes = glyphSet.getUnicodes()
|
allUnicodes = glyphSet.getUnicodes()
|
||||||
cmap = {}
|
cmap = {}
|
||||||
for glyphName, unicodes in allUnicodes.items():
|
for glyphName, unicodes in allUnicodes.items():
|
||||||
@ -552,7 +575,7 @@ class UFOReader(object):
|
|||||||
result.append(p)
|
result.append(p)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def getImageDirectoryListing(self, validate=self._validate):
|
def getImageDirectoryListing(self, validate=None):
|
||||||
"""
|
"""
|
||||||
Returns a list of all image file names in
|
Returns a list of all image file names in
|
||||||
the images directory. Each of the images will
|
the images directory. Each of the images will
|
||||||
@ -561,6 +584,8 @@ class UFOReader(object):
|
|||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
if self._formatVersion < 3:
|
if self._formatVersion < 3:
|
||||||
return []
|
return []
|
||||||
path = os.path.join(self._path, IMAGES_DIRNAME)
|
path = os.path.join(self._path, IMAGES_DIRNAME)
|
||||||
@ -581,13 +606,15 @@ class UFOReader(object):
|
|||||||
result.append(fileName)
|
result.append(fileName)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def readImage(self, fileName, validate=self._validate):
|
def readImage(self, fileName, validate=None):
|
||||||
"""
|
"""
|
||||||
Return image data for the file named fileName.
|
Return image data for the file named fileName.
|
||||||
|
|
||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
if self._formatVersion < 3:
|
if self._formatVersion < 3:
|
||||||
raise UFOLibError("Reading images is not allowed in UFO %d." % self._formatVersion)
|
raise UFOLibError("Reading images is not allowed in UFO %d." % self._formatVersion)
|
||||||
data = self.readBytesFromPath(os.path.join(IMAGES_DIRNAME, fileName))
|
data = self.readBytesFromPath(os.path.join(IMAGES_DIRNAME, fileName))
|
||||||
@ -860,7 +887,7 @@ class UFOWriter(object):
|
|||||||
remap[dataName] = writeName
|
remap[dataName] = writeName
|
||||||
self._downConversionKerningData = dict(groupRenameMap=remap)
|
self._downConversionKerningData = dict(groupRenameMap=remap)
|
||||||
|
|
||||||
def writeGroups(self, groups, validate=self._validate):
|
def writeGroups(self, groups, validate=None):
|
||||||
"""
|
"""
|
||||||
Write groups.plist. This method requires a
|
Write groups.plist. This method requires a
|
||||||
dict of glyph groups as an argument.
|
dict of glyph groups as an argument.
|
||||||
@ -868,6 +895,8 @@ class UFOWriter(object):
|
|||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
# validate the data structure
|
# validate the data structure
|
||||||
if validate:
|
if validate:
|
||||||
valid, message = groupsValidator(groups)
|
valid, message = groupsValidator(groups)
|
||||||
@ -910,7 +939,7 @@ class UFOWriter(object):
|
|||||||
|
|
||||||
# fontinfo.plist
|
# fontinfo.plist
|
||||||
|
|
||||||
def writeInfo(self, info, validate=self._validate):
|
def writeInfo(self, info, validate=None):
|
||||||
"""
|
"""
|
||||||
Write info.plist. This method requires an object
|
Write info.plist. This method requires an object
|
||||||
that supports getting attributes that follow the
|
that supports getting attributes that follow the
|
||||||
@ -921,6 +950,8 @@ class UFOWriter(object):
|
|||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
# gather version 3 data
|
# gather version 3 data
|
||||||
infoData = {}
|
infoData = {}
|
||||||
for attr in list(fontInfoAttributesVersion3ValueData.keys()):
|
for attr in list(fontInfoAttributesVersion3ValueData.keys()):
|
||||||
@ -950,7 +981,7 @@ class UFOWriter(object):
|
|||||||
|
|
||||||
# kerning.plist
|
# kerning.plist
|
||||||
|
|
||||||
def writeKerning(self, kerning, validate=self._validate):
|
def writeKerning(self, kerning, validate=None):
|
||||||
"""
|
"""
|
||||||
Write kerning.plist. This method requires a
|
Write kerning.plist. This method requires a
|
||||||
dict of kerning pairs as an argument.
|
dict of kerning pairs as an argument.
|
||||||
@ -963,6 +994,8 @@ class UFOWriter(object):
|
|||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
# validate the data structure
|
# validate the data structure
|
||||||
if validate:
|
if validate:
|
||||||
invalidFormatMessage = "The kerning is not properly formatted."
|
invalidFormatMessage = "The kerning is not properly formatted."
|
||||||
@ -1002,7 +1035,7 @@ class UFOWriter(object):
|
|||||||
|
|
||||||
# lib.plist
|
# lib.plist
|
||||||
|
|
||||||
def writeLib(self, libDict, validate=self._validate):
|
def writeLib(self, libDict, validate=None):
|
||||||
"""
|
"""
|
||||||
Write lib.plist. This method requires a
|
Write lib.plist. This method requires a
|
||||||
lib dict as an argument.
|
lib dict as an argument.
|
||||||
@ -1010,6 +1043,8 @@ class UFOWriter(object):
|
|||||||
``validate`` will validate the data, by default it is set to the
|
``validate`` will validate the data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
if validate:
|
if validate:
|
||||||
valid, message = fontLibValidator(libDict)
|
valid, message = fontLibValidator(libDict)
|
||||||
if not valid:
|
if not valid:
|
||||||
@ -1059,9 +1094,6 @@ class UFOWriter(object):
|
|||||||
"""
|
"""
|
||||||
Write the layercontents.plist file. This method *must* be called
|
Write the layercontents.plist file. This method *must* be called
|
||||||
after all glyph sets have been written.
|
after all glyph sets have been written.
|
||||||
|
|
||||||
``validate`` will validate the data, by default it is set to the
|
|
||||||
class's validate value, can be overridden.
|
|
||||||
"""
|
"""
|
||||||
if self.formatVersion < 3:
|
if self.formatVersion < 3:
|
||||||
return
|
return
|
||||||
@ -1092,7 +1124,7 @@ class UFOWriter(object):
|
|||||||
raise UFOLibError("Could not locate a glyph set directory for the layer named %s." % layerName)
|
raise UFOLibError("Could not locate a glyph set directory for the layer named %s." % layerName)
|
||||||
return foundDirectory
|
return foundDirectory
|
||||||
|
|
||||||
def getGlyphSet(self, layerName=None, defaultLayer=True, glyphNameToFileNameFunc=None, validate=self._validate):
|
def getGlyphSet(self, layerName=None, defaultLayer=True, glyphNameToFileNameFunc=None, validateRead=None, validateWrite=None):
|
||||||
"""
|
"""
|
||||||
Return the GlyphSet object associated with the
|
Return the GlyphSet object associated with the
|
||||||
appropriate glyph directory in the .ufo.
|
appropriate glyph directory in the .ufo.
|
||||||
@ -1101,9 +1133,15 @@ class UFOWriter(object):
|
|||||||
that the layer should be saved into the default
|
that the layer should be saved into the default
|
||||||
glyphs directory.
|
glyphs directory.
|
||||||
|
|
||||||
``validate`` will validate the data, by default it is set to the
|
``validateRead`` will validate the read data, by default it is set to the
|
||||||
|
class's validate value, can be overridden.
|
||||||
|
``validateWrte`` will validate the written data, by default it is set to the
|
||||||
class's validate value, can be overridden.
|
class's validate value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validateRead is None:
|
||||||
|
validateRead = self._validate
|
||||||
|
if validateWrite is None:
|
||||||
|
validateWrite = self._validate
|
||||||
# only default can be written in < 3
|
# only default can be written in < 3
|
||||||
if self._formatVersion < 3 and (not defaultLayer or layerName is not None):
|
if self._formatVersion < 3 and (not defaultLayer or layerName is not None):
|
||||||
raise UFOLibError("Only the default layer can be writen in UFO %d." % self.formatVersion)
|
raise UFOLibError("Only the default layer can be writen in UFO %d." % self.formatVersion)
|
||||||
@ -1118,21 +1156,21 @@ class UFOWriter(object):
|
|||||||
raise UFOLibError("A layer name must be provided for non-default layers.")
|
raise UFOLibError("A layer name must be provided for non-default layers.")
|
||||||
# move along to format specific writing
|
# move along to format specific writing
|
||||||
if self.formatVersion == 1:
|
if self.formatVersion == 1:
|
||||||
return self._getGlyphSetFormatVersion1(glyphNameToFileNameFunc=glyphNameToFileNameFunc, validate)
|
return self._getGlyphSetFormatVersion1(validateRead, validateWrite, glyphNameToFileNameFunc=glyphNameToFileNameFunc)
|
||||||
elif self.formatVersion == 2:
|
elif self.formatVersion == 2:
|
||||||
return self._getGlyphSetFormatVersion2(glyphNameToFileNameFunc=glyphNameToFileNameFunc, validate)
|
return self._getGlyphSetFormatVersion2(validateRead, validateWrite, glyphNameToFileNameFunc=glyphNameToFileNameFunc)
|
||||||
elif self.formatVersion == 3:
|
elif self.formatVersion == 3:
|
||||||
return self._getGlyphSetFormatVersion3(layerName=layerName, defaultLayer=defaultLayer, glyphNameToFileNameFunc=glyphNameToFileNameFunc, validate)
|
return self._getGlyphSetFormatVersion3(validateRead, validateWrite, layerName=layerName, defaultLayer=defaultLayer, glyphNameToFileNameFunc=glyphNameToFileNameFunc)
|
||||||
|
|
||||||
def _getGlyphSetFormatVersion1(self, glyphNameToFileNameFunc=None, validate):
|
def _getGlyphSetFormatVersion1(self, validateRead, validateWrite, glyphNameToFileNameFunc=None):
|
||||||
glyphDir = self._makeDirectory(DEFAULT_GLYPHS_DIRNAME)
|
glyphDir = self._makeDirectory(DEFAULT_GLYPHS_DIRNAME)
|
||||||
return GlyphSet(glyphDir, glyphNameToFileNameFunc, ufoFormatVersion=1, validate=validate)
|
return GlyphSet(glyphDir, glyphNameToFileNameFunc, ufoFormatVersion=1, validateRead=validateRead, validateWrite=validateWrite)
|
||||||
|
|
||||||
def _getGlyphSetFormatVersion2(self, glyphNameToFileNameFunc=None, validate):
|
def _getGlyphSetFormatVersion2(self, validateRead, validateWrite, glyphNameToFileNameFunc=None):
|
||||||
glyphDir = self._makeDirectory(DEFAULT_GLYPHS_DIRNAME)
|
glyphDir = self._makeDirectory(DEFAULT_GLYPHS_DIRNAME)
|
||||||
return GlyphSet(glyphDir, glyphNameToFileNameFunc, ufoFormatVersion=2, validate=validate)
|
return GlyphSet(glyphDir, glyphNameToFileNameFunc, ufoFormatVersion=2, validateRead=validateRead, validateWrite=validateWrite)
|
||||||
|
|
||||||
def _getGlyphSetFormatVersion3(self, layerName=None, defaultLayer=True, glyphNameToFileNameFunc=None, validate):
|
def _getGlyphSetFormatVersion3(self, validateRead, validateWrite, layerName=None, defaultLayer=True, glyphNameToFileNameFunc=None):
|
||||||
# if the default flag is on, make sure that the default in the file
|
# if the default flag is on, make sure that the default in the file
|
||||||
# matches the default being written. also make sure that this layer
|
# matches the default being written. also make sure that this layer
|
||||||
# name is not already linked to a non-default layer.
|
# name is not already linked to a non-default layer.
|
||||||
@ -1167,7 +1205,7 @@ class UFOWriter(object):
|
|||||||
# store the mapping
|
# store the mapping
|
||||||
self.layerContents[layerName] = directory
|
self.layerContents[layerName] = directory
|
||||||
# load the glyph set
|
# load the glyph set
|
||||||
return GlyphSet(path, glyphNameToFileNameFunc=glyphNameToFileNameFunc, ufoFormatVersion=3, validate=validate)
|
return GlyphSet(path, glyphNameToFileNameFunc=glyphNameToFileNameFunc, ufoFormatVersion=3, validateRead=validateRead, validateWrite=validateWrite)
|
||||||
|
|
||||||
def renameGlyphSet(self, layerName, newLayerName, defaultLayer=False):
|
def renameGlyphSet(self, layerName, newLayerName, defaultLayer=False):
|
||||||
"""
|
"""
|
||||||
@ -1228,11 +1266,13 @@ class UFOWriter(object):
|
|||||||
|
|
||||||
# /images
|
# /images
|
||||||
|
|
||||||
def writeImage(self, fileName, data, validate=self._validate):
|
def writeImage(self, fileName, data, validate=None):
|
||||||
"""
|
"""
|
||||||
Write data to fileName in the images directory.
|
Write data to fileName in the images directory.
|
||||||
The data must be a valid PNG.
|
The data must be a valid PNG.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validate
|
||||||
if self._formatVersion < 3:
|
if self._formatVersion < 3:
|
||||||
raise UFOLibError("Images are not allowed in UFO %d." % self._formatVersion)
|
raise UFOLibError("Images are not allowed in UFO %d." % self._formatVersion)
|
||||||
if validate:
|
if validate:
|
||||||
@ -1345,7 +1385,7 @@ def writeDataFileAtomically(data, path):
|
|||||||
# Format Conversion Functions
|
# Format Conversion Functions
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
||||||
def convertUFOFormatVersion1ToFormatVersion2(inPath, outPath=None, validateRead=False. validateWrite=True):
|
def convertUFOFormatVersion1ToFormatVersion2(inPath, outPath=None, validateRead=False, validateWrite=True):
|
||||||
"""
|
"""
|
||||||
Function for converting a version format 1 UFO
|
Function for converting a version format 1 UFO
|
||||||
to version format 2. inPath should be a path
|
to version format 2. inPath should be a path
|
||||||
|
@ -104,7 +104,7 @@ class GlyphSet(object):
|
|||||||
|
|
||||||
glyphClass = Glyph
|
glyphClass = Glyph
|
||||||
|
|
||||||
def __init__(self, dirName, glyphNameToFileNameFunc=None, ufoFormatVersion=3, validate=False):
|
def __init__(self, dirName, glyphNameToFileNameFunc=None, ufoFormatVersion=3, validateRead=False, validateWrite=True):
|
||||||
"""
|
"""
|
||||||
'dirName' should be a path to an existing directory.
|
'dirName' should be a path to an existing directory.
|
||||||
|
|
||||||
@ -113,6 +113,9 @@ class GlyphSet(object):
|
|||||||
instance. It should return a file name (including the .glif
|
instance. It should return a file name (including the .glif
|
||||||
extension). The glyphNameToFileName function is called whenever
|
extension). The glyphNameToFileName function is called whenever
|
||||||
a file name is created for a given glyph name.
|
a file name is created for a given glyph name.
|
||||||
|
|
||||||
|
``validateRead`` will validate read operations. It's default is ``False``.
|
||||||
|
``validateWrite`` will validate write operations. It's default is ``True``.
|
||||||
"""
|
"""
|
||||||
self.dirName = dirName
|
self.dirName = dirName
|
||||||
if ufoFormatVersion not in supportedUFOFormatVersions:
|
if ufoFormatVersion not in supportedUFOFormatVersions:
|
||||||
@ -121,15 +124,21 @@ class GlyphSet(object):
|
|||||||
if glyphNameToFileNameFunc is None:
|
if glyphNameToFileNameFunc is None:
|
||||||
glyphNameToFileNameFunc = glyphNameToFileName
|
glyphNameToFileNameFunc = glyphNameToFileName
|
||||||
self.glyphNameToFileName = glyphNameToFileNameFunc
|
self.glyphNameToFileName = glyphNameToFileNameFunc
|
||||||
|
self._validateRead = validateRead
|
||||||
|
self._validateWrite = validateWrite
|
||||||
self.rebuildContents()
|
self.rebuildContents()
|
||||||
self._reverseContents = None
|
self._reverseContents = None
|
||||||
self._glifCache = {}
|
self._glifCache = {}
|
||||||
self._validate = validate
|
|
||||||
|
|
||||||
def rebuildContents(self):
|
def rebuildContents(self, validateRead=None):
|
||||||
"""
|
"""
|
||||||
Rebuild the contents dict by loading contents.plist.
|
Rebuild the contents dict by loading contents.plist.
|
||||||
|
|
||||||
|
``validateRead`` will validate the data, by default it is set to the
|
||||||
|
class's ``validateRead`` value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validateRead is None:
|
||||||
|
validateRead = self._validateRead
|
||||||
contentsPath = os.path.join(self.dirName, "contents.plist")
|
contentsPath = os.path.join(self.dirName, "contents.plist")
|
||||||
try:
|
try:
|
||||||
contents = self._readPlist(contentsPath)
|
contents = self._readPlist(contentsPath)
|
||||||
@ -137,7 +146,7 @@ class GlyphSet(object):
|
|||||||
# missing, consider the glyphset empty.
|
# missing, consider the glyphset empty.
|
||||||
contents = {}
|
contents = {}
|
||||||
# validate the contents
|
# validate the contents
|
||||||
if validate:
|
if validateRead:
|
||||||
invalidFormat = False
|
invalidFormat = False
|
||||||
if not isinstance(contents, dict):
|
if not isinstance(contents, dict):
|
||||||
invalidFormat = True
|
invalidFormat = True
|
||||||
@ -181,7 +190,13 @@ class GlyphSet(object):
|
|||||||
|
|
||||||
# layer info
|
# layer info
|
||||||
|
|
||||||
def readLayerInfo(self, info):
|
def readLayerInfo(self, info, validateRead=None):
|
||||||
|
"""
|
||||||
|
``validateRead`` will validate the data, by default it is set to the
|
||||||
|
class's ``validateRead`` value, can be overridden.
|
||||||
|
"""
|
||||||
|
if validateRead is None:
|
||||||
|
validateRead = self._validateRead
|
||||||
path = os.path.join(self.dirName, LAYERINFO_FILENAME)
|
path = os.path.join(self.dirName, LAYERINFO_FILENAME)
|
||||||
try:
|
try:
|
||||||
infoDict = self._readPlist(path)
|
infoDict = self._readPlist(path)
|
||||||
@ -189,7 +204,8 @@ class GlyphSet(object):
|
|||||||
return
|
return
|
||||||
if not isinstance(infoDict, dict):
|
if not isinstance(infoDict, dict):
|
||||||
raise GlifLibError("layerinfo.plist is not properly formatted.")
|
raise GlifLibError("layerinfo.plist is not properly formatted.")
|
||||||
infoDict = validateLayerInfoVersion3Data(infoDict)
|
if validateRead:
|
||||||
|
infoDict = validateLayerInfoVersion3Data(infoDict)
|
||||||
# populate the object
|
# populate the object
|
||||||
for attr, value in infoDict.items():
|
for attr, value in infoDict.items():
|
||||||
try:
|
try:
|
||||||
@ -197,7 +213,13 @@ class GlyphSet(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise GlifLibError("The supplied layer info object does not support setting a necessary attribute (%s)." % attr)
|
raise GlifLibError("The supplied layer info object does not support setting a necessary attribute (%s)." % attr)
|
||||||
|
|
||||||
def writeLayerInfo(self, info):
|
def writeLayerInfo(self, info, validateWrite=None):
|
||||||
|
"""
|
||||||
|
``validateWrite`` will validate the data, by default it is set to the
|
||||||
|
class's ``validateWrite`` value, can be overridden.
|
||||||
|
"""
|
||||||
|
if validateWrite is None:
|
||||||
|
validateWrite = self._validateWrite
|
||||||
if self.ufoFormatVersion < 3:
|
if self.ufoFormatVersion < 3:
|
||||||
raise GlifLibError("layerinfo.plist is not allowed in UFO %d." % self.ufoFormatVersion)
|
raise GlifLibError("layerinfo.plist is not allowed in UFO %d." % self.ufoFormatVersion)
|
||||||
# gather data
|
# gather data
|
||||||
@ -212,7 +234,8 @@ class GlyphSet(object):
|
|||||||
continue
|
continue
|
||||||
infoData[attr] = value
|
infoData[attr] = value
|
||||||
# validate
|
# validate
|
||||||
infoData = validateLayerInfoVersion3Data(infoData)
|
if validateWrite:
|
||||||
|
infoData = validateLayerInfoVersion3Data(infoData)
|
||||||
# write file
|
# write file
|
||||||
path = os.path.join(self.dirName, LAYERINFO_FILENAME)
|
path = os.path.join(self.dirName, LAYERINFO_FILENAME)
|
||||||
with open(path, "wb") as f:
|
with open(path, "wb") as f:
|
||||||
@ -271,7 +294,7 @@ class GlyphSet(object):
|
|||||||
|
|
||||||
# reading/writing API
|
# reading/writing API
|
||||||
|
|
||||||
def readGlyph(self, glyphName, glyphObject=None, pointPen=None):
|
def readGlyph(self, glyphName, glyphObject=None, pointPen=None, validate=None):
|
||||||
"""
|
"""
|
||||||
Read a .glif file for 'glyphName' from the glyph set. The
|
Read a .glif file for 'glyphName' from the glyph set. The
|
||||||
'glyphObject' argument can be any kind of object (even None);
|
'glyphObject' argument can be any kind of object (even None);
|
||||||
@ -301,7 +324,12 @@ class GlyphSet(object):
|
|||||||
|
|
||||||
readGlyph() will raise KeyError if the glyph is not present in
|
readGlyph() will raise KeyError if the glyph is not present in
|
||||||
the glyph set.
|
the glyph set.
|
||||||
|
|
||||||
|
``validate`` will validate the data, by default it is set to the
|
||||||
|
class's ``validateRead`` value, can be overridden.
|
||||||
"""
|
"""
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validateRead
|
||||||
text = self.getGLIF(glyphName)
|
text = self.getGLIF(glyphName)
|
||||||
self._purgeCachedGLIF(glyphName)
|
self._purgeCachedGLIF(glyphName)
|
||||||
tree = _glifTreeFromString(text)
|
tree = _glifTreeFromString(text)
|
||||||
@ -309,9 +337,9 @@ class GlyphSet(object):
|
|||||||
formatVersions = (1,)
|
formatVersions = (1,)
|
||||||
else:
|
else:
|
||||||
formatVersions = (1, 2)
|
formatVersions = (1, 2)
|
||||||
_readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions)
|
_readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions, validate=validate)
|
||||||
|
|
||||||
def writeGlyph(self, glyphName, glyphObject=None, drawPointsFunc=None, formatVersion=None):
|
def writeGlyph(self, glyphName, glyphObject=None, drawPointsFunc=None, formatVersion=None, validate=None):
|
||||||
"""
|
"""
|
||||||
Write a .glif file for 'glyphName' to the glyph set. The
|
Write a .glif file for 'glyphName' to the glyph set. The
|
||||||
'glyphObject' argument can be any kind of object (even None);
|
'glyphObject' argument can be any kind of object (even None);
|
||||||
@ -338,6 +366,9 @@ class GlyphSet(object):
|
|||||||
The GLIF format version will be chosen based on the ufoFormatVersion
|
The GLIF format version will be chosen based on the ufoFormatVersion
|
||||||
passed during the creation of this object. If a particular format
|
passed during the creation of this object. If a particular format
|
||||||
version is desired, it can be passed with the formatVersion argument.
|
version is desired, it can be passed with the formatVersion argument.
|
||||||
|
|
||||||
|
``validate`` will validate the data, by default it is set to the
|
||||||
|
class's ``validateWrite`` value, can be overridden.
|
||||||
"""
|
"""
|
||||||
if formatVersion is None:
|
if formatVersion is None:
|
||||||
if self.ufoFormatVersion >= 3:
|
if self.ufoFormatVersion >= 3:
|
||||||
@ -349,8 +380,10 @@ class GlyphSet(object):
|
|||||||
raise GlifLibError("Unsupported GLIF format version: %s" % formatVersion)
|
raise GlifLibError("Unsupported GLIF format version: %s" % formatVersion)
|
||||||
if formatVersion == 2 and self.ufoFormatVersion < 3:
|
if formatVersion == 2 and self.ufoFormatVersion < 3:
|
||||||
raise GlifLibError("Unsupported GLIF format version (%d) for UFO format version %d." % (formatVersion, self.ufoFormatVersion))
|
raise GlifLibError("Unsupported GLIF format version (%d) for UFO format version %d." % (formatVersion, self.ufoFormatVersion))
|
||||||
|
if validate is None:
|
||||||
|
validate = self._validateWrite
|
||||||
self._purgeCachedGLIF(glyphName)
|
self._purgeCachedGLIF(glyphName)
|
||||||
data = writeGlyphToString(glyphName, glyphObject, drawPointsFunc, formatVersion=formatVersion)
|
data = writeGlyphToString(glyphName, glyphObject, drawPointsFunc, formatVersion=formatVersion, validate=validate)
|
||||||
fileName = self.contents.get(glyphName)
|
fileName = self.contents.get(glyphName)
|
||||||
if fileName is None:
|
if fileName is None:
|
||||||
fileName = self.glyphNameToFileName(glyphName, self)
|
fileName = self.glyphNameToFileName(glyphName, self)
|
||||||
@ -479,7 +512,7 @@ def glyphNameToFileName(glyphName, glyphSet):
|
|||||||
# GLIF To and From String
|
# GLIF To and From String
|
||||||
# -----------------------
|
# -----------------------
|
||||||
|
|
||||||
def readGlyphFromString(aString, glyphObject=None, pointPen=None, formatVersions=(1, 2)):
|
def readGlyphFromString(aString, glyphObject=None, pointPen=None, formatVersions=(1, 2), validate=False):
|
||||||
"""
|
"""
|
||||||
Read .glif data from a string into a glyph object.
|
Read .glif data from a string into a glyph object.
|
||||||
|
|
||||||
@ -510,12 +543,14 @@ def readGlyphFromString(aString, glyphObject=None, pointPen=None, formatVersions
|
|||||||
|
|
||||||
The formatVersions argument defined the GLIF format versions
|
The formatVersions argument defined the GLIF format versions
|
||||||
that are allowed to be read.
|
that are allowed to be read.
|
||||||
|
|
||||||
|
``validate`` will validate the read data. It is set to ``False`` by default.
|
||||||
"""
|
"""
|
||||||
tree = _glifTreeFromString(aString)
|
tree = _glifTreeFromString(aString)
|
||||||
_readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions)
|
_readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions, validate=validate)
|
||||||
|
|
||||||
|
|
||||||
def writeGlyphToString(glyphName, glyphObject=None, drawPointsFunc=None, writer=None, formatVersion=2):
|
def writeGlyphToString(glyphName, glyphObject=None, drawPointsFunc=None, writer=None, formatVersion=2, validate=True):
|
||||||
"""
|
"""
|
||||||
Return .glif data for a glyph as a UTF-8 encoded string.
|
Return .glif data for a glyph as a UTF-8 encoded string.
|
||||||
The 'glyphObject' argument can be any kind of object (even None);
|
The 'glyphObject' argument can be any kind of object (even None);
|
||||||
@ -540,6 +575,8 @@ def writeGlyphToString(glyphName, glyphObject=None, drawPointsFunc=None, writer=
|
|||||||
proper PointPen methods to transfer the outline to the .glif file.
|
proper PointPen methods to transfer the outline to the .glif file.
|
||||||
|
|
||||||
The GLIF format version can be specified with the formatVersion argument.
|
The GLIF format version can be specified with the formatVersion argument.
|
||||||
|
|
||||||
|
``validate`` will validate the written data. It is set to ``True`` by default.
|
||||||
"""
|
"""
|
||||||
if writer is None:
|
if writer is None:
|
||||||
try:
|
try:
|
||||||
@ -569,27 +606,27 @@ def writeGlyphToString(glyphName, glyphObject=None, drawPointsFunc=None, writer=
|
|||||||
_writeNote(glyphObject, writer)
|
_writeNote(glyphObject, writer)
|
||||||
# image
|
# image
|
||||||
if formatVersion >= 2 and getattr(glyphObject, "image", None):
|
if formatVersion >= 2 and getattr(glyphObject, "image", None):
|
||||||
_writeImage(glyphObject, writer)
|
_writeImage(glyphObject, writer, validate)
|
||||||
# guidelines
|
# guidelines
|
||||||
if formatVersion >= 2 and getattr(glyphObject, "guidelines", None):
|
if formatVersion >= 2 and getattr(glyphObject, "guidelines", None):
|
||||||
_writeGuidelines(glyphObject, writer, identifiers)
|
_writeGuidelines(glyphObject, writer, identifiers, validate)
|
||||||
# anchors
|
# anchors
|
||||||
anchors = getattr(glyphObject, "anchors", None)
|
anchors = getattr(glyphObject, "anchors", None)
|
||||||
if formatVersion >= 2 and anchors:
|
if formatVersion >= 2 and anchors:
|
||||||
_writeAnchors(glyphObject, writer, identifiers)
|
_writeAnchors(glyphObject, writer, identifiers, validate)
|
||||||
# outline
|
# outline
|
||||||
if drawPointsFunc is not None:
|
if drawPointsFunc is not None:
|
||||||
writer.begintag("outline")
|
writer.begintag("outline")
|
||||||
writer.newline()
|
writer.newline()
|
||||||
pen = GLIFPointPen(writer, identifiers=identifiers)
|
pen = GLIFPointPen(writer, identifiers=identifiers, validate=validate)
|
||||||
drawPointsFunc(pen)
|
drawPointsFunc(pen)
|
||||||
if formatVersion == 1 and anchors:
|
if formatVersion == 1 and anchors:
|
||||||
_writeAnchorsFormat1(pen, anchors)
|
_writeAnchorsFormat1(pen, anchors, validate)
|
||||||
writer.endtag("outline")
|
writer.endtag("outline")
|
||||||
writer.newline()
|
writer.newline()
|
||||||
# lib
|
# lib
|
||||||
if getattr(glyphObject, "lib", None):
|
if getattr(glyphObject, "lib", None):
|
||||||
_writeLib(glyphObject, writer)
|
_writeLib(glyphObject, writer, validate)
|
||||||
# end
|
# end
|
||||||
writer.endtag("glyph")
|
writer.endtag("glyph")
|
||||||
writer.newline()
|
writer.newline()
|
||||||
@ -650,9 +687,9 @@ def _writeNote(glyphObject, writer):
|
|||||||
writer.endtag("note")
|
writer.endtag("note")
|
||||||
writer.newline()
|
writer.newline()
|
||||||
|
|
||||||
def _writeImage(glyphObject, writer):
|
def _writeImage(glyphObject, writer, validate):
|
||||||
image = getattr(glyphObject, "image", None)
|
image = getattr(glyphObject, "image", None)
|
||||||
if not imageValidator(image):
|
if validate and not imageValidator(image):
|
||||||
raise GlifLibError("image attribute must be a dict or dict-like object with the proper structure.")
|
raise GlifLibError("image attribute must be a dict or dict-like object with the proper structure.")
|
||||||
attrs = [
|
attrs = [
|
||||||
("fileName", image["fileName"])
|
("fileName", image["fileName"])
|
||||||
@ -667,9 +704,9 @@ def _writeImage(glyphObject, writer):
|
|||||||
writer.simpletag("image", attrs)
|
writer.simpletag("image", attrs)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
|
|
||||||
def _writeGuidelines(glyphObject, writer, identifiers):
|
def _writeGuidelines(glyphObject, writer, identifiers, validate):
|
||||||
guidelines = getattr(glyphObject, "guidelines", [])
|
guidelines = getattr(glyphObject, "guidelines", [])
|
||||||
if not guidelinesValidator(guidelines):
|
if validate and not guidelinesValidator(guidelines):
|
||||||
raise GlifLibError("guidelines attribute does not have the proper structure.")
|
raise GlifLibError("guidelines attribute does not have the proper structure.")
|
||||||
for guideline in guidelines:
|
for guideline in guidelines:
|
||||||
attrs = []
|
attrs = []
|
||||||
@ -697,8 +734,8 @@ def _writeGuidelines(glyphObject, writer, identifiers):
|
|||||||
writer.simpletag("guideline", attrs)
|
writer.simpletag("guideline", attrs)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
|
|
||||||
def _writeAnchorsFormat1(pen, anchors):
|
def _writeAnchorsFormat1(pen, anchors, validate):
|
||||||
if not anchorsValidator(anchors):
|
if validate and not anchorsValidator(anchors):
|
||||||
raise GlifLibError("anchors attribute does not have the proper structure.")
|
raise GlifLibError("anchors attribute does not have the proper structure.")
|
||||||
for anchor in anchors:
|
for anchor in anchors:
|
||||||
attrs = []
|
attrs = []
|
||||||
@ -713,9 +750,9 @@ def _writeAnchorsFormat1(pen, anchors):
|
|||||||
pen.addPoint((x, y), segmentType="move", name=name)
|
pen.addPoint((x, y), segmentType="move", name=name)
|
||||||
pen.endPath()
|
pen.endPath()
|
||||||
|
|
||||||
def _writeAnchors(glyphObject, writer, identifiers):
|
def _writeAnchors(glyphObject, writer, identifiers, validate):
|
||||||
anchors = getattr(glyphObject, "anchors", [])
|
anchors = getattr(glyphObject, "anchors", [])
|
||||||
if not anchorsValidator(anchors):
|
if validate and not anchorsValidator(anchors):
|
||||||
raise GlifLibError("anchors attribute does not have the proper structure.")
|
raise GlifLibError("anchors attribute does not have the proper structure.")
|
||||||
for anchor in anchors:
|
for anchor in anchors:
|
||||||
attrs = []
|
attrs = []
|
||||||
@ -738,11 +775,12 @@ def _writeAnchors(glyphObject, writer, identifiers):
|
|||||||
writer.simpletag("anchor", attrs)
|
writer.simpletag("anchor", attrs)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
|
|
||||||
def _writeLib(glyphObject, writer):
|
def _writeLib(glyphObject, writer, validate):
|
||||||
lib = getattr(glyphObject, "lib", None)
|
lib = getattr(glyphObject, "lib", None)
|
||||||
valid, message = glyphLibValidator(lib)
|
if validate:
|
||||||
if not valid:
|
valid, message = glyphLibValidator(lib)
|
||||||
raise GlifLibError(message)
|
if not valid:
|
||||||
|
raise GlifLibError(message)
|
||||||
if not isinstance(lib, dict):
|
if not isinstance(lib, dict):
|
||||||
lib = dict(lib)
|
lib = dict(lib)
|
||||||
writer.begintag("lib")
|
writer.begintag("lib")
|
||||||
@ -827,7 +865,7 @@ def _glifTreeFromString(aString):
|
|||||||
raise GlifLibError("Invalid GLIF structure.")
|
raise GlifLibError("Invalid GLIF structure.")
|
||||||
return root
|
return root
|
||||||
|
|
||||||
def _readGlyphFromTree(tree, glyphObject=None, pointPen=None, formatVersions=(1, 2)):
|
def _readGlyphFromTree(tree, glyphObject=None, pointPen=None, formatVersions=(1, 2), validate=False):
|
||||||
# check the format version
|
# check the format version
|
||||||
formatVersion = tree.get("format")
|
formatVersion = tree.get("format")
|
||||||
if formatVersion is None:
|
if formatVersion is None:
|
||||||
@ -840,14 +878,14 @@ def _readGlyphFromTree(tree, glyphObject=None, pointPen=None, formatVersions=(1,
|
|||||||
if formatVersion not in formatVersions:
|
if formatVersion not in formatVersions:
|
||||||
raise GlifLibError("Forbidden GLIF format version: %s" % formatVersion)
|
raise GlifLibError("Forbidden GLIF format version: %s" % formatVersion)
|
||||||
if formatVersion == 1:
|
if formatVersion == 1:
|
||||||
_readGlyphFromTreeFormat1(tree=tree, glyphObject=glyphObject, pointPen=pointPen)
|
_readGlyphFromTreeFormat1(tree=tree, glyphObject=glyphObject, pointPen=pointPen, validate=validate)
|
||||||
elif formatVersion == 2:
|
elif formatVersion == 2:
|
||||||
_readGlyphFromTreeFormat2(tree=tree, glyphObject=glyphObject, pointPen=pointPen)
|
_readGlyphFromTreeFormat2(tree=tree, glyphObject=glyphObject, pointPen=pointPen, validate=validate)
|
||||||
else:
|
else:
|
||||||
raise GlifLibError("Unsupported GLIF format version: %s" % formatVersion)
|
raise GlifLibError("Unsupported GLIF format version: %s" % formatVersion)
|
||||||
|
|
||||||
|
|
||||||
def _readGlyphFromTreeFormat1(tree, glyphObject=None, pointPen=None):
|
def _readGlyphFromTreeFormat1(tree, glyphObject=None, pointPen=None, validate=None):
|
||||||
# get the name
|
# get the name
|
||||||
_readName(glyphObject, tree)
|
_readName(glyphObject, tree)
|
||||||
# populate the sub elements
|
# populate the sub elements
|
||||||
@ -862,7 +900,7 @@ def _readGlyphFromTreeFormat1(tree, glyphObject=None, pointPen=None):
|
|||||||
if element.text and element.text.strip() != '':
|
if element.text and element.text.strip() != '':
|
||||||
raise GlifLibError("Invalid outline structure.")
|
raise GlifLibError("Invalid outline structure.")
|
||||||
haveSeenOutline = True
|
haveSeenOutline = True
|
||||||
buildOutlineFormat1(glyphObject, pointPen, element)
|
buildOutlineFormat1(glyphObject, pointPen, element, validate)
|
||||||
elif glyphObject is None:
|
elif glyphObject is None:
|
||||||
continue
|
continue
|
||||||
elif element.tag == "advance":
|
elif element.tag == "advance":
|
||||||
@ -887,14 +925,14 @@ def _readGlyphFromTreeFormat1(tree, glyphObject=None, pointPen=None):
|
|||||||
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
|
||||||
_readLib(glyphObject, element)
|
_readLib(glyphObject, element, validate)
|
||||||
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
|
||||||
if unicodes:
|
if unicodes:
|
||||||
_relaxedSetattr(glyphObject, "unicodes", unicodes)
|
_relaxedSetattr(glyphObject, "unicodes", unicodes)
|
||||||
|
|
||||||
def _readGlyphFromTreeFormat2(tree, glyphObject=None, pointPen=None):
|
def _readGlyphFromTreeFormat2(tree, glyphObject=None, pointPen=None, validate=None):
|
||||||
# get the name
|
# get the name
|
||||||
_readName(glyphObject, tree)
|
_readName(glyphObject, tree)
|
||||||
# populate the sub elements
|
# populate the sub elements
|
||||||
@ -913,7 +951,7 @@ def _readGlyphFromTreeFormat2(tree, glyphObject=None, pointPen=None):
|
|||||||
raise GlifLibError("Invalid outline structure.")
|
raise GlifLibError("Invalid outline structure.")
|
||||||
haveSeenOutline = True
|
haveSeenOutline = True
|
||||||
if pointPen is not None:
|
if pointPen is not None:
|
||||||
buildOutlineFormat2(glyphObject, pointPen, element, identifiers)
|
buildOutlineFormat2(glyphObject, pointPen, element, identifiers, validate)
|
||||||
elif glyphObject is None:
|
elif glyphObject is None:
|
||||||
continue
|
continue
|
||||||
elif element.tag == "advance":
|
elif element.tag == "advance":
|
||||||
@ -949,7 +987,7 @@ def _readGlyphFromTreeFormat2(tree, glyphObject=None, pointPen=None):
|
|||||||
if len(element):
|
if len(element):
|
||||||
raise GlifLibError("Unknown children in image element.")
|
raise GlifLibError("Unknown children in image element.")
|
||||||
haveSeenImage = True
|
haveSeenImage = True
|
||||||
_readImage(glyphObject, element)
|
_readImage(glyphObject, element, validate)
|
||||||
elif element.tag == "note":
|
elif element.tag == "note":
|
||||||
if haveSeenNote:
|
if haveSeenNote:
|
||||||
raise GlifLibError("The note element occurs more than once.")
|
raise GlifLibError("The note element occurs more than once.")
|
||||||
@ -959,7 +997,7 @@ def _readGlyphFromTreeFormat2(tree, glyphObject=None, pointPen=None):
|
|||||||
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
|
||||||
_readLib(glyphObject, element)
|
_readLib(glyphObject, element, validate)
|
||||||
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
|
||||||
@ -994,21 +1032,22 @@ def _readNote(glyphObject, note):
|
|||||||
note = "\n".join(line.strip() for line in lines if line.strip())
|
note = "\n".join(line.strip() for line in lines if line.strip())
|
||||||
_relaxedSetattr(glyphObject, "note", note)
|
_relaxedSetattr(glyphObject, "note", note)
|
||||||
|
|
||||||
def _readLib(glyphObject, lib):
|
def _readLib(glyphObject, lib, validate):
|
||||||
assert len(lib) == 1
|
assert len(lib) == 1
|
||||||
child = lib[0]
|
child = lib[0]
|
||||||
plist = readPlistFromTree(child)
|
plist = readPlistFromTree(child)
|
||||||
valid, message = glyphLibValidator(plist)
|
if validate:
|
||||||
if not valid:
|
valid, message = glyphLibValidator(plist)
|
||||||
raise GlifLibError(message)
|
if not valid:
|
||||||
|
raise GlifLibError(message)
|
||||||
_relaxedSetattr(glyphObject, "lib", plist)
|
_relaxedSetattr(glyphObject, "lib", plist)
|
||||||
|
|
||||||
def _readImage(glyphObject, image):
|
def _readImage(glyphObject, image, validate):
|
||||||
imageData = image.attrib
|
imageData = image.attrib
|
||||||
for attr, default in _transformationInfo:
|
for attr, default in _transformationInfo:
|
||||||
value = imageData.get(attr, default)
|
value = imageData.get(attr, default)
|
||||||
imageData[attr] = _number(value)
|
imageData[attr] = _number(value)
|
||||||
if not imageValidator(imageData):
|
if validate and not imageValidator(imageData):
|
||||||
raise GlifLibError("The image element is not properly formatted.")
|
raise GlifLibError("The image element is not properly formatted.")
|
||||||
_relaxedSetattr(glyphObject, "image", imageData)
|
_relaxedSetattr(glyphObject, "image", imageData)
|
||||||
|
|
||||||
@ -1026,7 +1065,7 @@ pointTypeOptions = set(["move", "line", "offcurve", "curve", "qcurve"])
|
|||||||
|
|
||||||
# format 1
|
# format 1
|
||||||
|
|
||||||
def buildOutlineFormat1(glyphObject, pen, outline):
|
def buildOutlineFormat1(glyphObject, pen, outline, validate):
|
||||||
anchors = []
|
anchors = []
|
||||||
for element in outline:
|
for element in outline:
|
||||||
if element.tag == "contour":
|
if element.tag == "contour":
|
||||||
@ -1038,14 +1077,14 @@ def buildOutlineFormat1(glyphObject, pen, outline):
|
|||||||
anchors.append(anchor)
|
anchors.append(anchor)
|
||||||
continue
|
continue
|
||||||
if pen is not None:
|
if pen is not None:
|
||||||
_buildOutlineContourFormat1(pen, element)
|
_buildOutlineContourFormat1(pen, element, validate)
|
||||||
elif element.tag == "component":
|
elif element.tag == "component":
|
||||||
if pen is not None:
|
if pen is not None:
|
||||||
_buildOutlineComponentFormat1(pen, element)
|
_buildOutlineComponentFormat1(pen, element)
|
||||||
else:
|
else:
|
||||||
raise GlifLibError("Unknown element in outline element: %s" % element)
|
raise GlifLibError("Unknown element in outline element: %s" % element)
|
||||||
if glyphObject is not None and anchors:
|
if glyphObject is not None and anchors:
|
||||||
if not anchorsValidator(anchors):
|
if validate and not anchorsValidator(anchors):
|
||||||
raise GlifLibError("GLIF 1 anchors are not properly formatted.")
|
raise GlifLibError("GLIF 1 anchors are not properly formatted.")
|
||||||
_relaxedSetattr(glyphObject, "anchors", anchors)
|
_relaxedSetattr(glyphObject, "anchors", anchors)
|
||||||
|
|
||||||
@ -1066,7 +1105,7 @@ def _buildAnchorFormat1(point):
|
|||||||
anchor = dict(x=x, y=y, name=name)
|
anchor = dict(x=x, y=y, name=name)
|
||||||
return anchor
|
return anchor
|
||||||
|
|
||||||
def _buildOutlineContourFormat1(pen, contour):
|
def _buildOutlineContourFormat1(pen, contour, validate):
|
||||||
if contour.attrib:
|
if contour.attrib:
|
||||||
raise GlifLibError("Unknown attributes in contour element.")
|
raise GlifLibError("Unknown attributes in contour element.")
|
||||||
pen.beginPath()
|
pen.beginPath()
|
||||||
@ -1105,16 +1144,16 @@ def _buildOutlineComponentFormat1(pen, component):
|
|||||||
|
|
||||||
# format 2
|
# format 2
|
||||||
|
|
||||||
def buildOutlineFormat2(glyphObject, pen, outline, identifiers):
|
def buildOutlineFormat2(glyphObject, pen, outline, identifiers, validate):
|
||||||
for element in outline:
|
for element in outline:
|
||||||
if element.tag == "contour":
|
if element.tag == "contour":
|
||||||
_buildOutlineContourFormat2(pen, element, identifiers)
|
_buildOutlineContourFormat2(pen, element, identifiers, validate)
|
||||||
elif element.tag == "component":
|
elif element.tag == "component":
|
||||||
_buildOutlineComponentFormat2(pen, element, identifiers)
|
_buildOutlineComponentFormat2(pen, element, identifiers, validate)
|
||||||
else:
|
else:
|
||||||
raise GlifLibError("Unknown element in outline element: %s" % element.tag)
|
raise GlifLibError("Unknown element in outline element: %s" % element.tag)
|
||||||
|
|
||||||
def _buildOutlineContourFormat2(pen, contour, identifiers):
|
def _buildOutlineContourFormat2(pen, contour, identifiers, validate):
|
||||||
for attr in contour.attrib.keys():
|
for attr in contour.attrib.keys():
|
||||||
if attr not in contourAttributesFormat2:
|
if attr not in contourAttributesFormat2:
|
||||||
raise GlifLibError("Unknown attribute in contour element: %s" % attr)
|
raise GlifLibError("Unknown attribute in contour element: %s" % attr)
|
||||||
@ -1122,7 +1161,7 @@ def _buildOutlineContourFormat2(pen, contour, identifiers):
|
|||||||
if identifier is not None:
|
if identifier is not None:
|
||||||
if identifier in identifiers:
|
if identifier in identifiers:
|
||||||
raise GlifLibError("The identifier %s is used more than once." % identifier)
|
raise GlifLibError("The identifier %s is used more than once." % identifier)
|
||||||
if not identifierValidator(identifier):
|
if validate and not identifierValidator(identifier):
|
||||||
raise GlifLibError("The contour identifier %s is not valid." % identifier)
|
raise GlifLibError("The contour identifier %s is not valid." % identifier)
|
||||||
identifiers.add(identifier)
|
identifiers.add(identifier)
|
||||||
try:
|
try:
|
||||||
@ -1132,10 +1171,10 @@ def _buildOutlineContourFormat2(pen, contour, identifiers):
|
|||||||
warn("The beginPath method needs an identifier kwarg. The contour's identifier value has been discarded.", DeprecationWarning)
|
warn("The beginPath method needs an identifier kwarg. The contour's identifier value has been discarded.", DeprecationWarning)
|
||||||
if len(contour):
|
if len(contour):
|
||||||
_validateAndMassagePointStructures(contour, pointAttributesFormat2)
|
_validateAndMassagePointStructures(contour, pointAttributesFormat2)
|
||||||
_buildOutlinePointsFormat2(pen, contour, identifiers)
|
_buildOutlinePointsFormat2(pen, contour, identifiers, validate)
|
||||||
pen.endPath()
|
pen.endPath()
|
||||||
|
|
||||||
def _buildOutlinePointsFormat2(pen, contour, identifiers):
|
def _buildOutlinePointsFormat2(pen, contour, identifiers, validate):
|
||||||
for element in contour:
|
for element in contour:
|
||||||
x = element.attrib["x"]
|
x = element.attrib["x"]
|
||||||
y = element.attrib["y"]
|
y = element.attrib["y"]
|
||||||
@ -1146,7 +1185,7 @@ def _buildOutlinePointsFormat2(pen, contour, identifiers):
|
|||||||
if identifier is not None:
|
if identifier is not None:
|
||||||
if identifier in identifiers:
|
if identifier in identifiers:
|
||||||
raise GlifLibError("The identifier %s is used more than once." % identifier)
|
raise GlifLibError("The identifier %s is used more than once." % identifier)
|
||||||
if not identifierValidator(identifier):
|
if validate and not identifierValidator(identifier):
|
||||||
raise GlifLibError("The identifier %s is not valid." % identifier)
|
raise GlifLibError("The identifier %s is not valid." % identifier)
|
||||||
identifiers.add(identifier)
|
identifiers.add(identifier)
|
||||||
try:
|
try:
|
||||||
@ -1155,7 +1194,7 @@ def _buildOutlinePointsFormat2(pen, contour, identifiers):
|
|||||||
pen.addPoint((x, y), segmentType=segmentType, smooth=smooth, name=name)
|
pen.addPoint((x, y), segmentType=segmentType, smooth=smooth, name=name)
|
||||||
warn("The addPoint method needs an identifier kwarg. The point's identifier value has been discarded.", DeprecationWarning)
|
warn("The addPoint method needs an identifier kwarg. The point's identifier value has been discarded.", DeprecationWarning)
|
||||||
|
|
||||||
def _buildOutlineComponentFormat2(pen, component, identifiers):
|
def _buildOutlineComponentFormat2(pen, component, identifiers, validate):
|
||||||
if len(component):
|
if len(component):
|
||||||
raise GlifLibError("Unknown child elements of component element.")
|
raise GlifLibError("Unknown child elements of component element.")
|
||||||
for attr in component.attrib.keys():
|
for attr in component.attrib.keys():
|
||||||
@ -1176,7 +1215,7 @@ def _buildOutlineComponentFormat2(pen, component, identifiers):
|
|||||||
if identifier is not None:
|
if identifier is not None:
|
||||||
if identifier in identifiers:
|
if identifier in identifiers:
|
||||||
raise GlifLibError("The identifier %s is used more than once." % identifier)
|
raise GlifLibError("The identifier %s is used more than once." % identifier)
|
||||||
if not identifierValidator(identifier):
|
if validate and not identifierValidator(identifier):
|
||||||
raise GlifLibError("The identifier %s is not valid." % identifier)
|
raise GlifLibError("The identifier %s is not valid." % identifier)
|
||||||
identifiers.add(identifier)
|
identifiers.add(identifier)
|
||||||
try:
|
try:
|
||||||
@ -1443,7 +1482,7 @@ class GLIFPointPen(AbstractPointPen):
|
|||||||
part of .glif files.
|
part of .glif files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, xmlWriter, formatVersion=2, identifiers=None):
|
def __init__(self, xmlWriter, formatVersion=2, identifiers=None, validate=True):
|
||||||
if identifiers is None:
|
if identifiers is None:
|
||||||
identifiers = set()
|
identifiers = set()
|
||||||
self.formatVersion = formatVersion
|
self.formatVersion = formatVersion
|
||||||
@ -1451,13 +1490,14 @@ class GLIFPointPen(AbstractPointPen):
|
|||||||
self.writer = xmlWriter
|
self.writer = xmlWriter
|
||||||
self.prevOffCurveCount = 0
|
self.prevOffCurveCount = 0
|
||||||
self.prevPointTypes = []
|
self.prevPointTypes = []
|
||||||
|
self.validate = validate
|
||||||
|
|
||||||
def beginPath(self, identifier=None, **kwargs):
|
def beginPath(self, identifier=None, **kwargs):
|
||||||
attrs = []
|
attrs = []
|
||||||
if identifier is not None and self.formatVersion >= 2:
|
if identifier is not None and self.formatVersion >= 2:
|
||||||
if identifier in self.identifiers:
|
if identifier in self.identifiers:
|
||||||
raise GlifLibError("identifier used more than once: %s" % identifier)
|
raise GlifLibError("identifier used more than once: %s" % identifier)
|
||||||
if not identifierValidator(identifier):
|
if self.validate and not identifierValidator(identifier):
|
||||||
raise GlifLibError("identifier not formatted properly: %s" % identifier)
|
raise GlifLibError("identifier not formatted properly: %s" % identifier)
|
||||||
attrs.append(("identifier", identifier))
|
attrs.append(("identifier", identifier))
|
||||||
self.identifiers.add(identifier)
|
self.identifiers.add(identifier)
|
||||||
@ -1514,7 +1554,7 @@ class GLIFPointPen(AbstractPointPen):
|
|||||||
if identifier is not None and self.formatVersion >= 2:
|
if identifier is not None and self.formatVersion >= 2:
|
||||||
if identifier in self.identifiers:
|
if identifier in self.identifiers:
|
||||||
raise GlifLibError("identifier used more than once: %s" % identifier)
|
raise GlifLibError("identifier used more than once: %s" % identifier)
|
||||||
if not identifierValidator(identifier):
|
if self.validate and not identifierValidator(identifier):
|
||||||
raise GlifLibError("identifier not formatted properly: %s" % identifier)
|
raise GlifLibError("identifier not formatted properly: %s" % identifier)
|
||||||
attrs.append(("identifier", identifier))
|
attrs.append(("identifier", identifier))
|
||||||
self.identifiers.add(identifier)
|
self.identifiers.add(identifier)
|
||||||
@ -1531,7 +1571,7 @@ class GLIFPointPen(AbstractPointPen):
|
|||||||
if identifier is not None and self.formatVersion >= 2:
|
if identifier is not None and self.formatVersion >= 2:
|
||||||
if identifier in self.identifiers:
|
if identifier in self.identifiers:
|
||||||
raise GlifLibError("identifier used more than once: %s" % identifier)
|
raise GlifLibError("identifier used more than once: %s" % identifier)
|
||||||
if not identifierValidator(identifier):
|
if self.validate and not identifierValidator(identifier):
|
||||||
raise GlifLibError("identifier not formatted properly: %s" % identifier)
|
raise GlifLibError("identifier not formatted properly: %s" % identifier)
|
||||||
attrs.append(("identifier", identifier))
|
attrs.append(("identifier", identifier))
|
||||||
self.identifiers.add(identifier)
|
self.identifiers.add(identifier)
|
||||||
|
@ -32,7 +32,7 @@ class TestGLIF2(unittest.TestCase):
|
|||||||
glif = stripText(glif)
|
glif = stripText(glif)
|
||||||
glif = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + glif
|
glif = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + glif
|
||||||
glyph = Glyph()
|
glyph = Glyph()
|
||||||
readGlyphFromString(glif, glyphObject=glyph, pointPen=glyph)
|
readGlyphFromString(glif, glyphObject=glyph, pointPen=glyph, validate=True)
|
||||||
return glyph.py()
|
return glyph.py()
|
||||||
|
|
||||||
def testTopElement(self):
|
def testTopElement(self):
|
||||||
|
@ -37,7 +37,7 @@ class ReadFontInfoVersion1TestCase(unittest.TestCase):
|
|||||||
originalData = dict(fontInfoVersion1)
|
originalData = dict(fontInfoVersion1)
|
||||||
self._writeInfoToPlist(originalData)
|
self._writeInfoToPlist(originalData)
|
||||||
infoObject = TestInfoObject()
|
infoObject = TestInfoObject()
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
reader.readInfo(infoObject)
|
reader.readInfo(infoObject)
|
||||||
for attr in dir(infoObject):
|
for attr in dir(infoObject):
|
||||||
if attr not in fontInfoVersion2:
|
if attr not in fontInfoVersion2:
|
||||||
@ -57,7 +57,7 @@ class ReadFontInfoVersion1TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion1)
|
info = dict(fontInfoVersion1)
|
||||||
info["fontStyle"] = old
|
info["fontStyle"] = old
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
infoObject = TestInfoObject()
|
infoObject = TestInfoObject()
|
||||||
reader.readInfo(infoObject)
|
reader.readInfo(infoObject)
|
||||||
self.assertEqual(new, infoObject.styleMapStyleName)
|
self.assertEqual(new, infoObject.styleMapStyleName)
|
||||||
@ -78,7 +78,7 @@ class ReadFontInfoVersion1TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion1)
|
info = dict(fontInfoVersion1)
|
||||||
info["widthName"] = old
|
info["widthName"] = old
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
infoObject = TestInfoObject()
|
infoObject = TestInfoObject()
|
||||||
reader.readInfo(infoObject)
|
reader.readInfo(infoObject)
|
||||||
self.assertEqual(new, infoObject.openTypeOS2WidthClass)
|
self.assertEqual(new, infoObject.openTypeOS2WidthClass)
|
||||||
|
@ -37,7 +37,7 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
originalData = dict(fontInfoVersion2)
|
originalData = dict(fontInfoVersion2)
|
||||||
self._writeInfoToPlist(originalData)
|
self._writeInfoToPlist(originalData)
|
||||||
infoObject = TestInfoObject()
|
infoObject = TestInfoObject()
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
reader.readInfo(infoObject)
|
reader.readInfo(infoObject)
|
||||||
readData = {}
|
readData = {}
|
||||||
for attr in list(fontInfoVersion2.keys()):
|
for attr in list(fontInfoVersion2.keys()):
|
||||||
@ -49,92 +49,92 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["familyName"] = 123
|
info["familyName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# styleName
|
# styleName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["styleName"] = 123
|
info["styleName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# styleMapFamilyName
|
# styleMapFamilyName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["styleMapFamilyName"] = 123
|
info["styleMapFamilyName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# styleMapStyleName
|
# styleMapStyleName
|
||||||
## not a string
|
## not a string
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["styleMapStyleName"] = 123
|
info["styleMapStyleName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## out of range
|
## out of range
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["styleMapStyleName"] = "REGULAR"
|
info["styleMapStyleName"] = "REGULAR"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# versionMajor
|
# versionMajor
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["versionMajor"] = "1"
|
info["versionMajor"] = "1"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# versionMinor
|
# versionMinor
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["versionMinor"] = "0"
|
info["versionMinor"] = "0"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# copyright
|
# copyright
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["copyright"] = 123
|
info["copyright"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# trademark
|
# trademark
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["trademark"] = 123
|
info["trademark"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# unitsPerEm
|
# unitsPerEm
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["unitsPerEm"] = "abc"
|
info["unitsPerEm"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# descender
|
# descender
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["descender"] = "abc"
|
info["descender"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# xHeight
|
# xHeight
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["xHeight"] = "abc"
|
info["xHeight"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# capHeight
|
# capHeight
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["capHeight"] = "abc"
|
info["capHeight"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# ascender
|
# ascender
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["ascender"] = "abc"
|
info["ascender"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# italicAngle
|
# italicAngle
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["italicAngle"] = "abc"
|
info["italicAngle"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
|
|
||||||
def testHeadRead(self):
|
def testHeadRead(self):
|
||||||
@ -143,25 +143,25 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHeadCreated"] = 123
|
info["openTypeHeadCreated"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## invalid format
|
## invalid format
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHeadCreated"] = "2000-Jan-01 00:00:00"
|
info["openTypeHeadCreated"] = "2000-Jan-01 00:00:00"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeHeadLowestRecPPEM
|
# openTypeHeadLowestRecPPEM
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHeadLowestRecPPEM"] = "abc"
|
info["openTypeHeadLowestRecPPEM"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeHeadFlags
|
# openTypeHeadFlags
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHeadFlags"] = [-1]
|
info["openTypeHeadFlags"] = [-1]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
|
|
||||||
def testHheaRead(self):
|
def testHheaRead(self):
|
||||||
@ -169,37 +169,37 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHheaAscender"] = "abc"
|
info["openTypeHheaAscender"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeHheaDescender
|
# openTypeHheaDescender
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHheaDescender"] = "abc"
|
info["openTypeHheaDescender"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeHheaLineGap
|
# openTypeHheaLineGap
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHheaLineGap"] = "abc"
|
info["openTypeHheaLineGap"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeHheaCaretSlopeRise
|
# openTypeHheaCaretSlopeRise
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHheaCaretSlopeRise"] = "abc"
|
info["openTypeHheaCaretSlopeRise"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeHheaCaretSlopeRun
|
# openTypeHheaCaretSlopeRun
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHheaCaretSlopeRun"] = "abc"
|
info["openTypeHheaCaretSlopeRun"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeHheaCaretOffset
|
# openTypeHheaCaretOffset
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeHheaCaretOffset"] = "abc"
|
info["openTypeHheaCaretOffset"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
|
|
||||||
def testNameRead(self):
|
def testNameRead(self):
|
||||||
@ -207,91 +207,91 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameDesigner"] = 123
|
info["openTypeNameDesigner"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameDesignerURL
|
# openTypeNameDesignerURL
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameDesignerURL"] = 123
|
info["openTypeNameDesignerURL"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameManufacturer
|
# openTypeNameManufacturer
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameManufacturer"] = 123
|
info["openTypeNameManufacturer"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameManufacturerURL
|
# openTypeNameManufacturerURL
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameManufacturerURL"] = 123
|
info["openTypeNameManufacturerURL"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameLicense
|
# openTypeNameLicense
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameLicense"] = 123
|
info["openTypeNameLicense"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameLicenseURL
|
# openTypeNameLicenseURL
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameLicenseURL"] = 123
|
info["openTypeNameLicenseURL"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameVersion
|
# openTypeNameVersion
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameVersion"] = 123
|
info["openTypeNameVersion"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameUniqueID
|
# openTypeNameUniqueID
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameUniqueID"] = 123
|
info["openTypeNameUniqueID"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameDescription
|
# openTypeNameDescription
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameDescription"] = 123
|
info["openTypeNameDescription"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNamePreferredFamilyName
|
# openTypeNamePreferredFamilyName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNamePreferredFamilyName"] = 123
|
info["openTypeNamePreferredFamilyName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNamePreferredSubfamilyName
|
# openTypeNamePreferredSubfamilyName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNamePreferredSubfamilyName"] = 123
|
info["openTypeNamePreferredSubfamilyName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameCompatibleFullName
|
# openTypeNameCompatibleFullName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameCompatibleFullName"] = 123
|
info["openTypeNameCompatibleFullName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameSampleText
|
# openTypeNameSampleText
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameSampleText"] = 123
|
info["openTypeNameSampleText"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameWWSFamilyName
|
# openTypeNameWWSFamilyName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameWWSFamilyName"] = 123
|
info["openTypeNameWWSFamilyName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeNameWWSSubfamilyName
|
# openTypeNameWWSSubfamilyName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeNameWWSSubfamilyName"] = 123
|
info["openTypeNameWWSSubfamilyName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
|
|
||||||
def testOS2Read(self):
|
def testOS2Read(self):
|
||||||
@ -300,210 +300,210 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2WidthClass"] = "abc"
|
info["openTypeOS2WidthClass"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## out or range
|
## out or range
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2WidthClass"] = 15
|
info["openTypeOS2WidthClass"] = 15
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2WeightClass
|
# openTypeOS2WeightClass
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
## not an int
|
## not an int
|
||||||
info["openTypeOS2WeightClass"] = "abc"
|
info["openTypeOS2WeightClass"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## out of range
|
## out of range
|
||||||
info["openTypeOS2WeightClass"] = -50
|
info["openTypeOS2WeightClass"] = -50
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2Selection
|
# openTypeOS2Selection
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2Selection"] = [-1]
|
info["openTypeOS2Selection"] = [-1]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2VendorID
|
# openTypeOS2VendorID
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2VendorID"] = 1234
|
info["openTypeOS2VendorID"] = 1234
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2Panose
|
# openTypeOS2Panose
|
||||||
## not an int
|
## not an int
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2Panose"] = [0, 1, 2, 3, 4, 5, 6, 7, 8, str(9)]
|
info["openTypeOS2Panose"] = [0, 1, 2, 3, 4, 5, 6, 7, 8, str(9)]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## too few values
|
## too few values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2Panose"] = [0, 1, 2, 3]
|
info["openTypeOS2Panose"] = [0, 1, 2, 3]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## too many values
|
## too many values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2Panose"] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
info["openTypeOS2Panose"] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2FamilyClass
|
# openTypeOS2FamilyClass
|
||||||
## not an int
|
## not an int
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2FamilyClass"] = [1, str(1)]
|
info["openTypeOS2FamilyClass"] = [1, str(1)]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## too few values
|
## too few values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2FamilyClass"] = [1]
|
info["openTypeOS2FamilyClass"] = [1]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## too many values
|
## too many values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2FamilyClass"] = [1, 1, 1]
|
info["openTypeOS2FamilyClass"] = [1, 1, 1]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## out of range
|
## out of range
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2FamilyClass"] = [1, 201]
|
info["openTypeOS2FamilyClass"] = [1, 201]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2UnicodeRanges
|
# openTypeOS2UnicodeRanges
|
||||||
## not an int
|
## not an int
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2UnicodeRanges"] = ["0"]
|
info["openTypeOS2UnicodeRanges"] = ["0"]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## out of range
|
## out of range
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2UnicodeRanges"] = [-1]
|
info["openTypeOS2UnicodeRanges"] = [-1]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2CodePageRanges
|
# openTypeOS2CodePageRanges
|
||||||
## not an int
|
## not an int
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2CodePageRanges"] = ["0"]
|
info["openTypeOS2CodePageRanges"] = ["0"]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## out of range
|
## out of range
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2CodePageRanges"] = [-1]
|
info["openTypeOS2CodePageRanges"] = [-1]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2TypoAscender
|
# openTypeOS2TypoAscender
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2TypoAscender"] = "abc"
|
info["openTypeOS2TypoAscender"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2TypoDescender
|
# openTypeOS2TypoDescender
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2TypoDescender"] = "abc"
|
info["openTypeOS2TypoDescender"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2TypoLineGap
|
# openTypeOS2TypoLineGap
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2TypoLineGap"] = "abc"
|
info["openTypeOS2TypoLineGap"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2WinAscent
|
# openTypeOS2WinAscent
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2WinAscent"] = "abc"
|
info["openTypeOS2WinAscent"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2WinDescent
|
# openTypeOS2WinDescent
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2WinDescent"] = "abc"
|
info["openTypeOS2WinDescent"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2Type
|
# openTypeOS2Type
|
||||||
## not an int
|
## not an int
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2Type"] = ["1"]
|
info["openTypeOS2Type"] = ["1"]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
## out of range
|
## out of range
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2Type"] = [-1]
|
info["openTypeOS2Type"] = [-1]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2SubscriptXSize
|
# openTypeOS2SubscriptXSize
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2SubscriptXSize"] = "abc"
|
info["openTypeOS2SubscriptXSize"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2SubscriptYSize
|
# openTypeOS2SubscriptYSize
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2SubscriptYSize"] = "abc"
|
info["openTypeOS2SubscriptYSize"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2SubscriptXOffset
|
# openTypeOS2SubscriptXOffset
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2SubscriptXOffset"] = "abc"
|
info["openTypeOS2SubscriptXOffset"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2SubscriptYOffset
|
# openTypeOS2SubscriptYOffset
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2SubscriptYOffset"] = "abc"
|
info["openTypeOS2SubscriptYOffset"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2SuperscriptXSize
|
# openTypeOS2SuperscriptXSize
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2SuperscriptXSize"] = "abc"
|
info["openTypeOS2SuperscriptXSize"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2SuperscriptYSize
|
# openTypeOS2SuperscriptYSize
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2SuperscriptYSize"] = "abc"
|
info["openTypeOS2SuperscriptYSize"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2SuperscriptXOffset
|
# openTypeOS2SuperscriptXOffset
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2SuperscriptXOffset"] = "abc"
|
info["openTypeOS2SuperscriptXOffset"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2SuperscriptYOffset
|
# openTypeOS2SuperscriptYOffset
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2SuperscriptYOffset"] = "abc"
|
info["openTypeOS2SuperscriptYOffset"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2StrikeoutSize
|
# openTypeOS2StrikeoutSize
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2StrikeoutSize"] = "abc"
|
info["openTypeOS2StrikeoutSize"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeOS2StrikeoutPosition
|
# openTypeOS2StrikeoutPosition
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeOS2StrikeoutPosition"] = "abc"
|
info["openTypeOS2StrikeoutPosition"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
|
|
||||||
def testVheaRead(self):
|
def testVheaRead(self):
|
||||||
@ -511,37 +511,37 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeVheaVertTypoAscender"] = "abc"
|
info["openTypeVheaVertTypoAscender"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeVheaVertTypoDescender
|
# openTypeVheaVertTypoDescender
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeVheaVertTypoDescender"] = "abc"
|
info["openTypeVheaVertTypoDescender"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeVheaVertTypoLineGap
|
# openTypeVheaVertTypoLineGap
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeVheaVertTypoLineGap"] = "abc"
|
info["openTypeVheaVertTypoLineGap"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeVheaCaretSlopeRise
|
# openTypeVheaCaretSlopeRise
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeVheaCaretSlopeRise"] = "abc"
|
info["openTypeVheaCaretSlopeRise"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeVheaCaretSlopeRun
|
# openTypeVheaCaretSlopeRun
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeVheaCaretSlopeRun"] = "abc"
|
info["openTypeVheaCaretSlopeRun"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# openTypeVheaCaretOffset
|
# openTypeVheaCaretOffset
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["openTypeVheaCaretOffset"] = "abc"
|
info["openTypeVheaCaretOffset"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
|
|
||||||
def testFONDRead(self):
|
def testFONDRead(self):
|
||||||
@ -549,13 +549,13 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["macintoshFONDFamilyID"] = "abc"
|
info["macintoshFONDFamilyID"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# macintoshFONDName
|
# macintoshFONDName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["macintoshFONDName"] = 123
|
info["macintoshFONDName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
|
|
||||||
def testPostscriptRead(self):
|
def testPostscriptRead(self):
|
||||||
@ -563,211 +563,211 @@ class ReadFontInfoVersion2TestCase(unittest.TestCase):
|
|||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptFontName"] = 123
|
info["postscriptFontName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# postscriptFullName
|
# postscriptFullName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptFullName"] = 123
|
info["postscriptFullName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# postscriptSlantAngle
|
# postscriptSlantAngle
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptSlantAngle"] = "abc"
|
info["postscriptSlantAngle"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, info=TestInfoObject())
|
||||||
# postscriptUniqueID
|
# postscriptUniqueID
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptUniqueID"] = "abc"
|
info["postscriptUniqueID"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptUnderlineThickness
|
# postscriptUnderlineThickness
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptUnderlineThickness"] = "abc"
|
info["postscriptUnderlineThickness"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptUnderlinePosition
|
# postscriptUnderlinePosition
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptUnderlinePosition"] = "abc"
|
info["postscriptUnderlinePosition"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptIsFixedPitch
|
# postscriptIsFixedPitch
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptIsFixedPitch"] = 2
|
info["postscriptIsFixedPitch"] = 2
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptBlueValues
|
# postscriptBlueValues
|
||||||
## not a list
|
## not a list
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptBlueValues"] = "abc"
|
info["postscriptBlueValues"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## uneven value count
|
## uneven value count
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptBlueValues"] = [500]
|
info["postscriptBlueValues"] = [500]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## too many values
|
## too many values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptBlueValues"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
info["postscriptBlueValues"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptOtherBlues
|
# postscriptOtherBlues
|
||||||
## not a list
|
## not a list
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptOtherBlues"] = "abc"
|
info["postscriptOtherBlues"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## uneven value count
|
## uneven value count
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptOtherBlues"] = [500]
|
info["postscriptOtherBlues"] = [500]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## too many values
|
## too many values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptOtherBlues"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
info["postscriptOtherBlues"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptFamilyBlues
|
# postscriptFamilyBlues
|
||||||
## not a list
|
## not a list
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptFamilyBlues"] = "abc"
|
info["postscriptFamilyBlues"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## uneven value count
|
## uneven value count
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptFamilyBlues"] = [500]
|
info["postscriptFamilyBlues"] = [500]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## too many values
|
## too many values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptFamilyBlues"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
info["postscriptFamilyBlues"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptFamilyOtherBlues
|
# postscriptFamilyOtherBlues
|
||||||
## not a list
|
## not a list
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptFamilyOtherBlues"] = "abc"
|
info["postscriptFamilyOtherBlues"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## uneven value count
|
## uneven value count
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptFamilyOtherBlues"] = [500]
|
info["postscriptFamilyOtherBlues"] = [500]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## too many values
|
## too many values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptFamilyOtherBlues"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
info["postscriptFamilyOtherBlues"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptStemSnapH
|
# postscriptStemSnapH
|
||||||
## not list
|
## not list
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptStemSnapH"] = "abc"
|
info["postscriptStemSnapH"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## too many values
|
## too many values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptStemSnapH"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
info["postscriptStemSnapH"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptStemSnapV
|
# postscriptStemSnapV
|
||||||
## not list
|
## not list
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptStemSnapV"] = "abc"
|
info["postscriptStemSnapV"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
## too many values
|
## too many values
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptStemSnapV"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
info["postscriptStemSnapV"] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptBlueFuzz
|
# postscriptBlueFuzz
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptBlueFuzz"] = "abc"
|
info["postscriptBlueFuzz"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptBlueShift
|
# postscriptBlueShift
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptBlueShift"] = "abc"
|
info["postscriptBlueShift"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptBlueScale
|
# postscriptBlueScale
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptBlueScale"] = "abc"
|
info["postscriptBlueScale"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptForceBold
|
# postscriptForceBold
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptForceBold"] = "abc"
|
info["postscriptForceBold"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptDefaultWidthX
|
# postscriptDefaultWidthX
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptDefaultWidthX"] = "abc"
|
info["postscriptDefaultWidthX"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptNominalWidthX
|
# postscriptNominalWidthX
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptNominalWidthX"] = "abc"
|
info["postscriptNominalWidthX"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptWeightName
|
# postscriptWeightName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptWeightName"] = 123
|
info["postscriptWeightName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptDefaultCharacter
|
# postscriptDefaultCharacter
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptDefaultCharacter"] = 123
|
info["postscriptDefaultCharacter"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# postscriptWindowsCharacterSet
|
# postscriptWindowsCharacterSet
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["postscriptWindowsCharacterSet"] = -1
|
info["postscriptWindowsCharacterSet"] = -1
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# macintoshFONDFamilyID
|
# macintoshFONDFamilyID
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["macintoshFONDFamilyID"] = "abc"
|
info["macintoshFONDFamilyID"] = "abc"
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
# macintoshFONDName
|
# macintoshFONDName
|
||||||
info = dict(fontInfoVersion2)
|
info = dict(fontInfoVersion2)
|
||||||
info["macintoshFONDName"] = 123
|
info["macintoshFONDName"] = 123
|
||||||
self._writeInfoToPlist(info)
|
self._writeInfoToPlist(info)
|
||||||
reader = UFOReader(self.dstDir)
|
reader = UFOReader(self.dstDir, validate=True)
|
||||||
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject())
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -224,7 +224,7 @@ class KerningUpConversionTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def testUFO1(self):
|
def testUFO1(self):
|
||||||
self.makeUFO(formatVersion=2)
|
self.makeUFO(formatVersion=2)
|
||||||
reader = UFOReader(self.ufoPath)
|
reader = UFOReader(self.ufoPath, validate=True)
|
||||||
kerning = reader.readKerning()
|
kerning = reader.readKerning()
|
||||||
self.assertEqual(self.expectedKerning, kerning)
|
self.assertEqual(self.expectedKerning, kerning)
|
||||||
groups = reader.readGroups()
|
groups = reader.readGroups()
|
||||||
@ -234,7 +234,7 @@ class KerningUpConversionTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def testUFO2(self):
|
def testUFO2(self):
|
||||||
self.makeUFO(formatVersion=2)
|
self.makeUFO(formatVersion=2)
|
||||||
reader = UFOReader(self.ufoPath)
|
reader = UFOReader(self.ufoPath, validate=True)
|
||||||
kerning = reader.readKerning()
|
kerning = reader.readKerning()
|
||||||
self.assertEqual(self.expectedKerning, kerning)
|
self.assertEqual(self.expectedKerning, kerning)
|
||||||
groups = reader.readGroups()
|
groups = reader.readGroups()
|
||||||
|
@ -23,8 +23,8 @@ class GlyphSetTests(unittest.TestCase):
|
|||||||
import difflib
|
import difflib
|
||||||
srcDir = GLYPHSETDIR
|
srcDir = GLYPHSETDIR
|
||||||
dstDir = self.dstDir
|
dstDir = self.dstDir
|
||||||
src = GlyphSet(srcDir, ufoFormatVersion=2)
|
src = GlyphSet(srcDir, ufoFormatVersion=2, validateRead=True, validateWrite=True)
|
||||||
dst = GlyphSet(dstDir, ufoFormatVersion=2)
|
dst = GlyphSet(dstDir, ufoFormatVersion=2, validateRead=True, validateWrite=True)
|
||||||
for glyphName in src.keys():
|
for glyphName in src.keys():
|
||||||
g = src[glyphName]
|
g = src[glyphName]
|
||||||
g.drawPoints(None) # load attrs
|
g.drawPoints(None) # load attrs
|
||||||
@ -49,13 +49,13 @@ class GlyphSetTests(unittest.TestCase):
|
|||||||
"%s.glif file differs after round tripping" % glyphName)
|
"%s.glif file differs after round tripping" % glyphName)
|
||||||
|
|
||||||
def testRebuildContents(self):
|
def testRebuildContents(self):
|
||||||
gset = GlyphSet(GLYPHSETDIR)
|
gset = GlyphSet(GLYPHSETDIR, validateRead=True, validateWrite=True)
|
||||||
contents = gset.contents
|
contents = gset.contents
|
||||||
gset.rebuildContents()
|
gset.rebuildContents()
|
||||||
self.assertEqual(contents, gset.contents)
|
self.assertEqual(contents, gset.contents)
|
||||||
|
|
||||||
def testReverseContents(self):
|
def testReverseContents(self):
|
||||||
gset = GlyphSet(GLYPHSETDIR)
|
gset = GlyphSet(GLYPHSETDIR, validateRead=True, validateWrite=True)
|
||||||
d = {}
|
d = {}
|
||||||
for k, v in gset.getReverseContents().items():
|
for k, v in gset.getReverseContents().items():
|
||||||
d[v] = k
|
d[v] = k
|
||||||
@ -65,8 +65,8 @@ class GlyphSetTests(unittest.TestCase):
|
|||||||
self.assertEqual(d, org)
|
self.assertEqual(d, org)
|
||||||
|
|
||||||
def testReverseContents2(self):
|
def testReverseContents2(self):
|
||||||
src = GlyphSet(GLYPHSETDIR)
|
src = GlyphSet(GLYPHSETDIR, validateRead=True, validateWrite=True)
|
||||||
dst = GlyphSet(self.dstDir)
|
dst = GlyphSet(self.dstDir, validateRead=True, validateWrite=True)
|
||||||
dstMap = dst.getReverseContents()
|
dstMap = dst.getReverseContents()
|
||||||
self.assertEqual(dstMap, {})
|
self.assertEqual(dstMap, {})
|
||||||
for glyphName in src.keys():
|
for glyphName in src.keys():
|
||||||
@ -83,8 +83,8 @@ class GlyphSetTests(unittest.TestCase):
|
|||||||
def testCustomFileNamingScheme(self):
|
def testCustomFileNamingScheme(self):
|
||||||
def myGlyphNameToFileName(glyphName, glyphSet):
|
def myGlyphNameToFileName(glyphName, glyphSet):
|
||||||
return "prefix" + glyphNameToFileName(glyphName, glyphSet)
|
return "prefix" + glyphNameToFileName(glyphName, glyphSet)
|
||||||
src = GlyphSet(GLYPHSETDIR)
|
src = GlyphSet(GLYPHSETDIR, validateRead=True, validateWrite=True)
|
||||||
dst = GlyphSet(self.dstDir, myGlyphNameToFileName)
|
dst = GlyphSet(self.dstDir, myGlyphNameToFileName, validateRead=True, validateWrite=True)
|
||||||
for glyphName in src.keys():
|
for glyphName in src.keys():
|
||||||
g = src[glyphName]
|
g = src[glyphName]
|
||||||
g.drawPoints(None) # load attrs
|
g.drawPoints(None) # load attrs
|
||||||
@ -95,7 +95,7 @@ class GlyphSetTests(unittest.TestCase):
|
|||||||
self.assertEqual(d, dst.contents)
|
self.assertEqual(d, dst.contents)
|
||||||
|
|
||||||
def testGetUnicodes(self):
|
def testGetUnicodes(self):
|
||||||
src = GlyphSet(GLYPHSETDIR)
|
src = GlyphSet(GLYPHSETDIR, validateRead=True, validateWrite=True)
|
||||||
unicodes = src.getUnicodes()
|
unicodes = src.getUnicodes()
|
||||||
for glyphName in src.keys():
|
for glyphName in src.keys():
|
||||||
g = src[glyphName]
|
g = src[glyphName]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user