ufoLib

” A library for importing .ufo files and their descendants. Refer to http://unifiedfontobject.com for the UFO specification.

The UFOReader and UFOWriter classes support versions 1 and 2 of the specification. Up and down conversion functions are also supplied in this library. These conversion functions are only necessary if conversion without loading the UFO data into a set of objects is desired. These functions are:

convertUFOFormatVersion1ToFormatVersion2 convertUFOFormatVersion2ToFormatVersion1

Two sets that list the font info attribute names for the two fontinfo.plist formats are available for external use. These are:

fontInfoAttributesVersion1 fontInfoAttributesVersion2

A set listing the fontinfo.plist attributes that were deprecated in version 2 is available for external use:

deprecatedFontInfoAttributesVersion2

A function, validateFontInfoVersion2ValueForAttribute, that does some basic validation on values for a fontinfo.plist value is available for external use.

Two value conversion functions are availble for converting fontinfo.plist values between the possible format versions.

convertFontInfoValueForAttributeFromVersion1ToVersion2 convertFontInfoValueForAttributeFromVersion2ToVersion1
convertUFOFormatVersion1ToFormatVersion2(inPath, outPath=None)

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.

convertUFOFormatVersion2ToFormatVersion1(inPath, outPath=None)

Function for converting a version format 2 UFO to version format 1. 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.

class UFOReader(path)

Read the various components of the .ufo.

formatVersion

The format version of the UFO. This is determined by reading metainfo.plist during __init__.

readMetaInfo()

Read metainfo.plist. Only used for internal operations.

readGroups()

Read groups.plist. Returns a dict.

readInfo(info)

Read fontinfo.plist. It requires an object that allows setting attributes with names that follow the fontinfo.plist version 2 specification. This will write the attributes defined in the file into the object.

readKerning()

Read kerning.plist. Returns a dict.

readLib()

Read lib.plist. Returns a dict.

readFeatures()

Read features.fea. Returns a string.

getGlyphSet()

Return the GlyphSet associated with the glyphs directory in the .ufo.

getCharacterMapping()

Return a dictionary that maps unicode values (ints) to lists of glyph names.

class UFOWriter(path, formatVersion=2, fileCreator='org.robofab.ufoLib')

Write the various components of the .ufo.

formatVersion

The format version of the UFO. This is set into metainfo.plist during __init__.

fileCreator

The file creator of the UFO. This is set into metainfo.plist during __init__.

writeGroups(groups)

Write groups.plist. This method requires a dict of glyph groups as an argument.

writeInfo(info)

Write info.plist. This method requires an object that supports getting attributes that follow the fontinfo.plist version 2 secification. Attributes will be taken from the given object and written into the file.

writeKerning(kerning)

Write kerning.plist. This method requires a dict of kerning pairs as an argument.

writeLib(libDict)

Write lib.plist. This method requires a lib dict as an argument.

writeFeatures(features)

Write features.fea. This method requires a features string as an argument.

makeGlyphPath()

Make the glyphs directory in the .ufo. Returns the path of the directory created.

getGlyphSet(glyphNameToFileNameFunc=None)

Return the GlyphSet associated with the glyphs directory in the .ufo.

validateFontInfoVersion2ValueForAttribute(attr, value)

This performs very basic validation of the value for attribute following the UFO 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.

convertFontInfoValueForAttributeFromVersion1ToVersion2(attr, value)

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.

convertFontInfoValueForAttributeFromVersion2ToVersion1(attr, value)

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.

links