hinting-diff
Compare the TrueType hinting of two versions of a font, or a family of fonts, in a browser.
hinting-diff writes an HTML page that shows every glyph of a font, encoded or
not, rendered with its hinting at a size in pixels per em (ppem), for the old
and the new version of the font. Click old/new to switch between them
and see what changed. For a family, it writes a page for each font, and an index
page that links to them.
Source Sans Pro without hinting (old) and hinted with ttfautohint (new), in Firefox on Windows 11, enlarged 3×.
Browsers only apply TrueType hinting on Windows, so open the page on Windows. It works in old browsers too, as far back as Internet Explorer 11, Chrome 49 and Firefox 52, for checking hinting on old versions of Windows.
Install
pip install hinting-diff
It needs Python 3.10 or later, and installs fontTools too.
Usage
hinting-diff old/Family-Regular.ttf new/Family-Regular.ttf -o hinting-diff/
This writes hinting-diff/Family-Regular-hinting.html, with copies of both
fonts next to it, and prints the page's path. Open it in a browser on Windows.
To compare a family, give the folders of the old and the new fonts, or the fonts
with -fb/--fonts-before and -fa/--fonts-after, as in
diffenator2:
hinting-diff old/ new/
hinting-diff -fb old/*.ttf -fa new/*.ttf
Fonts are matched by their file names, and folders' subfolders are searched too.
A font that's only in the old or only in the new fonts is skipped, with a
warning. This writes a page for each font, and an index.html page that links
to them, and prints their paths, with the index page last. A single old font and
a single new font, given on their own, are compared whatever their names.
If a font can't be read, the other fonts' pages are still written, and the command exits with an error.
The output folder is optional, and is hinting-diff by default. All the
options:
usage:
hinting-diff [-h] [-o OUT] [--version] BEFORE AFTER
hinting-diff [-h] [-o OUT] [--version] -fb FONT [FONT ...] -fa FONT [FONT ...]
hinting-diff [-h] [-o OUT] [--version] AFTER [AFTER ...] --commit [REF]
Write pages to compare the TrueType hinting of two versions of fonts. Give the
old and new font, or folders of them, or several fonts with -fb and -fa: fonts
are matched by their file names. Or give the new fonts, or folders of them, in
a git repository, with --commit to compare them with the fonts at the same
paths in a commit. Browsers only apply TrueType hinting on Windows, so open
the pages on Windows.
positional arguments:
BEFORE AFTER the old and the new font (TTF), or folders of fonts.
With --commit, the new fonts or folders
options:
-h, --help show this help message and exit
-fb FONT [FONT ...], --fonts-before FONT [FONT ...]
the old fonts (TTF), or folders of fonts
-fa FONT [FONT ...], --fonts-after FONT [FONT ...]
the new fonts (TTF), or folders of fonts
--commit [REF] compare the new fonts with the fonts at the same paths
in this commit, e.g. HEAD~1 or a tag (default: HEAD,
the last commit)
-o OUT, --out OUT, --output OUT
folder for the pages and copies of the fonts (default:
hinting-diff)
--version show program's version number and exit
The page has:
- Sample text, which starts as every character the new font encodes (without combining marks or spaces), for a quick look over the whole character set. Choose Basic Latin in the Text menu for its letters, figures and punctuation, or edit the text to use your own (Custom). Tick Text waterfall to show the text from 8 to 64 ppem, one line for each size, cut off at the right: editing the text at one size changes it at the others.
- Every glyph, at the Font Size you choose (48 ppem to start with). Hover over a glyph to see its name, or filter the glyphs by name. Glyphs that are only in one of the fonts say so.
- A waterfall of a glyph from 8 to 64 ppem: click a glyph to show it.
- For variable fonts, an Instance menu with the font's named instances.
The size, font, text, filter and selected glyph are kept for the browser tab's session, so they stay the same when you open another font's page in the same tab.
Sizes are in device pixels, so they stay the same with browser zoom or display scaling (e.g. 150% in Windows), which change how many device pixels a CSS pixel is.
Comparing with a commit
In a git repository, give only the new fonts, or folders of them, with
--commit to compare them with the fonts at the same paths in a commit:
hinting-diff fonts/ttf/ --commit
hinting-diff fonts/ttf/*.ttf --commit HEAD~1
hinting-diff fonts/ttf/Family-Regular.ttf --commit v1.2.0
By default, the fonts are compared with the last commit (HEAD), e.g. to check
fonts you've just built before committing them. Give another commit, e.g.
HEAD~1, a branch, a tag or a commit hash, to compare with that. Put --commit
after the fonts, or give its commit, as in --commit HEAD fonts/ttf/: otherwise
the fonts' path is taken as the commit.
A font that wasn't in the commit, or one in a folder that was in the commit but
isn't now, is skipped, with a warning. The old fonts are read from the local
repository, so git needs to be installed, and the commit needs to be there,
e.g. git fetch first for origin/main. Fonts in
Git LFS work too, if git lfs is installed.
Showing the page in a report
A page that shows the hinting page in a frame can pick a variable font's
instance by adding its name to the URL, e.g.
Family-Regular-hinting.html#style=Bold. This hides the page's own
Instance menu.
Python API
Everything the command does is available from Python too, e.g. to make hinting pages as part of a bigger report.
Writing a page
write_hinting_page() writes the page for one font:
from pathlib import Path
from hinting_diff import write_hinting_page
page_path = write_hinting_page(
Path("old/Family-Regular.ttf"),
Path("new/Family-Regular.ttf"),
Path("hinting-diff"),
)
print(page_path) # hinting-diff/Family-Regular-hinting.html
Its arguments are:
before_path: the old font (TTF).after_path: the new font (TTF).output_path: the folder for the page and the copies of the fonts. It's made if it doesn't exist yet.page_name(optional): the page's file name. By default, it's the new font's name with-hinting.html, e.g.Family-Regular-hinting.html.
It returns the page's path. The copies of the fonts are saved next to the page as
hinting-old-<new font's file name> and hinting-new-<new font's file name>, so
pages for several fonts can share a folder.
It doesn't check that the fonts exist first: a missing or broken font raises
fontTools' or Python's own error (e.g. FileNotFoundError), and a font with too
many glyphs to map to Private Use Area codepoints raises a ValueError.
Writing pages for a family
match_fonts() matches old and new fonts by their file names, as the command
does, and write_index_page() writes a page that links to hinting pages:
from pathlib import Path
from hinting_diff import match_fonts, write_hinting_page, write_index_page
font_match = match_fonts([Path("old")], [Path("new")])
for after_path in font_match.only_after:
print(f"{after_path.name} is new")
page_paths = [
write_hinting_page(before_path, after_path, Path("hinting-diff"))
for before_path, after_path in font_match.pairs
]
index_path = write_index_page(page_paths, Path("hinting-diff"))
print(index_path) # hinting-diff/index.html
-
match_fonts(before_paths, after_paths)takes the old and the new fonts, each as fonts or folders of fonts, and returns aFontMatchnamed tuple:pairs: a list of(old font, new font)with the same file name, in file name order.only_before: old fonts without a new font with the same file name.only_after: new fonts without an old font with the same file name.
A single old font and a single new font, given on their own, are paired whatever their names. It raises a
FileNotFoundErrorfor a path that doesn't exist, and aValueErrorfor a folder without TrueType fonts or for two old or two new fonts with the same file name. -
find_fonts(paths)returns the fonts in a list of paths, asmatch_fonts()finds them: fonts as they are, and every TrueType font (.ttf, in any case) in folders and their subfolders, in file name order. -
write_index_page(page_paths, output_path, page_name="index.html")writes the index page inoutput_pathand returns its path. Its links are relative, so the pages can be in other folders too.
Reading fonts from a commit
save_fonts_at_commit(paths, commit, output_path) saves the fonts in paths, as
they were at commit, in output_path, and returns their paths there, to give
to match_fonts() as the old fonts:
import tempfile
from pathlib import Path
from hinting_diff import match_fonts, save_fonts_at_commit
fonts_path = Path("fonts/ttf")
with tempfile.TemporaryDirectory() as temp_folder:
before_paths = save_fonts_at_commit([fonts_path], "HEAD~1", Path(temp_folder))
font_match = match_fonts(before_paths, [fonts_path])
... # Write the pages before the temporary folder is deleted
Each path is a font or a folder of fonts in a git repository. For a folder, every
TrueType font that was in it, or its subfolders, at the commit is saved. A font
that wasn't in the commit isn't saved. It raises a ValueError if a path isn't in
a git repository or the commit doesn't exist, and a FileNotFoundError for a path
that doesn't exist.
Lower-level functions
The functions the page is made with can be used on their own:
add_glyph_codepoints(font_path, output_path)saves a copy of a font with each glyph mapped to a Private Use Area codepoint (see How it works), and returns adictof each glyph's name and codepoint..notdefisn't mapped.get_sample_text(font)returns every character aTTFontencodes, in codepoint order, without combining marks or characters that show nothing.get_named_instances(font)returns a variableTTFont's named instances as a list of(name, coordinates), e.g.("Bold", {"wght": 700.0}). It returns an empty list for a static font.GLYPH_CODEPOINT_STARTis the codepoint the first glyph is mapped to (0xF0000). A glyph's codepoint is this plus its glyph ID.
from pathlib import Path
from fontTools.ttLib import TTFont
from hinting_diff import add_glyph_codepoints, get_named_instances
codepoints = add_glyph_codepoints(
Path("new/Family-Regular.ttf"), Path("Family-Regular-pua.ttf")
)
print(f"U+{codepoints['a']:X}") # e.g. U+F0024
with TTFont("new/Family-Regular.ttf", lazy=True) as font:
for name, coordinates in get_named_instances(font):
print(name, coordinates)
hinting_diff.__version__ is the package's version.
How it works
Browsers can only show characters, not glyphs, so the fonts on the page are
copies with each glyph mapped to a Private Use Area codepoint, from U+F0000.
Only their cmap table changes: the other tables, including glyf, fpgm,
prep and cvt , are saved as they are, so the hinting is kept. Glyphs that a
variable font swaps with feature variations (rvrn) at the selected instance
show the swapped glyph, as they would in use.
Contributing
Bug reports, ideas and pull requests are welcome: see the contributing guide for how to set up the project and make a change. Please report security problems privately, as the security policy explains.
Acknowledgements
The page's look and its old/new toggle follow the HTML pages of diffenator2 (Copyright Google LLC, Apache License 2.0), so a hinting page fits in with them in a report. Its styles are adapted from diffenator2's.
Licence
Metadata
Release files for hinting-diff 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hinting_diff-0.2.0.tar.gz | 34.1 kB | With provenance | Details for hinting_diff-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hinting_diff-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for hinting_diff-0.2.0-py3-none-any.whl |
Total release size: 59.6 kB
Release files / hinting_diff-0.2.0.tar.gz
| Download URL | hinting_diff-0.2.0.tar.gz |
|---|---|
| Size | 34.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
163c74ebe4d1500ddd6b1afb434d6f15cfb27936abf0d2c7e7615d6849ac7b70
|
|
BLAKE2b-256 checksum How to use checksums |
3866714601c13270febeb19b37b1fca839c4a6d5bc23f6ea9e7fac4b42535004
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / hinting_diff-0.2.0-py3-none-any.whl
| Download URL | hinting_diff-0.2.0-py3-none-any.whl |
|---|---|
| Size | 25.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f5106ed5ba99eb65d848794aacb4a9e806c8068b6b1538faa3b448a13808170b
|
|
BLAKE2b-256 checksum How to use checksums |
2e8c1755422f331f520e36ce6082a59794a47d20f4333f562e215a1c86bd3481
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for hinting-diff 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for hinting_diff-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.