Font Bakery

repository·main·Indexed 20 days ago

https://github.com/fonttools/fontbakery

A command-line font quality assurance tool used to check the quality of font projects, specifically targeting OpenType binary files and project metadata files like Google Fonts' METADATA.pb. It includes the Google Fonts Axis Registry for variable font axes and allows developers to create custom quality control checks via Python profiles.

Tokens
12.7K
Snippets
54
Records
79
Agent score
72%

What's inside fontbakery

  1. Overview of Font Bakery capabilities

    main

    Font Bakery is a tool designed to automate font quality assurance by running a collection of "checks" against font files. It is intended to be used both as a final validation step before publishing and as an iterative part of the daily font development process.

    Supported File Formats:

    • OpenType
    • UFO
    • GlyphsApp
    • TruFont

    Levels of Checks:

    1. Standardized format profiles: Checks against established industry standards.
    2. Distributor requirements: Checks tailored to specific requirements of font distributors (e.g., Google Fonts).
    3. Custom checks: Individual or foundry-specific custom validation routines.
  2. What is a Font Bakery Profile?

    main

    A Font Bakery Profile is a container for a set of quality control checks to be run on fonts and associated files. Profiles are defined as Python modules containing a single PROFILE dictionary.

    Profiles allow you to:

    • Group specific checks into named sections.
    • Include existing profiles (like opentype) as a baseline.
    • Exclude specific checks from included profiles.
    • Override the severity (status) of specific check results.
    • Provide default configuration values for checks.

    Custom profiles are useful for individual font projects or for foundries to establish and monitor quality standards.

  3. Naming check IDs

    main

    Check IDs should be globally and temporally unique.

    • Uniqueness: Within a single profile, a check ID must be unique. For global uniqueness, avoid changing IDs once assigned.
    • Disambiguation: If different vendors use the same ID for different criteria, use the vendor-specific profile name as a prefix, separated by a colon (e.g., vendor:check_id).
    • Organization: You may organize names by including relevant metadata, such as table names, in the ID.
  4. Understand the structure of a FontBakery Markdown report

    main

    FontBakery generates reports that categorize check results into specific severity levels and sections to help developers prioritize font fixes. The Markdown report structure follows this hierarchy:

    1. Version Information: Displays the fontbakery version used.
    2. DEPRECATION WARNING: Alerts users to features or checks that are being phased out.
    3. Checks with FATAL results: High-priority issues that must be addressed immediately (often used to break CI/CD pipelines).
    4. Experimental checks: New checks that are currently non-blocking but will eventually become effective.
    5. Check results / All other checks: Standard check results categorized by severity.
    6. Summary: A statistical overview of the results, including counts and percentages for each log level (e.g., FATAL, ERROR, WARNING, INFO).
    7. Omitted Loglevels: A note listing any log levels that were excluded from the report.
  5. Use dependency injection for check parameters

    main

    FontBakery uses dependency injection to pass objects to your check functions. The check runner looks at your function's parameter names and matches them to 'conditions' (cached properties) on the Testable object (like Font or Ufo) or the CheckRunContext.

    While you can use 'clever' short-cuts, it is best practice to be explicit to avoid undefined behavior when multiple testable types share condition names.

    • Explicit (Recommended): Use font or ufo as parameters and call conditions as methods on them.
    • Short-cut (Common): Use ttFont as a parameter to receive the parsed TTFont object directly.
    • Context-wide checks: Use parameters like fonts or ttFonts to receive collections of files from the CheckRunContext for cross-file validation.
    • Context awareness: Use context as a parameter to access the CheckRunContext from within a specific testable object.
    # Explicit pattern (Recommended)
    @check(id="my_check")
    def check_my_logic(font: Font):
        ttFont = font.ttFont
        # ...
    
    # Short-cut pattern (Common for TTFont checks)
    @check(id="my_check")
    def check_my_logic(ttFont):
        # ...
    
    # Collection pattern (For checking all files)
    @check(id="check_all")
    def check_all_same_family(fonts):
        # 'fonts' is a list of Font objects
        pass
    
    # Context pattern
    @check(id="check_context")
    def check_with_context(ttFont, context):
        # 'context' is the CheckRunContext
        pass
  6. Understand the Google Fonts (GF) Axis Registry

    main

    The fontbakery package includes the Google Fonts Axis Registry, which is a collection of metadata source files defining variable font axes. This registry is used to provide metadata for axes used in CSS and API requests.

    Important Notes:

    • The live, authoritative registry is located at fonts.google.com/variablefonts.
    • Axes present in a font file that are not in this registry will not function via the Google Fonts API.
    • This registry supports a superset of the OpenType axis registry and includes additional metadata fields.
  7. Font Bakery's core product values

    main

    Font Bakery is built around three guiding principles:

    1. Simple: The code is easy to read, and running checks is designed to be easy and pleasant.
    2. Reliable: Every check is constantly verified with self-tests to ensure accuracy.
    3. Understandable: Each check includes documentation explaining the rationale and why the specific check is important for font quality.
  8. Use the check-universal profile

    main

    The check-universal subcommand runs a profile containing checks for best practices agreed upon by the type design community. It includes the full OpenType profile as well as checks originally included in the adobefonts and googlefonts profiles. It is intended to be the primary profile for shared, non-vendor-specific checks.

    fontbakery check-universal *.ttf
  9. How to run FontBakery Shaping checks

    main

    The Shaping profile in FontBakery validates that a font's OpenType layout features work as expected. Unlike standard structural checks, Shaping checks require a test suite consisting of JSON files that define specific parameters and values for the tests.

    To use this feature, you must follow these steps:

    1. Prepare Test Suites: Create or use JSON files that define the shaping test parameters. You can find examples in the shaping/ directory of the repository.
    2. Configure the Test Directory: Create a YAML configuration file (e.g., shaping.yml) that points to the directory containing your JSON test files using the shaping.test_directory key.
    3. Execute the Check: Run the check-shaping command via the CLI, passing your configuration file and the font file you wish to test.
    fontbakery check-shaping --config shaping.yml Font.ttf