hinting-diff 0.1.1__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.
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,224 @@
1
+ Metadata-Version: 2.4
2
+ Name: hinting-diff
3
+ Version: 0.1.1
4
+ Summary: Compare the TrueType hinting of two versions of a font in a browser
5
+ Author: Klim Type Foundry
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Source, https://github.com/klim-type-foundry/hinting-diff
8
+ Project-URL: Issues, https://github.com/klim-type-foundry/hinting-diff/issues
9
+ Project-URL: Changelog, https://github.com/klim-type-foundry/hinting-diff/releases
10
+ Keywords: fonts,truetype,hinting,diff
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Text Processing :: Fonts
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE.txt
27
+ Requires-Dist: fonttools<5,>=4.40
28
+ Dynamic: license-file
29
+
30
+ # hinting-diff
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/hinting-diff)](https://pypi.org/project/hinting-diff/)
33
+ [![Python versions](https://img.shields.io/pypi/pyversions/hinting-diff)](https://pypi.org/project/hinting-diff/)
34
+ [![Checks](https://github.com/klim-type-foundry/hinting-diff/actions/workflows/check.yml/badge.svg?branch=main)](https://github.com/klim-type-foundry/hinting-diff/actions/workflows/check.yml)
35
+ [![Licence](https://img.shields.io/pypi/l/hinting-diff)](https://github.com/klim-type-foundry/hinting-diff/blob/main/LICENSE.txt)
36
+
37
+ Compare the TrueType hinting of two versions of a font in a browser.
38
+
39
+ `hinting-diff` writes an HTML page that shows every glyph of a font, encoded or
40
+ not, rendered with its hinting at a size in pixels per em (ppem), for the old
41
+ and the new version of the font. Click **old**/**new** to switch between them
42
+ and see what changed.
43
+
44
+ ![A waterfall of the letter "a" from 8 to 19 ppem, switching between the old, unhinted font, whose small sizes are blurry and uneven, and the new, hinted font, whose small sizes are sharper and more even](https://raw.githubusercontent.com/klim-type-foundry/hinting-diff/main/docs/hinting-diff.webp)
45
+
46
+ <sub>Source Sans Pro without hinting (old) and hinted with ttfautohint (new), in
47
+ Firefox on Windows 11, enlarged 3×.</sub>
48
+
49
+ Browsers only apply TrueType hinting on Windows, so open the page on Windows. It
50
+ works in old browsers too, as far back as Internet Explorer 11, Chrome 49 and
51
+ Firefox 52, for checking hinting on old versions of Windows.
52
+
53
+ ## Install
54
+
55
+ ```shell
56
+ pip install hinting-diff
57
+ ```
58
+
59
+ It needs Python 3.10 or later, and installs
60
+ [fontTools](https://github.com/fonttools/fonttools) too.
61
+
62
+ ## Usage
63
+
64
+ ```shell
65
+ hinting-diff old/Family-Regular.ttf new/Family-Regular.ttf -o hinting-diff/
66
+ ```
67
+
68
+ This writes `hinting-diff/Family-Regular-hinting.html`, with copies of both
69
+ fonts next to it, and prints the page's path. Open it in a browser on Windows.
70
+
71
+ The output folder is optional, and is `hinting-diff` by default. All the
72
+ options:
73
+
74
+ ```text
75
+ usage: hinting-diff [-h] [-o OUTPUT] [--version] before after
76
+
77
+ Write a page to compare the TrueType hinting of two versions of a font.
78
+ Browsers only apply TrueType hinting on Windows, so open the page on Windows.
79
+
80
+ positional arguments:
81
+ before the old font (TTF)
82
+ after the new font (TTF)
83
+
84
+ options:
85
+ -h, --help show this help message and exit
86
+ -o OUTPUT, --output OUTPUT
87
+ folder for the page and copies of the fonts (default:
88
+ hinting-diff)
89
+ --version show program's version number and exit
90
+ ```
91
+
92
+ The page has:
93
+
94
+ - **Sample text**, which starts as every character the new font encodes
95
+ (without combining marks or spaces), for a quick look over the whole character
96
+ set. You can edit it.
97
+ - **Every glyph**, at the **Font Size** you choose (48 ppem to start with).
98
+ Hover over a glyph to see its name, or filter the glyphs by name. Glyphs that
99
+ are only in one of the fonts say so.
100
+ - **A waterfall** of a glyph from 8 to 64 ppem: click a glyph to show it.
101
+ - For variable fonts, an **Instance** menu with the font's named instances.
102
+
103
+ The size, font, filter, selected glyph and edited text are kept for the browser
104
+ tab's session, so they stay the same when you open another font's page in the
105
+ same tab.
106
+
107
+ Sizes are in device pixels, so they stay the same with browser zoom or display
108
+ scaling (e.g. 150% in Windows), which change how many device pixels a CSS pixel
109
+ is.
110
+
111
+ ### Showing the page in a report
112
+
113
+ A page that shows the hinting page in a frame can pick a variable font's
114
+ instance by adding its name to the URL, e.g.
115
+ `Family-Regular-hinting.html#style=Bold`. This hides the page's own
116
+ **Instance** menu.
117
+
118
+ ## Python API
119
+
120
+ Everything the command does is available from Python too, e.g. to make hinting
121
+ pages as part of a bigger report.
122
+
123
+ ### Writing a page
124
+
125
+ `write_hinting_page()` does the same as the `hinting-diff` command:
126
+
127
+ ```python
128
+ from pathlib import Path
129
+
130
+ from hinting_diff import write_hinting_page
131
+
132
+ page_path = write_hinting_page(
133
+ Path("old/Family-Regular.ttf"),
134
+ Path("new/Family-Regular.ttf"),
135
+ Path("hinting-diff"),
136
+ )
137
+ print(page_path) # hinting-diff/Family-Regular-hinting.html
138
+ ```
139
+
140
+ Its arguments are:
141
+
142
+ - `before_path`: the old font (TTF).
143
+ - `after_path`: the new font (TTF).
144
+ - `output_path`: the folder for the page and the copies of the fonts. It's made if
145
+ it doesn't exist yet.
146
+ - `page_name` (optional): the page's file name. By default, it's the new font's
147
+ name with `-hinting.html`, e.g. `Family-Regular-hinting.html`.
148
+
149
+ It returns the page's path. The copies of the fonts are saved next to the page as
150
+ `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:
152
+
153
+ ```python
154
+ from pathlib import Path
155
+
156
+ from hinting_diff import write_hinting_page
157
+
158
+ for after_path in sorted(Path("new").glob("*.ttf")):
159
+ before_path = Path("old", after_path.name)
160
+ if before_path.is_file():
161
+ write_hinting_page(before_path, after_path, Path("hinting-diff"))
162
+ ```
163
+
164
+ Unlike the command, it doesn't check that the fonts exist first: a missing or
165
+ broken font raises fontTools' or Python's own error (e.g. `FileNotFoundError`),
166
+ and a font with too many glyphs to map to Private Use Area codepoints raises a
167
+ `ValueError`.
168
+
169
+ ### Lower-level functions
170
+
171
+ The functions the page is made with can be used on their own:
172
+
173
+ - `add_glyph_codepoints(font_path, output_path)` saves a copy of a font with each
174
+ glyph mapped to a Private Use Area codepoint (see
175
+ [How it works](#how-it-works)), and returns a `dict` of each glyph's name and
176
+ codepoint. `.notdef` isn't mapped.
177
+ - `get_sample_text(font)` returns every character a `TTFont` encodes, in
178
+ codepoint order, without combining marks or characters that show nothing.
179
+ - `get_named_instances(font)` returns a variable `TTFont`'s named instances as a
180
+ list of `(name, coordinates)`, e.g. `("Bold", {"wght": 700.0})`. It returns an
181
+ empty list for a static font.
182
+ - `GLYPH_CODEPOINT_START` is the codepoint the first glyph is mapped to
183
+ (`0xF0000`). A glyph's codepoint is this plus its glyph ID.
184
+
185
+ ```python
186
+ from pathlib import Path
187
+
188
+ from fontTools.ttLib import TTFont
189
+
190
+ from hinting_diff import add_glyph_codepoints, get_named_instances
191
+
192
+ codepoints = add_glyph_codepoints(
193
+ Path("new/Family-Regular.ttf"), Path("Family-Regular-pua.ttf")
194
+ )
195
+ print(f"U+{codepoints['a']:X}") # e.g. U+F0024
196
+
197
+ with TTFont("new/Family-Regular.ttf", lazy=True) as font:
198
+ for name, coordinates in get_named_instances(font):
199
+ print(name, coordinates)
200
+ ```
201
+
202
+ `hinting_diff.__version__` is the package's version.
203
+
204
+ ## How it works
205
+
206
+ Browsers can only show characters, not glyphs, so the fonts on the page are
207
+ copies with each glyph mapped to a Private Use Area codepoint, from U+F0000.
208
+ Only their `cmap` table changes: the other tables, including `glyf`, `fpgm`,
209
+ `prep` and `cvt `, are saved as they are, so the hinting is kept. Glyphs that a
210
+ variable font swaps with feature variations (`rvrn`) at the selected instance
211
+ show the swapped glyph, as they would in use.
212
+
213
+ ## Contributing
214
+
215
+ Bug reports, ideas and pull requests are welcome: see the
216
+ [contributing guide](https://github.com/klim-type-foundry/hinting-diff/blob/main/CONTRIBUTING.md)
217
+ for how to set up the project and make a change. Please report security
218
+ problems privately, as the
219
+ [security policy](https://github.com/klim-type-foundry/hinting-diff/blob/main/SECURITY.md)
220
+ explains.
221
+
222
+ ## Licence
223
+
224
+ [Apache License 2.0](https://github.com/klim-type-foundry/hinting-diff/blob/main/LICENSE.txt)
@@ -0,0 +1,195 @@
1
+ # hinting-diff
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/hinting-diff)](https://pypi.org/project/hinting-diff/)
4
+ [![Python versions](https://img.shields.io/pypi/pyversions/hinting-diff)](https://pypi.org/project/hinting-diff/)
5
+ [![Checks](https://github.com/klim-type-foundry/hinting-diff/actions/workflows/check.yml/badge.svg?branch=main)](https://github.com/klim-type-foundry/hinting-diff/actions/workflows/check.yml)
6
+ [![Licence](https://img.shields.io/pypi/l/hinting-diff)](https://github.com/klim-type-foundry/hinting-diff/blob/main/LICENSE.txt)
7
+
8
+ Compare the TrueType hinting of two versions of a font in a browser.
9
+
10
+ `hinting-diff` writes an HTML page that shows every glyph of a font, encoded or
11
+ not, rendered with its hinting at a size in pixels per em (ppem), for the old
12
+ and the new version of the font. Click **old**/**new** to switch between them
13
+ and see what changed.
14
+
15
+ ![A waterfall of the letter "a" from 8 to 19 ppem, switching between the old, unhinted font, whose small sizes are blurry and uneven, and the new, hinted font, whose small sizes are sharper and more even](https://raw.githubusercontent.com/klim-type-foundry/hinting-diff/main/docs/hinting-diff.webp)
16
+
17
+ <sub>Source Sans Pro without hinting (old) and hinted with ttfautohint (new), in
18
+ Firefox on Windows 11, enlarged 3×.</sub>
19
+
20
+ Browsers only apply TrueType hinting on Windows, so open the page on Windows. It
21
+ works in old browsers too, as far back as Internet Explorer 11, Chrome 49 and
22
+ Firefox 52, for checking hinting on old versions of Windows.
23
+
24
+ ## Install
25
+
26
+ ```shell
27
+ pip install hinting-diff
28
+ ```
29
+
30
+ It needs Python 3.10 or later, and installs
31
+ [fontTools](https://github.com/fonttools/fonttools) too.
32
+
33
+ ## Usage
34
+
35
+ ```shell
36
+ hinting-diff old/Family-Regular.ttf new/Family-Regular.ttf -o hinting-diff/
37
+ ```
38
+
39
+ This writes `hinting-diff/Family-Regular-hinting.html`, with copies of both
40
+ fonts next to it, and prints the page's path. Open it in a browser on Windows.
41
+
42
+ The output folder is optional, and is `hinting-diff` by default. All the
43
+ options:
44
+
45
+ ```text
46
+ usage: hinting-diff [-h] [-o OUTPUT] [--version] before after
47
+
48
+ Write a page to compare the TrueType hinting of two versions of a font.
49
+ Browsers only apply TrueType hinting on Windows, so open the page on Windows.
50
+
51
+ positional arguments:
52
+ before the old font (TTF)
53
+ after the new font (TTF)
54
+
55
+ options:
56
+ -h, --help show this help message and exit
57
+ -o OUTPUT, --output OUTPUT
58
+ folder for the page and copies of the fonts (default:
59
+ hinting-diff)
60
+ --version show program's version number and exit
61
+ ```
62
+
63
+ The page has:
64
+
65
+ - **Sample text**, which starts as every character the new font encodes
66
+ (without combining marks or spaces), for a quick look over the whole character
67
+ set. You can edit it.
68
+ - **Every glyph**, at the **Font Size** you choose (48 ppem to start with).
69
+ Hover over a glyph to see its name, or filter the glyphs by name. Glyphs that
70
+ are only in one of the fonts say so.
71
+ - **A waterfall** of a glyph from 8 to 64 ppem: click a glyph to show it.
72
+ - For variable fonts, an **Instance** menu with the font's named instances.
73
+
74
+ The size, font, filter, selected glyph and edited text are kept for the browser
75
+ tab's session, so they stay the same when you open another font's page in the
76
+ same tab.
77
+
78
+ Sizes are in device pixels, so they stay the same with browser zoom or display
79
+ scaling (e.g. 150% in Windows), which change how many device pixels a CSS pixel
80
+ is.
81
+
82
+ ### Showing the page in a report
83
+
84
+ A page that shows the hinting page in a frame can pick a variable font's
85
+ instance by adding its name to the URL, e.g.
86
+ `Family-Regular-hinting.html#style=Bold`. This hides the page's own
87
+ **Instance** menu.
88
+
89
+ ## Python API
90
+
91
+ Everything the command does is available from Python too, e.g. to make hinting
92
+ pages as part of a bigger report.
93
+
94
+ ### Writing a page
95
+
96
+ `write_hinting_page()` does the same as the `hinting-diff` command:
97
+
98
+ ```python
99
+ from pathlib import Path
100
+
101
+ from hinting_diff import write_hinting_page
102
+
103
+ page_path = write_hinting_page(
104
+ Path("old/Family-Regular.ttf"),
105
+ Path("new/Family-Regular.ttf"),
106
+ Path("hinting-diff"),
107
+ )
108
+ print(page_path) # hinting-diff/Family-Regular-hinting.html
109
+ ```
110
+
111
+ Its arguments are:
112
+
113
+ - `before_path`: the old font (TTF).
114
+ - `after_path`: the new font (TTF).
115
+ - `output_path`: the folder for the page and the copies of the fonts. It's made if
116
+ it doesn't exist yet.
117
+ - `page_name` (optional): the page's file name. By default, it's the new font's
118
+ name with `-hinting.html`, e.g. `Family-Regular-hinting.html`.
119
+
120
+ It returns the page's path. The copies of the fonts are saved next to the page as
121
+ `hinting-old-<new font's file name>` and `hinting-new-<new font's file name>`, so
122
+ pages for several fonts can share a folder:
123
+
124
+ ```python
125
+ from pathlib import Path
126
+
127
+ from hinting_diff import write_hinting_page
128
+
129
+ for after_path in sorted(Path("new").glob("*.ttf")):
130
+ before_path = Path("old", after_path.name)
131
+ if before_path.is_file():
132
+ write_hinting_page(before_path, after_path, Path("hinting-diff"))
133
+ ```
134
+
135
+ Unlike the command, it doesn't check that the fonts exist first: a missing or
136
+ broken font raises fontTools' or Python's own error (e.g. `FileNotFoundError`),
137
+ and a font with too many glyphs to map to Private Use Area codepoints raises a
138
+ `ValueError`.
139
+
140
+ ### Lower-level functions
141
+
142
+ The functions the page is made with can be used on their own:
143
+
144
+ - `add_glyph_codepoints(font_path, output_path)` saves a copy of a font with each
145
+ glyph mapped to a Private Use Area codepoint (see
146
+ [How it works](#how-it-works)), and returns a `dict` of each glyph's name and
147
+ codepoint. `.notdef` isn't mapped.
148
+ - `get_sample_text(font)` returns every character a `TTFont` encodes, in
149
+ codepoint order, without combining marks or characters that show nothing.
150
+ - `get_named_instances(font)` returns a variable `TTFont`'s named instances as a
151
+ list of `(name, coordinates)`, e.g. `("Bold", {"wght": 700.0})`. It returns an
152
+ empty list for a static font.
153
+ - `GLYPH_CODEPOINT_START` is the codepoint the first glyph is mapped to
154
+ (`0xF0000`). A glyph's codepoint is this plus its glyph ID.
155
+
156
+ ```python
157
+ from pathlib import Path
158
+
159
+ from fontTools.ttLib import TTFont
160
+
161
+ from hinting_diff import add_glyph_codepoints, get_named_instances
162
+
163
+ codepoints = add_glyph_codepoints(
164
+ Path("new/Family-Regular.ttf"), Path("Family-Regular-pua.ttf")
165
+ )
166
+ print(f"U+{codepoints['a']:X}") # e.g. U+F0024
167
+
168
+ with TTFont("new/Family-Regular.ttf", lazy=True) as font:
169
+ for name, coordinates in get_named_instances(font):
170
+ print(name, coordinates)
171
+ ```
172
+
173
+ `hinting_diff.__version__` is the package's version.
174
+
175
+ ## How it works
176
+
177
+ Browsers can only show characters, not glyphs, so the fonts on the page are
178
+ copies with each glyph mapped to a Private Use Area codepoint, from U+F0000.
179
+ Only their `cmap` table changes: the other tables, including `glyf`, `fpgm`,
180
+ `prep` and `cvt `, are saved as they are, so the hinting is kept. Glyphs that a
181
+ variable font swaps with feature variations (`rvrn`) at the selected instance
182
+ show the swapped glyph, as they would in use.
183
+
184
+ ## Contributing
185
+
186
+ Bug reports, ideas and pull requests are welcome: see the
187
+ [contributing guide](https://github.com/klim-type-foundry/hinting-diff/blob/main/CONTRIBUTING.md)
188
+ for how to set up the project and make a change. Please report security
189
+ problems privately, as the
190
+ [security policy](https://github.com/klim-type-foundry/hinting-diff/blob/main/SECURITY.md)
191
+ explains.
192
+
193
+ ## Licence
194
+
195
+ [Apache License 2.0](https://github.com/klim-type-foundry/hinting-diff/blob/main/LICENSE.txt)
@@ -0,0 +1 @@
1
+ 0.1.1