ufoLib¶
-
class
ufoLib.
UFOReader
(path)[source]¶ Read the various components of the .ufo.
-
formatVersion
¶ The format version of the UFO. This is determined by reading metainfo.plist during __init__.
-
getCharacterMapping
(layerName=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.
-
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)[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.
-
getImageDirectoryListing
()[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.
-
getKerningGroupConversionRenameMaps
()[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.
-
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.
-
-
class
ufoLib.
UFOWriter
(path, formatVersion=3, fileCreator='org.robofab.ufoLib')[source]¶ Write the various components of the .ufo.
-
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)[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)[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.
-
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.
-
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)[source]¶ Write features.fea. This method requires a features string as an argument.
-
writeGroups
(groups)[source]¶ Write groups.plist. This method requires a dict of glyph groups as an argument.
-
writeImage
(fileName, data)[source]¶ Write data to fileName in the images directory. The data must be a valid PNG.
-
writeInfo
(info)[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.
-
writeKerning
(kerning)[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.
-
-
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.