ufoLib¶
-
ufoLib.
makeUFOPath
(path)[source]¶ Return a .ufo pathname.
>>> makeUFOPath("directory/something.ext") == ( ... os.path.join('directory', 'something.ufo')) True >>> makeUFOPath("directory/something.another.thing.ext") == ( ... os.path.join('directory', 'something.another.thing.ufo')) True
-
exception
ufoLib.
UFOLibError
[source]¶ -
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
ufoLib.
UFOReader
(path, validate=True)[source]¶ Read the various components of the .ufo.
By default read data is validated. Set
validate
toFalse
to not validate the data.-
formatVersion
¶ The format version of the UFO. This is determined by reading metainfo.plist during __init__.
-
getCharacterMapping
(layerName=None, validate=None)[source]¶ Return a dictionary that maps unicode values (ints) to lists of glyph names.
-
getDataDirectoryListing
(maxDepth=100)[source]¶ Returns a list of all files in the data directory. The returned paths will be relative to the UFO. This will not list directory names, only file names. Thus, empty directories will be skipped.
The maxDepth argument sets the maximum number of sub-directories that are allowed.
-
getDefaultLayerName
(validate=None)[source]¶ Get the default layer name from layercontents.plist.
validate
will validate the data, by default it is set to the class’s validate value, can be overridden.
-
getFileModificationTime
(path)[source]¶ Returns the modification time (as reported by os.path.getmtime) for the file at the given path. The path must be relative to the UFO path. Returns None if the file does not exist.
-
getGlyphSet
(layerName=None, validateRead=None, validateWrite=None)[source]¶ Return the GlyphSet associated with the glyphs directory mapped to layerName in the UFO. If layerName is not provided, the name retrieved with getDefaultLayerName will be used.
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.
-
getImageDirectoryListing
(validate=None)[source]¶ Returns a list of all image file names in the images directory. Each of the images will have been verified to have the PNG signature.
validate
will validate the data, by default it is set to the class’s validate value, can be overridden.
-
getKerningGroupConversionRenameMaps
(validate=None)[source]¶ Get maps defining the renaming that was done during any needed kerning group conversion. This method returns a dictionary of this form:
- {
- “side1” : {“old group name” : “new group name”}, “side2” : {“old group name” : “new group name”}
}
When no conversion has been performed, the side1 and side2 dictionaries will be empty.
validate
will validate the groups, by default it is set to the class’s validate value, can be overridden.
-
getLayerNames
(validate=None)[source]¶ Get the ordered layer names from layercontents.plist.
validate
will validate the data, by default it is set to the class’s validate value, can be overridden.
-
getReadFileForPath
(path, encoding=None)[source]¶ Returns a file (or file-like) object for the file at the given path. The path must be relative to the UFO path. Returns None if the file does not exist. An encoding may be passed if needed.
Note: The caller is responsible for closing the open file.
-
readBytesFromPath
(path, encoding=None)[source]¶ Returns the bytes in the file at the given path. The path must be relative to the UFO path. Returns None if the file does not exist. An encoding may be passed if needed.
-
readGroups
(validate=None)[source]¶ Read groups.plist. Returns a dict.
validate
will validate the read data, by default it is set to the class’s validate value, can be overridden.
-
readImage
(fileName, validate=None)[source]¶ Return image data for the file named fileName.
validate
will validate the data, by default it is set to the class’s validate value, can be overridden.
-
readInfo
(info, validate=None)[source]¶ Read fontinfo.plist. It requires an object that allows setting attributes with names that follow the fontinfo.plist version 3 specification. This will write the attributes defined in the file into the object.
validate
will validate the read data, by default it is set to the class’s validate value, can be overridden.
-
readKerning
(validate=None)[source]¶ Read kerning.plist. Returns a dict.
validate
will validate the kerning data, by default it is set to the class’s validate value, can be overridden.
-
-
class
ufoLib.
UFOWriter
(path, formatVersion=3, fileCreator='org.robofab.ufoLib', validate=True)[source]¶ Write the various components of the .ufo.
By default, the written data will be validated before writing. Set
validate
toFalse
if you do not want to validate the data. Validation can also be overriden on a per method level if desired.-
copyFromReader
(reader, sourcePath, destPath)[source]¶ Copy the sourcePath in the provided UFOReader to destPath in this writer. The paths must be relative. They may represent directories or paths. This uses the most memory efficient method possible for copying the data possible.
-
copyImageFromReader
(reader, sourceFileName, destFileName, validate=None)[source]¶ Copy the sourceFileName in the provided UFOReader to destFileName in this writer. This uses the most memory efficient method possible for copying the data possible.
-
fileCreator
¶ The file creator of the UFO. This is set into metainfo.plist during __init__.
-
formatVersion
¶ The format version of the UFO. This is set into metainfo.plist during __init__.
-
getFileObjectForPath
(path, encoding=None)[source]¶ Creates a write mode file object at path. If needed, the directory tree for the given path will be built. The path must be relative to the UFO. An encoding may be passed if needed.
Note: The caller is responsible for closing the open file.
-
getGlyphSet
(layerName=None, defaultLayer=True, glyphNameToFileNameFunc=None, validateRead=None, validateWrite=None)[source]¶ Return the GlyphSet object associated with the appropriate glyph directory in the .ufo. If layerName is None, the default glyph set will be used. The defaultLayer flag indictes that the layer should be saved into the default glyphs directory.
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.
-
path
¶ The path the UFO is being written to.
-
removeFileForPath
(path)[source]¶ Remove the file (or directory) at path. The path must be relative to the UFO. This is only allowed for files in the data and image directories.
-
removeImage
(fileName, validate=None)[source]¶ Remove the file named fileName from the images directory.
-
renameGlyphSet
(layerName, newLayerName, defaultLayer=False)[source]¶ Rename a glyph set.
Note: if a GlyphSet object has already been retrieved for layerName, it is up to the caller to inform that object that the directory it represents has changed.
-
setKerningGroupConversionRenameMaps
(maps)[source]¶ Set maps defining the renaming that should be done when writing groups and kerning in UFO 1 and UFO 2. This will effectively undo the conversion done when UFOReader reads this data. The dictionary should have this form:
- {
- “side1” : {“group name to use when writing” : “group name in data”}, “side2” : {“group name to use when writing” : “group name in data”}
}
This is the same form returned by UFOReader’s getKerningGroupConversionRenameMaps method.
-
setModificationTime
()[source]¶ Set the UFO modification time to the current time. This is never called automatically. It is up to the caller to call this when finished working on the UFO.
-
writeBytesToPath
(path, data, encoding=None)[source]¶ Write bytes to path. If needed, the directory tree for the given path will be built. The path must be relative to the UFO. An encoding may be passed if needed.
-
writeFeatures
(features, validate=None)[source]¶ Write features.fea. This method requires a features string as an argument.
-
writeGroups
(groups, validate=None)[source]¶ Write groups.plist. This method requires a dict of glyph groups as an argument.
validate
will validate the data, by default it is set to the class’s validate value, can be overridden.
-
writeImage
(fileName, data, validate=None)[source]¶ Write data to fileName in the images directory. The data must be a valid PNG.
-
writeInfo
(info, validate=None)[source]¶ Write info.plist. This method requires an object that supports getting attributes that follow the fontinfo.plist version 2 specification. Attributes will be taken from the given object and written into the file.
validate
will validate the data, by default it is set to the class’s validate value, can be overridden.
-
writeKerning
(kerning, validate=None)[source]¶ Write kerning.plist. This method requires a dict of kerning pairs as an argument.
This performs basic structural validation of the kerning, but it does not check for compliance with the spec in regards to conflicting pairs. The assumption is that the kerning data being passed is standards compliant.
validate
will validate the data, by default it is set to the class’s validate value, can be overridden.
-
-
ufoLib.
validateFontInfoVersion2ValueForAttribute
(attr, value)[source]¶ This performs very basic validation of the value for attribute following the UFO 2 fontinfo.plist specification. The results of this should not be interpretted as correct for the font that they are part of. This merely indicates that the value is of the proper type and, where the specification defines a set range of possible values for an attribute, that the value is in the accepted range.
-
ufoLib.
validateFontInfoVersion3ValueForAttribute
(attr, value)[source]¶ This performs very basic validation of the value for attribute following the UFO 3 fontinfo.plist specification. The results of this should not be interpretted as correct for the font that they are part of. This merely indicates that the value is of the proper type and, where the specification defines a set range of possible values for an attribute, that the value is in the accepted range.
-
ufoLib.
convertFontInfoValueForAttributeFromVersion1ToVersion2
(attr, value)[source]¶ Convert value from version 1 to version 2 format. Returns the new attribute name and the converted value. If the value is None, None will be returned for the new value.
-
ufoLib.
convertFontInfoValueForAttributeFromVersion2ToVersion1
(attr, value)[source]¶ Convert value from version 2 to version 1 format. Returns the new attribute name and the converted value. If the value is None, None will be returned for the new value.
-
ufoLib.
convertUFOFormatVersion1ToFormatVersion2
(inPath, outPath=None, validateRead=False, validateWrite=True)[source]¶ Function for converting a version format 1 UFO to version format 2. inPath should be a path to a UFO. outPath is the path where the new UFO should be written. If outPath is not given, the inPath will be used and, therefore, the UFO will be converted in place. Otherwise, if outPath is specified, nothing must exist at that path.
validateRead
will validate the read data.validateWrite
will validate the written data.