$ show googlefonts/glyphsLib
glyphsLib is a Python library that provides bidirectional conversion between Glyphs.app source files (.glyphs) and the UFO (Unified Font Object) format with Designspace documents. It serves as the core bridge in font production pipelines, enabling tools like fontmake to compile variable and static OpenType fonts from Glyphs sources. The library handles the full round-trip of font metadata, glyph outlines, components, anchors, hints, guidelines, kerning, OpenType features, instances, axes, and custom parameters, supporting both Glyphs v2 and v3 file formats. Architecturally, glyphsLib employs a builder pattern with UFOBuilder and GlyphsBuilder classes that orchestrate conversion through specialized sub-modules for each font data domain (paths, components, anchors, features, etc.). Key entry points include the high-level functions `to_ufos()`, `to_designspace()`, and `to_glyphs()` in the `glyphsLib.builder` package, as well as CLI tools `glyphs2ufo` and `ufo2glyphs`. The library integrates deeply with the fontTools ecosystem, using fontTools.designspaceLib for axis definitions and ufo2ft for feature writing and filters. External dependencies include fonttools, ufoLib2, defcon, openstep-plist, and xmldiff. The library also bundles GlyphData XML files for glyph classification and production name mapping. Notable features include smart component decomposition, bracket/brace layer handling, anchor propagation, token expansion in feature code, automatic STAT table generation, and variable feature conversion from Glyphs-specific conditional syntax to feaLib variation blocks. The codebase is well-tested with extensive round-trip tests and regression tests against real font families.
The LLM identified 4 files worth highlighting for reuse:
Implements TokenExpander, a reusable token expansion engine that substitutes Glyphs-style tokens (e.g., $padding, ${A:width}, $[name endswith '.sc']) in feature code. Supports arithmetic expressions, glyph property lookups, and predicate-based filtering. This pattern is isolated and could be extracted for any font tool needing dynamic token substitution in OpenType feature text.
Contains VariableFeatureConverter, a stateful regex-based translator that converts Glyphs-specific conditional feature syntax (e.g., if/else blocks with axis conditions) into feaLib-compatible conditionset and variation blocks. Demonstrates non-obvious skill in parsing and rewriting OpenType feature code, and is reusable for any tool that needs to bridge Glyphs variable feature syntax to standard OpenType.
Provides CornerComponentApplier, a dataclass that encapsulates complex bezier curve splitting, point projection, and alignment logic for generating curved corner shapes from straight corners. This filter is optional and self-contained, relying only on fontTools bezier utilities. It demonstrates advanced geometric computation and can be reused in any font processing pipeline that needs corner rounding or component-based corner deformation.
Defines the ParamHandler abstract base class and a KNOWN_PARAM_HANDLERS registry for converting custom parameters between Glyphs and UFO formats. Each handler implements to_glyphs() and to_ufo() methods, allowing clean separation of conversion logic per parameter. This pattern is reusable for any bidirectional data format conversion where custom metadata needs to be mapped between two schemas.