Package: glyphsLib
glyphsLibThis Python library provides a bridge from Glyphs source files (.glyphs) to
UFOs and Designspace files viadefconanddesignspaceLib.The main methods for conversion are found in__init__.py.
Intermediate data can be accessed without actually writing UFOs, if
needed.Write and return UFOsThe following code will write UFOs and a Designspace file to disk.importglyphsLibmaster_dir="master_ufos"ufos,designspace_path=glyphsLib.build_masters("MyFont.glyphs",master_dir)If you want to interpolate instances, please use fontmake instead. It uses this library under the hood when dealing with Glyphs files.Load UFO objects without writingimportglyphsLibufos=glyphsLib.load_to_ufos("MyFont.glyphs")Read and write Glyphs data as Python objectsfromglyphsLibimportGSFontfont=GSFont(glyphs_file)font.save(glyphs_file)TheglyphsLib.classesmodule aims to provide an interface similar to
Glyphs.app’sPython Scripting API.Note that currently not all the classes and methods may be fully
implemented. We try to keep up to date, but if you find something that
is missing or does not work as expected, please open a issue.Go back and forth between UFOs and GlyphsYou can use theufo2glyphsandglyphs2ufocommand line scripts to
round-trip your source files. By default, the scripts try to preserve as
much metadata as possible.# Generate master UFOs and Designspace file
glyphs2ufo Example.glyphs

# Go back
ufo2glyphs Example.designspace

# You can also combine single UFOs into a Glyphs source file.
ufo2glyphs Example-Regular.ufo Example-Bold.ufoWithout a designspace file, using for example theInria fonts by Black[Foundry]:importglobfromdefconimportFontfromglyphsLibimportto_glyphsufos=[Font(path)forpathinglob.glob("*Italic.ufo")]# Sort the UFOs because glyphsLib will create masters in the same orderufos=sorted(ufos,key=lambdaufo:ufo.info.openTypeOS2WeightClass)font=to_glyphs(ufos)font.save("InriaSansItalic.glyphs")Here is the resulting glyphs fileWith a designspace, usingSpectral from Production Type:importglobfromfontTools.designspaceLibimportDesignSpaceDocumentfromglyphsLibimportto_glyphsdoc=DesignSpaceDocument()doc.read("spectral-build-roman.designspace")font=to_glyphs(doc)font.save("SpectralRoman.glyphs")Here is the resulting glyphs fileIn both programmatic cases, if you intend to go back to UFOs after modifying
the file with Glyphs, you should use theminimize_ufo_diffsparameter to
minimize the amount of diffs that will show up in git after the back and
forth. To do so, the glyphsLib will add some bookkeeping values in varioususerDatafields. For example, it will try to remember which GSClass came
from groups.plist or from the feature file.The same option exists for people who want to do Glyphs->UFOs->Glyphs:minimize_glyphs_diffs, which will add some bookkeeping data in UFOlib.
For example, it will keep the same UUIDs for Glyphs layers, and so will need
to store those layer UUIDs in the UFOs.importglobimportosfromfontTools.designspaceLibimportDesignSpaceDocumentfromglyphsLibimportto_glyphs,to_designspace,GSFontdoc=DesignSpaceDocument()doc.read("spectral-build-roman.designspace")font=to_glyphs(doc,minimize_ufo_diffs=True)doc2=to_designspace(font,propagate_anchors=False)# UFOs are in memory only, attached to the doc via `sources`# Writing doc2 over the original doc should generate very few git diffs (ideally none)doc2.write(doc.path)forsourceindoc2.sources:path=os.path.join(os.path.dirname(doc.path),source.filename)# You will want to use ufoNormalizer aftersource.font.save(path)font=GSFont("SpectralRoman.glyphs")doc=to_designspace(font,minimize_glyphs_diffs=True,propagate_anchors=False)font2=to_glyphs(doc)# Writing font2 over font should generate very few git diffs (ideally none):font2.save(font.filepath)In practice there are always a few diffs on things that don’t really make a
difference, like optional things being added/removed or whitespace changes or
things getting reordered…Make a releaseUsegit tag-ato make a new annotated tag, orgit tag-sfor a GPG-signed
annotated tag, if you prefer.Name the new tag with with a leading ‘v’ followed by threeMAJOR.MINOR.PATCHdigits, like in semantic versioning. Look at the existing tags for examples.In the tag message write some short release notes describing the changes since the
previous tag.Finally, push the tag to the remote repository (e.g. assuming your upstream is
calledorigin):$ git push origin v0.4.3This will trigger the CI to build the distribution packages and upload them to
the Python Package Index automatically, if all the tests pass successfully.