googlefonts / diffenator2

A font comparison tool that will not stop until your fonts are exhaustively compared.
Apache License 2.0
45 stars 6 forks source link

Diffenator 2

Compare two font families. Currently, the tool only supports static ttfs and variable ttfs.

This tool primarily checks two font families for visual differences by comparing fonts against real words (wordlists can be found in the src/diffenator/data/wordlists directory). It also provides an improved "ttx diff" by treating each font as a tree and then doing a tree comparison. The output is a plain html file which then allows us to screenshot the differences using Selenium.

This tool replaces the original github.com/googlefonts/fontdiffenator

A next-generation of the tool, written in Rust, is in development at github.com/simoncozens/diffenator3

Features

Install

pip install git+https://github.com/googlefonts/diffenator2

There's also a github action for testing upstream font repositories.

Caveats

Since we're comparing words, we cannot guarantee that abbreviations, names and optional OpenType features haven't regressed. In order to check these, users should create their own wordlist which contains the combinations they'd like to check. See Usage section for examples on how to do this.

Words are compared by pixel diffing FreeType bitmaps at 3ppem. This size may sound too small, however M Foley's tests show that it's still able to pick up incredibly small details. We include all pixel differences in the outputted reports (we will include threshold filtering soon). If you hover over each word, it will display an array which shows the pixel differences (0 no change, 255 max change).

In order to test fonts on the correct words, we first determine what scripts are supported within the font and then select the appropriate script specific wordlist. There are still a few scripts which we don't have wordlists for. Please ask M Foley to generate one if it's missing for your project.

Usage

diffenator2 has two subcommands, diff and proof.

diff

usage: diffenator2 diff [-h] [--out OUT] [--imgs]
                        [--filter-styles FILTER_STYLES] [--pt-size PT_SIZE]
                        [--styles {instances,cross_product,masters}]
                        --fonts-before FONTS_BEFORE [FONTS_BEFORE ...]
                        --fonts-after FONTS_AFTER [FONTS_AFTER ...]
                        [--user-wordlist USER_WORDLIST] [--no-diffenator]
                        [--threshold THRESHOLD]

  --out OUT, -o OUT     Output dir
  --imgs                Generate images
  --filter-styles FILTER_STYLES
  --pt-size PT_SIZE, -pt PT_SIZE
  --styles {instances,cross_product,masters}, -s {instances,cross_product,masters}
                        Show font instances, cross product or master styles
  --fonts-before FONTS_BEFORE [FONTS_BEFORE ...], -fb FONTS_BEFORE [FONTS_BEFORE ...]
  --fonts-after FONTS_AFTER [FONTS_AFTER ...], -fa FONTS_AFTER [FONTS_AFTER ...]
  --user-wordlist USER_WORDLIST
  --no-diffenator
  --threshold THRESHOLD, -t THRESHOLD

Standard use: compare two families

The most typical usage is to compare two font families:

  # -fb == --fonts-before, -fa == --fonts-after
  diffenator2 diff -fb font1.ttf -fa font2.ttf -o out_dir

User Wordlist

Compare two font families and include a custom wordlist

diffenator2 diff -fb font1.ttf -fa font2.ttf --user-wordlist wordlist.txt -o out_dir

A wordlist could be

Filter Styles

The --filter-styles option can be used to select which styles should be compared

For example, to only diff regular and bold styles:

diffenator2 diff -fb font1.ttf -fa font2.ttf --filter-styles "Regular|Bold"

Choose locations

-s is used to choose which locations of a variable font should be compared

Choose specific characters

-ch is used to select which characters to compare

To compare only ascii characters:

diffenator2 diff -fb font2.ttf -fa font2.ttf -ch "[!-~]"

proof

usage: diffenator2 proof [-h] [--out OUT] [--imgs]
                         [--filter-styles FILTER_STYLES] [--pt-size PT_SIZE]
                         [--styles {instances,cross_product,masters}]
                         fonts [fonts ...]

diffenator2 proof font1.ttf font2.ttf font3.ttf -o out_dir

diffenator2 proof font1.ttf font2.ttf font3.ttf -o out_dir --imgs