hinting-diff 0.1.1__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/PKG-INFO +143 -24
- hinting_diff-0.2.0/README.md +314 -0
- hinting_diff-0.2.0/VERSION +1 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff/__init__.py +8 -0
- hinting_diff-0.2.0/src/hinting_diff/cli.py +164 -0
- hinting_diff-0.2.0/src/hinting_diff/git.py +97 -0
- hinting_diff-0.2.0/src/hinting_diff/matching.py +98 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff/page.html +163 -18
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff/page.py +63 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff.egg-info/PKG-INFO +143 -24
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff.egg-info/SOURCES.txt +4 -0
- hinting_diff-0.2.0/tests/test_cli.py +143 -0
- hinting_diff-0.2.0/tests/test_git.py +158 -0
- hinting_diff-0.2.0/tests/test_matching.py +77 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/tests/test_page.py +40 -0
- hinting_diff-0.1.1/README.md +0 -195
- hinting_diff-0.1.1/VERSION +0 -1
- hinting_diff-0.1.1/src/hinting_diff/cli.py +0 -43
- hinting_diff-0.1.1/tests/test_cli.py +0 -38
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/LICENSE.txt +0 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/pyproject.toml +0 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/setup.cfg +0 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff/py.typed +0 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff.egg-info/dependency_links.txt +0 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff.egg-info/entry_points.txt +0 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff.egg-info/requires.txt +0 -0
- {hinting_diff-0.1.1 → hinting_diff-0.2.0}/src/hinting_diff.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hinting-diff
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Compare the TrueType hinting of two versions of a font in a browser
|
|
5
5
|
Author: Klim Type Foundry
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -34,12 +34,14 @@ Dynamic: license-file
|
|
|
34
34
|
[](https://github.com/klim-type-foundry/hinting-diff/actions/workflows/check.yml)
|
|
35
35
|
[](https://github.com/klim-type-foundry/hinting-diff/blob/main/LICENSE.txt)
|
|
36
36
|
|
|
37
|
-
Compare the TrueType hinting of two versions of a font
|
|
37
|
+
Compare the TrueType hinting of two versions of a font, or a family of fonts,
|
|
38
|
+
in a browser.
|
|
38
39
|
|
|
39
40
|
`hinting-diff` writes an HTML page that shows every glyph of a font, encoded or
|
|
40
41
|
not, rendered with its hinting at a size in pixels per em (ppem), for the old
|
|
41
42
|
and the new version of the font. Click **old**/**new** to switch between them
|
|
42
|
-
and see what changed.
|
|
43
|
+
and see what changed. For a family, it writes a page for each font, and an index
|
|
44
|
+
page that links to them.
|
|
43
45
|
|
|
44
46
|

|
|
45
47
|
|
|
@@ -68,23 +70,55 @@ hinting-diff old/Family-Regular.ttf new/Family-Regular.ttf -o hinting-diff/
|
|
|
68
70
|
This writes `hinting-diff/Family-Regular-hinting.html`, with copies of both
|
|
69
71
|
fonts next to it, and prints the page's path. Open it in a browser on Windows.
|
|
70
72
|
|
|
73
|
+
To compare a family, give the folders of the old and the new fonts, or the fonts
|
|
74
|
+
with `-fb`/`--fonts-before` and `-fa`/`--fonts-after`, as in
|
|
75
|
+
[diffenator2](https://github.com/googlefonts/diffenator2):
|
|
76
|
+
|
|
77
|
+
```shell
|
|
78
|
+
hinting-diff old/ new/
|
|
79
|
+
hinting-diff -fb old/*.ttf -fa new/*.ttf
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Fonts are matched by their file names, and folders' subfolders are searched too.
|
|
83
|
+
A font that's only in the old or only in the new fonts is skipped, with a
|
|
84
|
+
warning. This writes a page for each font, and an `index.html` page that links
|
|
85
|
+
to them, and prints their paths, with the index page last. A single old font and
|
|
86
|
+
a single new font, given on their own, are compared whatever their names.
|
|
87
|
+
|
|
88
|
+
If a font can't be read, the other fonts' pages are still written, and the
|
|
89
|
+
command exits with an error.
|
|
90
|
+
|
|
71
91
|
The output folder is optional, and is `hinting-diff` by default. All the
|
|
72
92
|
options:
|
|
73
93
|
|
|
74
94
|
```text
|
|
75
|
-
usage:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
95
|
+
usage:
|
|
96
|
+
hinting-diff [-h] [-o OUT] [--version] BEFORE AFTER
|
|
97
|
+
hinting-diff [-h] [-o OUT] [--version] -fb FONT [FONT ...] -fa FONT [FONT ...]
|
|
98
|
+
hinting-diff [-h] [-o OUT] [--version] AFTER [AFTER ...] --commit [REF]
|
|
99
|
+
|
|
100
|
+
Write pages to compare the TrueType hinting of two versions of fonts. Give the
|
|
101
|
+
old and new font, or folders of them, or several fonts with -fb and -fa: fonts
|
|
102
|
+
are matched by their file names. Or give the new fonts, or folders of them, in
|
|
103
|
+
a git repository, with --commit to compare them with the fonts at the same
|
|
104
|
+
paths in a commit. Browsers only apply TrueType hinting on Windows, so open
|
|
105
|
+
the pages on Windows.
|
|
79
106
|
|
|
80
107
|
positional arguments:
|
|
81
|
-
|
|
82
|
-
|
|
108
|
+
BEFORE AFTER the old and the new font (TTF), or folders of fonts.
|
|
109
|
+
With --commit, the new fonts or folders
|
|
83
110
|
|
|
84
111
|
options:
|
|
85
112
|
-h, --help show this help message and exit
|
|
86
|
-
-
|
|
87
|
-
|
|
113
|
+
-fb FONT [FONT ...], --fonts-before FONT [FONT ...]
|
|
114
|
+
the old fonts (TTF), or folders of fonts
|
|
115
|
+
-fa FONT [FONT ...], --fonts-after FONT [FONT ...]
|
|
116
|
+
the new fonts (TTF), or folders of fonts
|
|
117
|
+
--commit [REF] compare the new fonts with the fonts at the same paths
|
|
118
|
+
in this commit, e.g. HEAD~1 or a tag (default: HEAD,
|
|
119
|
+
the last commit)
|
|
120
|
+
-o OUT, --out OUT, --output OUT
|
|
121
|
+
folder for the pages and copies of the fonts (default:
|
|
88
122
|
hinting-diff)
|
|
89
123
|
--version show program's version number and exit
|
|
90
124
|
```
|
|
@@ -93,14 +127,17 @@ The page has:
|
|
|
93
127
|
|
|
94
128
|
- **Sample text**, which starts as every character the new font encodes
|
|
95
129
|
(without combining marks or spaces), for a quick look over the whole character
|
|
96
|
-
set.
|
|
130
|
+
set. Choose **Basic Latin** in the **Text** menu for its letters, figures and
|
|
131
|
+
punctuation, or edit the text to use your own (**Custom**). Tick **Text
|
|
132
|
+
waterfall** to show the text from 8 to 64 ppem, one line for each size, cut off
|
|
133
|
+
at the right: editing the text at one size changes it at the others.
|
|
97
134
|
- **Every glyph**, at the **Font Size** you choose (48 ppem to start with).
|
|
98
135
|
Hover over a glyph to see its name, or filter the glyphs by name. Glyphs that
|
|
99
136
|
are only in one of the fonts say so.
|
|
100
137
|
- **A waterfall** of a glyph from 8 to 64 ppem: click a glyph to show it.
|
|
101
138
|
- For variable fonts, an **Instance** menu with the font's named instances.
|
|
102
139
|
|
|
103
|
-
The size, font,
|
|
140
|
+
The size, font, text, filter and selected glyph are kept for the browser
|
|
104
141
|
tab's session, so they stay the same when you open another font's page in the
|
|
105
142
|
same tab.
|
|
106
143
|
|
|
@@ -108,6 +145,29 @@ Sizes are in device pixels, so they stay the same with browser zoom or display
|
|
|
108
145
|
scaling (e.g. 150% in Windows), which change how many device pixels a CSS pixel
|
|
109
146
|
is.
|
|
110
147
|
|
|
148
|
+
### Comparing with a commit
|
|
149
|
+
|
|
150
|
+
In a git repository, give only the new fonts, or folders of them, with
|
|
151
|
+
`--commit` to compare them with the fonts at the same paths in a commit:
|
|
152
|
+
|
|
153
|
+
```shell
|
|
154
|
+
hinting-diff fonts/ttf/ --commit
|
|
155
|
+
hinting-diff fonts/ttf/*.ttf --commit HEAD~1
|
|
156
|
+
hinting-diff fonts/ttf/Family-Regular.ttf --commit v1.2.0
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
By default, the fonts are compared with the last commit (`HEAD`), e.g. to check
|
|
160
|
+
fonts you've just built before committing them. Give another commit, e.g.
|
|
161
|
+
`HEAD~1`, a branch, a tag or a commit hash, to compare with that. Put `--commit`
|
|
162
|
+
after the fonts, or give its commit, as in `--commit HEAD fonts/ttf/`: otherwise
|
|
163
|
+
the fonts' path is taken as the commit.
|
|
164
|
+
|
|
165
|
+
A font that wasn't in the commit, or one in a folder that was in the commit but
|
|
166
|
+
isn't now, is skipped, with a warning. The old fonts are read from the local
|
|
167
|
+
repository, so `git` needs to be installed, and the commit needs to be there,
|
|
168
|
+
e.g. `git fetch` first for `origin/main`. Fonts in
|
|
169
|
+
[Git LFS](https://git-lfs.com) work too, if `git lfs` is installed.
|
|
170
|
+
|
|
111
171
|
### Showing the page in a report
|
|
112
172
|
|
|
113
173
|
A page that shows the hinting page in a frame can pick a variable font's
|
|
@@ -122,7 +182,7 @@ pages as part of a bigger report.
|
|
|
122
182
|
|
|
123
183
|
### Writing a page
|
|
124
184
|
|
|
125
|
-
`write_hinting_page()`
|
|
185
|
+
`write_hinting_page()` writes the page for one font:
|
|
126
186
|
|
|
127
187
|
```python
|
|
128
188
|
from pathlib import Path
|
|
@@ -148,23 +208,75 @@ Its arguments are:
|
|
|
148
208
|
|
|
149
209
|
It returns the page's path. The copies of the fonts are saved next to the page as
|
|
150
210
|
`hinting-old-<new font's file name>` and `hinting-new-<new font's file name>`, so
|
|
151
|
-
pages for several fonts can share a folder
|
|
211
|
+
pages for several fonts can share a folder.
|
|
212
|
+
|
|
213
|
+
It doesn't check that the fonts exist first: a missing or broken font raises
|
|
214
|
+
fontTools' or Python's own error (e.g. `FileNotFoundError`), and a font with too
|
|
215
|
+
many glyphs to map to Private Use Area codepoints raises a `ValueError`.
|
|
216
|
+
|
|
217
|
+
### Writing pages for a family
|
|
218
|
+
|
|
219
|
+
`match_fonts()` matches old and new fonts by their file names, as the command
|
|
220
|
+
does, and `write_index_page()` writes a page that links to hinting pages:
|
|
152
221
|
|
|
153
222
|
```python
|
|
154
223
|
from pathlib import Path
|
|
155
224
|
|
|
156
|
-
from hinting_diff import write_hinting_page
|
|
225
|
+
from hinting_diff import match_fonts, write_hinting_page, write_index_page
|
|
226
|
+
|
|
227
|
+
font_match = match_fonts([Path("old")], [Path("new")])
|
|
228
|
+
for after_path in font_match.only_after:
|
|
229
|
+
print(f"{after_path.name} is new")
|
|
230
|
+
page_paths = [
|
|
231
|
+
write_hinting_page(before_path, after_path, Path("hinting-diff"))
|
|
232
|
+
for before_path, after_path in font_match.pairs
|
|
233
|
+
]
|
|
234
|
+
index_path = write_index_page(page_paths, Path("hinting-diff"))
|
|
235
|
+
print(index_path) # hinting-diff/index.html
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
- `match_fonts(before_paths, after_paths)` takes the old and the new fonts, each
|
|
239
|
+
as fonts or folders of fonts, and returns a `FontMatch` named tuple:
|
|
240
|
+
- `pairs`: a list of `(old font, new font)` with the same file name, in file
|
|
241
|
+
name order.
|
|
242
|
+
- `only_before`: old fonts without a new font with the same file name.
|
|
243
|
+
- `only_after`: new fonts without an old font with the same file name.
|
|
244
|
+
|
|
245
|
+
A single old font and a single new font, given on their own, are paired
|
|
246
|
+
whatever their names. It raises a `FileNotFoundError` for a path that doesn't
|
|
247
|
+
exist, and a `ValueError` for a folder without TrueType fonts or for two old or
|
|
248
|
+
two new fonts with the same file name.
|
|
249
|
+
- `find_fonts(paths)` returns the fonts in a list of paths, as `match_fonts()`
|
|
250
|
+
finds them: fonts as they are, and every TrueType font (`.ttf`, in any case) in
|
|
251
|
+
folders and their subfolders, in file name order.
|
|
252
|
+
- `write_index_page(page_paths, output_path, page_name="index.html")` writes the
|
|
253
|
+
index page in `output_path` and returns its path. Its links are relative, so the
|
|
254
|
+
pages can be in other folders too.
|
|
255
|
+
|
|
256
|
+
### Reading fonts from a commit
|
|
257
|
+
|
|
258
|
+
`save_fonts_at_commit(paths, commit, output_path)` saves the fonts in `paths`, as
|
|
259
|
+
they were at `commit`, in `output_path`, and returns their paths there, to give
|
|
260
|
+
to `match_fonts()` as the old fonts:
|
|
157
261
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
262
|
+
```python
|
|
263
|
+
import tempfile
|
|
264
|
+
from pathlib import Path
|
|
265
|
+
|
|
266
|
+
from hinting_diff import match_fonts, save_fonts_at_commit
|
|
267
|
+
|
|
268
|
+
fonts_path = Path("fonts/ttf")
|
|
269
|
+
with tempfile.TemporaryDirectory() as temp_folder:
|
|
270
|
+
before_paths = save_fonts_at_commit([fonts_path], "HEAD~1", Path(temp_folder))
|
|
271
|
+
font_match = match_fonts(before_paths, [fonts_path])
|
|
272
|
+
... # Write the pages before the temporary folder is deleted
|
|
162
273
|
```
|
|
163
274
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
`
|
|
275
|
+
Each path is a font or a folder of fonts in a git repository. For a folder, every
|
|
276
|
+
TrueType font that was in it, or its subfolders, at the commit is saved. A font
|
|
277
|
+
that wasn't in the commit isn't saved. It raises a `ValueError` if a path isn't in
|
|
278
|
+
a git repository or the commit doesn't exist, and a `FileNotFoundError` for a path
|
|
279
|
+
that doesn't exist.
|
|
168
280
|
|
|
169
281
|
### Lower-level functions
|
|
170
282
|
|
|
@@ -219,6 +331,13 @@ problems privately, as the
|
|
|
219
331
|
[security policy](https://github.com/klim-type-foundry/hinting-diff/blob/main/SECURITY.md)
|
|
220
332
|
explains.
|
|
221
333
|
|
|
334
|
+
## Acknowledgements
|
|
335
|
+
|
|
336
|
+
The page's look and its **old**/**new** toggle follow the HTML pages of
|
|
337
|
+
[diffenator2](https://github.com/googlefonts/diffenator2) (Copyright Google LLC,
|
|
338
|
+
Apache License 2.0), so a hinting page fits in with them in a report. Its styles
|
|
339
|
+
are adapted from diffenator2's.
|
|
340
|
+
|
|
222
341
|
## Licence
|
|
223
342
|
|
|
224
343
|
[Apache License 2.0](https://github.com/klim-type-foundry/hinting-diff/blob/main/LICENSE.txt)
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# hinting-diff
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/hinting-diff/)
|
|
4
|
+
[](https://pypi.org/project/hinting-diff/)
|
|
5
|
+
[](https://github.com/klim-type-foundry/hinting-diff/actions/workflows/check.yml)
|
|
6
|
+
[](https://github.com/klim-type-foundry/hinting-diff/blob/main/LICENSE.txt)
|
|
7
|
+
|
|
8
|
+
Compare the TrueType hinting of two versions of a font, or a family of fonts,
|
|
9
|
+
in a browser.
|
|
10
|
+
|
|
11
|
+
`hinting-diff` writes an HTML page that shows every glyph of a font, encoded or
|
|
12
|
+
not, rendered with its hinting at a size in pixels per em (ppem), for the old
|
|
13
|
+
and the new version of the font. Click **old**/**new** to switch between them
|
|
14
|
+
and see what changed. For a family, it writes a page for each font, and an index
|
|
15
|
+
page that links to them.
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
<sub>Source Sans Pro without hinting (old) and hinted with ttfautohint (new), in
|
|
20
|
+
Firefox on Windows 11, enlarged 3×.</sub>
|
|
21
|
+
|
|
22
|
+
Browsers only apply TrueType hinting on Windows, so open the page on Windows. It
|
|
23
|
+
works in old browsers too, as far back as Internet Explorer 11, Chrome 49 and
|
|
24
|
+
Firefox 52, for checking hinting on old versions of Windows.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
pip install hinting-diff
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
It needs Python 3.10 or later, and installs
|
|
33
|
+
[fontTools](https://github.com/fonttools/fonttools) too.
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
hinting-diff old/Family-Regular.ttf new/Family-Regular.ttf -o hinting-diff/
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This writes `hinting-diff/Family-Regular-hinting.html`, with copies of both
|
|
42
|
+
fonts next to it, and prints the page's path. Open it in a browser on Windows.
|
|
43
|
+
|
|
44
|
+
To compare a family, give the folders of the old and the new fonts, or the fonts
|
|
45
|
+
with `-fb`/`--fonts-before` and `-fa`/`--fonts-after`, as in
|
|
46
|
+
[diffenator2](https://github.com/googlefonts/diffenator2):
|
|
47
|
+
|
|
48
|
+
```shell
|
|
49
|
+
hinting-diff old/ new/
|
|
50
|
+
hinting-diff -fb old/*.ttf -fa new/*.ttf
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Fonts are matched by their file names, and folders' subfolders are searched too.
|
|
54
|
+
A font that's only in the old or only in the new fonts is skipped, with a
|
|
55
|
+
warning. This writes a page for each font, and an `index.html` page that links
|
|
56
|
+
to them, and prints their paths, with the index page last. A single old font and
|
|
57
|
+
a single new font, given on their own, are compared whatever their names.
|
|
58
|
+
|
|
59
|
+
If a font can't be read, the other fonts' pages are still written, and the
|
|
60
|
+
command exits with an error.
|
|
61
|
+
|
|
62
|
+
The output folder is optional, and is `hinting-diff` by default. All the
|
|
63
|
+
options:
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
usage:
|
|
67
|
+
hinting-diff [-h] [-o OUT] [--version] BEFORE AFTER
|
|
68
|
+
hinting-diff [-h] [-o OUT] [--version] -fb FONT [FONT ...] -fa FONT [FONT ...]
|
|
69
|
+
hinting-diff [-h] [-o OUT] [--version] AFTER [AFTER ...] --commit [REF]
|
|
70
|
+
|
|
71
|
+
Write pages to compare the TrueType hinting of two versions of fonts. Give the
|
|
72
|
+
old and new font, or folders of them, or several fonts with -fb and -fa: fonts
|
|
73
|
+
are matched by their file names. Or give the new fonts, or folders of them, in
|
|
74
|
+
a git repository, with --commit to compare them with the fonts at the same
|
|
75
|
+
paths in a commit. Browsers only apply TrueType hinting on Windows, so open
|
|
76
|
+
the pages on Windows.
|
|
77
|
+
|
|
78
|
+
positional arguments:
|
|
79
|
+
BEFORE AFTER the old and the new font (TTF), or folders of fonts.
|
|
80
|
+
With --commit, the new fonts or folders
|
|
81
|
+
|
|
82
|
+
options:
|
|
83
|
+
-h, --help show this help message and exit
|
|
84
|
+
-fb FONT [FONT ...], --fonts-before FONT [FONT ...]
|
|
85
|
+
the old fonts (TTF), or folders of fonts
|
|
86
|
+
-fa FONT [FONT ...], --fonts-after FONT [FONT ...]
|
|
87
|
+
the new fonts (TTF), or folders of fonts
|
|
88
|
+
--commit [REF] compare the new fonts with the fonts at the same paths
|
|
89
|
+
in this commit, e.g. HEAD~1 or a tag (default: HEAD,
|
|
90
|
+
the last commit)
|
|
91
|
+
-o OUT, --out OUT, --output OUT
|
|
92
|
+
folder for the pages and copies of the fonts (default:
|
|
93
|
+
hinting-diff)
|
|
94
|
+
--version show program's version number and exit
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The page has:
|
|
98
|
+
|
|
99
|
+
- **Sample text**, which starts as every character the new font encodes
|
|
100
|
+
(without combining marks or spaces), for a quick look over the whole character
|
|
101
|
+
set. Choose **Basic Latin** in the **Text** menu for its letters, figures and
|
|
102
|
+
punctuation, or edit the text to use your own (**Custom**). Tick **Text
|
|
103
|
+
waterfall** to show the text from 8 to 64 ppem, one line for each size, cut off
|
|
104
|
+
at the right: editing the text at one size changes it at the others.
|
|
105
|
+
- **Every glyph**, at the **Font Size** you choose (48 ppem to start with).
|
|
106
|
+
Hover over a glyph to see its name, or filter the glyphs by name. Glyphs that
|
|
107
|
+
are only in one of the fonts say so.
|
|
108
|
+
- **A waterfall** of a glyph from 8 to 64 ppem: click a glyph to show it.
|
|
109
|
+
- For variable fonts, an **Instance** menu with the font's named instances.
|
|
110
|
+
|
|
111
|
+
The size, font, text, filter and selected glyph are kept for the browser
|
|
112
|
+
tab's session, so they stay the same when you open another font's page in the
|
|
113
|
+
same tab.
|
|
114
|
+
|
|
115
|
+
Sizes are in device pixels, so they stay the same with browser zoom or display
|
|
116
|
+
scaling (e.g. 150% in Windows), which change how many device pixels a CSS pixel
|
|
117
|
+
is.
|
|
118
|
+
|
|
119
|
+
### Comparing with a commit
|
|
120
|
+
|
|
121
|
+
In a git repository, give only the new fonts, or folders of them, with
|
|
122
|
+
`--commit` to compare them with the fonts at the same paths in a commit:
|
|
123
|
+
|
|
124
|
+
```shell
|
|
125
|
+
hinting-diff fonts/ttf/ --commit
|
|
126
|
+
hinting-diff fonts/ttf/*.ttf --commit HEAD~1
|
|
127
|
+
hinting-diff fonts/ttf/Family-Regular.ttf --commit v1.2.0
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
By default, the fonts are compared with the last commit (`HEAD`), e.g. to check
|
|
131
|
+
fonts you've just built before committing them. Give another commit, e.g.
|
|
132
|
+
`HEAD~1`, a branch, a tag or a commit hash, to compare with that. Put `--commit`
|
|
133
|
+
after the fonts, or give its commit, as in `--commit HEAD fonts/ttf/`: otherwise
|
|
134
|
+
the fonts' path is taken as the commit.
|
|
135
|
+
|
|
136
|
+
A font that wasn't in the commit, or one in a folder that was in the commit but
|
|
137
|
+
isn't now, is skipped, with a warning. The old fonts are read from the local
|
|
138
|
+
repository, so `git` needs to be installed, and the commit needs to be there,
|
|
139
|
+
e.g. `git fetch` first for `origin/main`. Fonts in
|
|
140
|
+
[Git LFS](https://git-lfs.com) work too, if `git lfs` is installed.
|
|
141
|
+
|
|
142
|
+
### Showing the page in a report
|
|
143
|
+
|
|
144
|
+
A page that shows the hinting page in a frame can pick a variable font's
|
|
145
|
+
instance by adding its name to the URL, e.g.
|
|
146
|
+
`Family-Regular-hinting.html#style=Bold`. This hides the page's own
|
|
147
|
+
**Instance** menu.
|
|
148
|
+
|
|
149
|
+
## Python API
|
|
150
|
+
|
|
151
|
+
Everything the command does is available from Python too, e.g. to make hinting
|
|
152
|
+
pages as part of a bigger report.
|
|
153
|
+
|
|
154
|
+
### Writing a page
|
|
155
|
+
|
|
156
|
+
`write_hinting_page()` writes the page for one font:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from pathlib import Path
|
|
160
|
+
|
|
161
|
+
from hinting_diff import write_hinting_page
|
|
162
|
+
|
|
163
|
+
page_path = write_hinting_page(
|
|
164
|
+
Path("old/Family-Regular.ttf"),
|
|
165
|
+
Path("new/Family-Regular.ttf"),
|
|
166
|
+
Path("hinting-diff"),
|
|
167
|
+
)
|
|
168
|
+
print(page_path) # hinting-diff/Family-Regular-hinting.html
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Its arguments are:
|
|
172
|
+
|
|
173
|
+
- `before_path`: the old font (TTF).
|
|
174
|
+
- `after_path`: the new font (TTF).
|
|
175
|
+
- `output_path`: the folder for the page and the copies of the fonts. It's made if
|
|
176
|
+
it doesn't exist yet.
|
|
177
|
+
- `page_name` (optional): the page's file name. By default, it's the new font's
|
|
178
|
+
name with `-hinting.html`, e.g. `Family-Regular-hinting.html`.
|
|
179
|
+
|
|
180
|
+
It returns the page's path. The copies of the fonts are saved next to the page as
|
|
181
|
+
`hinting-old-<new font's file name>` and `hinting-new-<new font's file name>`, so
|
|
182
|
+
pages for several fonts can share a folder.
|
|
183
|
+
|
|
184
|
+
It doesn't check that the fonts exist first: a missing or broken font raises
|
|
185
|
+
fontTools' or Python's own error (e.g. `FileNotFoundError`), and a font with too
|
|
186
|
+
many glyphs to map to Private Use Area codepoints raises a `ValueError`.
|
|
187
|
+
|
|
188
|
+
### Writing pages for a family
|
|
189
|
+
|
|
190
|
+
`match_fonts()` matches old and new fonts by their file names, as the command
|
|
191
|
+
does, and `write_index_page()` writes a page that links to hinting pages:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from pathlib import Path
|
|
195
|
+
|
|
196
|
+
from hinting_diff import match_fonts, write_hinting_page, write_index_page
|
|
197
|
+
|
|
198
|
+
font_match = match_fonts([Path("old")], [Path("new")])
|
|
199
|
+
for after_path in font_match.only_after:
|
|
200
|
+
print(f"{after_path.name} is new")
|
|
201
|
+
page_paths = [
|
|
202
|
+
write_hinting_page(before_path, after_path, Path("hinting-diff"))
|
|
203
|
+
for before_path, after_path in font_match.pairs
|
|
204
|
+
]
|
|
205
|
+
index_path = write_index_page(page_paths, Path("hinting-diff"))
|
|
206
|
+
print(index_path) # hinting-diff/index.html
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
- `match_fonts(before_paths, after_paths)` takes the old and the new fonts, each
|
|
210
|
+
as fonts or folders of fonts, and returns a `FontMatch` named tuple:
|
|
211
|
+
- `pairs`: a list of `(old font, new font)` with the same file name, in file
|
|
212
|
+
name order.
|
|
213
|
+
- `only_before`: old fonts without a new font with the same file name.
|
|
214
|
+
- `only_after`: new fonts without an old font with the same file name.
|
|
215
|
+
|
|
216
|
+
A single old font and a single new font, given on their own, are paired
|
|
217
|
+
whatever their names. It raises a `FileNotFoundError` for a path that doesn't
|
|
218
|
+
exist, and a `ValueError` for a folder without TrueType fonts or for two old or
|
|
219
|
+
two new fonts with the same file name.
|
|
220
|
+
- `find_fonts(paths)` returns the fonts in a list of paths, as `match_fonts()`
|
|
221
|
+
finds them: fonts as they are, and every TrueType font (`.ttf`, in any case) in
|
|
222
|
+
folders and their subfolders, in file name order.
|
|
223
|
+
- `write_index_page(page_paths, output_path, page_name="index.html")` writes the
|
|
224
|
+
index page in `output_path` and returns its path. Its links are relative, so the
|
|
225
|
+
pages can be in other folders too.
|
|
226
|
+
|
|
227
|
+
### Reading fonts from a commit
|
|
228
|
+
|
|
229
|
+
`save_fonts_at_commit(paths, commit, output_path)` saves the fonts in `paths`, as
|
|
230
|
+
they were at `commit`, in `output_path`, and returns their paths there, to give
|
|
231
|
+
to `match_fonts()` as the old fonts:
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
import tempfile
|
|
235
|
+
from pathlib import Path
|
|
236
|
+
|
|
237
|
+
from hinting_diff import match_fonts, save_fonts_at_commit
|
|
238
|
+
|
|
239
|
+
fonts_path = Path("fonts/ttf")
|
|
240
|
+
with tempfile.TemporaryDirectory() as temp_folder:
|
|
241
|
+
before_paths = save_fonts_at_commit([fonts_path], "HEAD~1", Path(temp_folder))
|
|
242
|
+
font_match = match_fonts(before_paths, [fonts_path])
|
|
243
|
+
... # Write the pages before the temporary folder is deleted
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Each path is a font or a folder of fonts in a git repository. For a folder, every
|
|
247
|
+
TrueType font that was in it, or its subfolders, at the commit is saved. A font
|
|
248
|
+
that wasn't in the commit isn't saved. It raises a `ValueError` if a path isn't in
|
|
249
|
+
a git repository or the commit doesn't exist, and a `FileNotFoundError` for a path
|
|
250
|
+
that doesn't exist.
|
|
251
|
+
|
|
252
|
+
### Lower-level functions
|
|
253
|
+
|
|
254
|
+
The functions the page is made with can be used on their own:
|
|
255
|
+
|
|
256
|
+
- `add_glyph_codepoints(font_path, output_path)` saves a copy of a font with each
|
|
257
|
+
glyph mapped to a Private Use Area codepoint (see
|
|
258
|
+
[How it works](#how-it-works)), and returns a `dict` of each glyph's name and
|
|
259
|
+
codepoint. `.notdef` isn't mapped.
|
|
260
|
+
- `get_sample_text(font)` returns every character a `TTFont` encodes, in
|
|
261
|
+
codepoint order, without combining marks or characters that show nothing.
|
|
262
|
+
- `get_named_instances(font)` returns a variable `TTFont`'s named instances as a
|
|
263
|
+
list of `(name, coordinates)`, e.g. `("Bold", {"wght": 700.0})`. It returns an
|
|
264
|
+
empty list for a static font.
|
|
265
|
+
- `GLYPH_CODEPOINT_START` is the codepoint the first glyph is mapped to
|
|
266
|
+
(`0xF0000`). A glyph's codepoint is this plus its glyph ID.
|
|
267
|
+
|
|
268
|
+
```python
|
|
269
|
+
from pathlib import Path
|
|
270
|
+
|
|
271
|
+
from fontTools.ttLib import TTFont
|
|
272
|
+
|
|
273
|
+
from hinting_diff import add_glyph_codepoints, get_named_instances
|
|
274
|
+
|
|
275
|
+
codepoints = add_glyph_codepoints(
|
|
276
|
+
Path("new/Family-Regular.ttf"), Path("Family-Regular-pua.ttf")
|
|
277
|
+
)
|
|
278
|
+
print(f"U+{codepoints['a']:X}") # e.g. U+F0024
|
|
279
|
+
|
|
280
|
+
with TTFont("new/Family-Regular.ttf", lazy=True) as font:
|
|
281
|
+
for name, coordinates in get_named_instances(font):
|
|
282
|
+
print(name, coordinates)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`hinting_diff.__version__` is the package's version.
|
|
286
|
+
|
|
287
|
+
## How it works
|
|
288
|
+
|
|
289
|
+
Browsers can only show characters, not glyphs, so the fonts on the page are
|
|
290
|
+
copies with each glyph mapped to a Private Use Area codepoint, from U+F0000.
|
|
291
|
+
Only their `cmap` table changes: the other tables, including `glyf`, `fpgm`,
|
|
292
|
+
`prep` and `cvt `, are saved as they are, so the hinting is kept. Glyphs that a
|
|
293
|
+
variable font swaps with feature variations (`rvrn`) at the selected instance
|
|
294
|
+
show the swapped glyph, as they would in use.
|
|
295
|
+
|
|
296
|
+
## Contributing
|
|
297
|
+
|
|
298
|
+
Bug reports, ideas and pull requests are welcome: see the
|
|
299
|
+
[contributing guide](https://github.com/klim-type-foundry/hinting-diff/blob/main/CONTRIBUTING.md)
|
|
300
|
+
for how to set up the project and make a change. Please report security
|
|
301
|
+
problems privately, as the
|
|
302
|
+
[security policy](https://github.com/klim-type-foundry/hinting-diff/blob/main/SECURITY.md)
|
|
303
|
+
explains.
|
|
304
|
+
|
|
305
|
+
## Acknowledgements
|
|
306
|
+
|
|
307
|
+
The page's look and its **old**/**new** toggle follow the HTML pages of
|
|
308
|
+
[diffenator2](https://github.com/googlefonts/diffenator2) (Copyright Google LLC,
|
|
309
|
+
Apache License 2.0), so a hinting page fits in with them in a report. Its styles
|
|
310
|
+
are adapted from diffenator2's.
|
|
311
|
+
|
|
312
|
+
## Licence
|
|
313
|
+
|
|
314
|
+
[Apache License 2.0](https://github.com/klim-type-foundry/hinting-diff/blob/main/LICENSE.txt)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.2.0
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
from importlib.metadata import PackageNotFoundError, version
|
|
2
2
|
|
|
3
|
+
from hinting_diff.git import save_fonts_at_commit
|
|
4
|
+
from hinting_diff.matching import FontMatch, find_fonts, match_fonts
|
|
3
5
|
from hinting_diff.page import (
|
|
4
6
|
GLYPH_CODEPOINT_START,
|
|
5
7
|
add_glyph_codepoints,
|
|
6
8
|
get_named_instances,
|
|
7
9
|
get_sample_text,
|
|
8
10
|
write_hinting_page,
|
|
11
|
+
write_index_page,
|
|
9
12
|
)
|
|
10
13
|
|
|
11
14
|
try:
|
|
@@ -18,9 +21,14 @@ finally:
|
|
|
18
21
|
|
|
19
22
|
__all__ = [
|
|
20
23
|
"GLYPH_CODEPOINT_START",
|
|
24
|
+
"FontMatch",
|
|
21
25
|
"__version__",
|
|
22
26
|
"add_glyph_codepoints",
|
|
27
|
+
"find_fonts",
|
|
23
28
|
"get_named_instances",
|
|
24
29
|
"get_sample_text",
|
|
30
|
+
"match_fonts",
|
|
31
|
+
"save_fonts_at_commit",
|
|
25
32
|
"write_hinting_page",
|
|
33
|
+
"write_index_page",
|
|
26
34
|
]
|