hinting-diff 0.1.1__py3-none-any.whl
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/__init__.py +26 -0
- hinting_diff/cli.py +43 -0
- hinting_diff/page.html +418 -0
- hinting_diff/page.py +155 -0
- hinting_diff/py.typed +0 -0
- hinting_diff-0.1.1.dist-info/METADATA +224 -0
- hinting_diff-0.1.1.dist-info/RECORD +11 -0
- hinting_diff-0.1.1.dist-info/WHEEL +5 -0
- hinting_diff-0.1.1.dist-info/entry_points.txt +2 -0
- hinting_diff-0.1.1.dist-info/licenses/LICENSE.txt +202 -0
- hinting_diff-0.1.1.dist-info/top_level.txt +1 -0
hinting_diff/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
2
|
+
|
|
3
|
+
from hinting_diff.page import (
|
|
4
|
+
GLYPH_CODEPOINT_START,
|
|
5
|
+
add_glyph_codepoints,
|
|
6
|
+
get_named_instances,
|
|
7
|
+
get_sample_text,
|
|
8
|
+
write_hinting_page,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
# The version is set by the VERSION file, see pyproject.toml
|
|
13
|
+
__version__ = version("hinting-diff")
|
|
14
|
+
except PackageNotFoundError: # pragma: no cover
|
|
15
|
+
__version__ = "unknown"
|
|
16
|
+
finally:
|
|
17
|
+
del version, PackageNotFoundError
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"GLYPH_CODEPOINT_START",
|
|
21
|
+
"__version__",
|
|
22
|
+
"add_glyph_codepoints",
|
|
23
|
+
"get_named_instances",
|
|
24
|
+
"get_sample_text",
|
|
25
|
+
"write_hinting_page",
|
|
26
|
+
]
|
hinting_diff/cli.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from hinting_diff import __version__
|
|
6
|
+
from hinting_diff.page import write_hinting_page
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main(argv: list[str] | None = None) -> int:
|
|
10
|
+
parser = argparse.ArgumentParser(
|
|
11
|
+
prog="hinting-diff",
|
|
12
|
+
description=(
|
|
13
|
+
"Write a page to compare the TrueType hinting of two versions of a "
|
|
14
|
+
"font. Browsers only apply TrueType hinting on Windows, so open the "
|
|
15
|
+
"page on Windows."
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument("before", type=Path, help="the old font (TTF)")
|
|
19
|
+
parser.add_argument("after", type=Path, help="the new font (TTF)")
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
"-o",
|
|
22
|
+
"--output",
|
|
23
|
+
type=Path,
|
|
24
|
+
default=Path("hinting-diff"),
|
|
25
|
+
help="folder for the page and copies of the fonts (default: hinting-diff)",
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument("--version", action="version", version=__version__)
|
|
28
|
+
args = parser.parse_args(argv)
|
|
29
|
+
|
|
30
|
+
for font_path in (args.before, args.after):
|
|
31
|
+
if not font_path.is_file():
|
|
32
|
+
parser.error(f"{font_path} not found")
|
|
33
|
+
try:
|
|
34
|
+
page_path = write_hinting_page(args.before, args.after, args.output)
|
|
35
|
+
except Exception as error: # noqa: BLE001
|
|
36
|
+
print(f"hinting-diff: error: {error}", file=sys.stderr)
|
|
37
|
+
return 1
|
|
38
|
+
print(page_path)
|
|
39
|
+
return 0
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__": # pragma: no cover
|
|
43
|
+
sys.exit(main())
|
hinting_diff/page.html
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>Hinting: {{title}}</title>
|
|
6
|
+
<style>
|
|
7
|
+
/* The page has to work in old browsers too, as hinting is checked on old versions
|
|
8
|
+
of Windows (e.g. Internet Explorer 11, Chrome 49 and Firefox 52), so newer CSS
|
|
9
|
+
only refines a layout that works without it */
|
|
10
|
+
@font-face { font-family: "hinting-old"; src: url("{{before_font}}"); }
|
|
11
|
+
@font-face { font-family: "hinting-new"; src: url("{{after_font}}"); }
|
|
12
|
+
/* The look of diffenator2's pages, so the page fits in with them in a report */
|
|
13
|
+
html { font-family: sans-serif; }
|
|
14
|
+
body { font-family: Helvetica; }
|
|
15
|
+
#nav { position: fixed; right: 20px; z-index: 100; }
|
|
16
|
+
.nav-item { display: block; cursor: pointer; -webkit-user-select: none;
|
|
17
|
+
-moz-user-select: none; -ms-user-select: none; user-select: none;
|
|
18
|
+
text-align: center; color: white; background-color: black; font-size: 9pt;
|
|
19
|
+
padding: 5px; margin: 2px; }
|
|
20
|
+
/* .nav-item's display would show hidden items */
|
|
21
|
+
.nav-item[hidden] { display: none; }
|
|
22
|
+
.nav-item select, .nav-item input { background-color: black; color: white;
|
|
23
|
+
font-size: 9pt; }
|
|
24
|
+
.nav-item input { width: 7em; border: 1px solid white; }
|
|
25
|
+
.box-title { width: 100%; font-size: 8pt; font-weight: 700;
|
|
26
|
+
border-top: 1px solid black; padding-top: 5px; margin-bottom: 10pt;
|
|
27
|
+
display: block; }
|
|
28
|
+
.box { margin-bottom: 20pt; }
|
|
29
|
+
.warning { font-size: 9pt; }
|
|
30
|
+
.sample { font-kerning: none; font-feature-settings: "liga" 0, "clig" 0, "calt" 0;
|
|
31
|
+
font-synthesis: none; line-height: 1.2; white-space: pre; }
|
|
32
|
+
.box-text { outline: none; }
|
|
33
|
+
/* Every character the font encodes, wrapped anywhere, as it has no spaces.
|
|
34
|
+
Browsers without `overflow-wrap: anywhere` break words anywhere instead */
|
|
35
|
+
#text-sample { white-space: pre-wrap; word-break: break-all;
|
|
36
|
+
margin-right: 150px; }
|
|
37
|
+
@supports (overflow-wrap: anywhere) {
|
|
38
|
+
#text-sample { word-break: normal; overflow-wrap: anywhere; }
|
|
39
|
+
}
|
|
40
|
+
.font-old { font-family: "hinting-old"; }
|
|
41
|
+
.font-new { font-family: "hinting-new"; }
|
|
42
|
+
.missing { font-size: 8pt; color: #888; }
|
|
43
|
+
.size-label { display: block; font-size: 7pt; color: #888; }
|
|
44
|
+
/* Margins rather than `gap`, which old browsers don't support in flex layouts */
|
|
45
|
+
#waterfall-samples { display: -ms-flexbox; display: flex; -ms-flex-wrap: wrap;
|
|
46
|
+
flex-wrap: wrap; -ms-flex-align: baseline; align-items: baseline;
|
|
47
|
+
margin-right: 150px; }
|
|
48
|
+
#waterfall-samples > span { margin: 0 12px 4px 0; }
|
|
49
|
+
/* The glyphs' cells are as wide as the size in ppem needs (see #glyph-size-style).
|
|
50
|
+
In browsers with grid layout, they also stretch to fill each row */
|
|
51
|
+
#glyphs { margin-right: 150px; }
|
|
52
|
+
.glyph { display: inline-block; vertical-align: top; margin: 2px;
|
|
53
|
+
-webkit-box-sizing: border-box; box-sizing: border-box;
|
|
54
|
+
border: 1px dashed grey; padding: 4px; cursor: pointer; overflow: hidden;
|
|
55
|
+
background: none; color: inherit; font: inherit; text-align: center; }
|
|
56
|
+
@supports (display: grid) {
|
|
57
|
+
#glyphs { display: grid; grid-gap: 4px; gap: 4px; }
|
|
58
|
+
.glyph { margin: 0; }
|
|
59
|
+
}
|
|
60
|
+
.glyph[aria-pressed="true"] { border: 1px solid black; }
|
|
61
|
+
.glyph .missing { white-space: nowrap; }
|
|
62
|
+
</style>
|
|
63
|
+
<!-- The glyphs' cell size, set from the size in ppem -->
|
|
64
|
+
<style id="glyph-size-style"></style>
|
|
65
|
+
</head>
|
|
66
|
+
<body>
|
|
67
|
+
<div id="nav">
|
|
68
|
+
<div class="nav-item" id="font-toggle">old</div>
|
|
69
|
+
<div class="nav-item">
|
|
70
|
+
<label for="ppem">Font Size:</label>
|
|
71
|
+
<select id="ppem"></select>
|
|
72
|
+
</div>
|
|
73
|
+
<div class="nav-item" id="instance-item" hidden>
|
|
74
|
+
<label for="instance">Instance:</label>
|
|
75
|
+
<select id="instance"></select>
|
|
76
|
+
</div>
|
|
77
|
+
<div class="nav-item">
|
|
78
|
+
<label for="filter">Glyphs:</label>
|
|
79
|
+
<input type="text" id="filter" placeholder="Filter by name">
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
<div id="content">
|
|
83
|
+
<h2><b>Hinting</b></h2>
|
|
84
|
+
<p class="warning" id="platform-warning" hidden>Browsers only apply TrueType
|
|
85
|
+
hinting on Windows, so open this page on Windows to inspect it.</p>
|
|
86
|
+
<div class="box">
|
|
87
|
+
<div class="box-title" id="text-title"></div>
|
|
88
|
+
<div contenteditable="true" spellcheck="false" class="box-text sample"
|
|
89
|
+
id="text-sample"></div>
|
|
90
|
+
</div>
|
|
91
|
+
<div class="box" id="waterfall" hidden>
|
|
92
|
+
<div class="box-title" id="waterfall-title"></div>
|
|
93
|
+
<div id="waterfall-samples"></div>
|
|
94
|
+
</div>
|
|
95
|
+
<div class="box">
|
|
96
|
+
<div class="box-title" id="glyphs-title"></div>
|
|
97
|
+
<div id="glyphs"></div>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
<script>
|
|
101
|
+
// ES5 only, without newer DOM methods (e.g. `replaceChildren()` or `append()`), as
|
|
102
|
+
// the page has to work in old browsers too, e.g. Internet Explorer 11, Chrome 49
|
|
103
|
+
// and Firefox 52 on old versions of Windows. tests/test_page.py checks for some of
|
|
104
|
+
// the newer syntax and methods.
|
|
105
|
+
var DATA = {{hinting_json}};
|
|
106
|
+
var TITLE = {{title_json}};
|
|
107
|
+
var fontToggle = document.getElementById("font-toggle");
|
|
108
|
+
var ppemSelect = document.getElementById("ppem");
|
|
109
|
+
var instanceSelect = document.getElementById("instance");
|
|
110
|
+
var filterInput = document.getElementById("filter");
|
|
111
|
+
var textSample = document.getElementById("text-sample");
|
|
112
|
+
var glyphsDiv = document.getElementById("glyphs");
|
|
113
|
+
var glyphSizeStyle = document.getElementById("glyph-size-style");
|
|
114
|
+
var WATERFALL_SIZES = [];
|
|
115
|
+
for (var size = 8; size <= 64; size++) WATERFALL_SIZES.push(size);
|
|
116
|
+
var PPEM_SIZES = WATERFALL_SIZES.concat([72, 96]);
|
|
117
|
+
var DEFAULT_PPEM = 48;
|
|
118
|
+
// The settings are kept for the browser tab's session, so they stay the same when
|
|
119
|
+
// another font's page is opened in the same tab (e.g. in a report's frame)
|
|
120
|
+
var SETTINGS_KEY = "hinting-diff";
|
|
121
|
+
// Like diffenator2's pages, one font is shown at a time, so switching between
|
|
122
|
+
// them shows what changed
|
|
123
|
+
var font = "old";
|
|
124
|
+
var selectedGlyph = null;
|
|
125
|
+
// The sample text, if it's been edited
|
|
126
|
+
var editedText = null;
|
|
127
|
+
|
|
128
|
+
function indexWhere(items, test) {
|
|
129
|
+
for (var i = 0; i < items.length; i++) {
|
|
130
|
+
if (test(items[i])) return i;
|
|
131
|
+
}
|
|
132
|
+
return -1;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function removeChildren(element) {
|
|
136
|
+
while (element.firstChild) element.removeChild(element.firstChild);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Appended as one fragment, so the page is laid out once
|
|
140
|
+
function setChildren(element, children) {
|
|
141
|
+
var fragment = document.createDocumentFragment();
|
|
142
|
+
for (var i = 0; i < children.length; i++) fragment.appendChild(children[i]);
|
|
143
|
+
removeChildren(element);
|
|
144
|
+
element.appendChild(fragment);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Like String.fromCodePoint(), for codepoints above U+FFFF too
|
|
148
|
+
function codepointString(codepoint) {
|
|
149
|
+
if (codepoint <= 0xffff) return String.fromCharCode(codepoint);
|
|
150
|
+
var offset = codepoint - 0x10000;
|
|
151
|
+
return String.fromCharCode(0xd800 + (offset >> 10), 0xdc00 + (offset & 0x3ff));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function setHidden(element, hidden) {
|
|
155
|
+
element.hidden = hidden;
|
|
156
|
+
// For browsers that don't hide elements with the `hidden` attribute
|
|
157
|
+
element.style.display = hidden ? "none" : "";
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!/Win/.test(navigator.userAgent)) {
|
|
161
|
+
setHidden(document.getElementById("platform-warning"), false);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
PPEM_SIZES.forEach(function (ppem) {
|
|
165
|
+
var option = document.createElement("option");
|
|
166
|
+
option.value = String(ppem);
|
|
167
|
+
option.textContent = ppem + " ppem";
|
|
168
|
+
ppemSelect.appendChild(option);
|
|
169
|
+
});
|
|
170
|
+
ppemSelect.value = String(DEFAULT_PPEM);
|
|
171
|
+
DATA.instances.forEach(function (instance, index) {
|
|
172
|
+
var option = document.createElement("option");
|
|
173
|
+
option.value = String(index);
|
|
174
|
+
option.textContent = instance.name;
|
|
175
|
+
instanceSelect.appendChild(option);
|
|
176
|
+
});
|
|
177
|
+
setHidden(document.getElementById("instance-item"), !DATA.instances.length);
|
|
178
|
+
|
|
179
|
+
// Storage can be unavailable, e.g. for pages opened from files in some browsers
|
|
180
|
+
function loadSettings() {
|
|
181
|
+
var settings = null;
|
|
182
|
+
try {
|
|
183
|
+
settings = JSON.parse(sessionStorage.getItem(SETTINGS_KEY));
|
|
184
|
+
} catch (error) {}
|
|
185
|
+
if (!settings) return;
|
|
186
|
+
if (PPEM_SIZES.indexOf(settings.ppem) >= 0) ppemSelect.value = String(settings.ppem);
|
|
187
|
+
if (settings.font === "old" || settings.font === "new") font = settings.font;
|
|
188
|
+
if (typeof settings.filter === "string") filterInput.value = settings.filter;
|
|
189
|
+
if (typeof settings.text === "string") editedText = settings.text;
|
|
190
|
+
var index = indexWhere(DATA.glyphs, function (g) {
|
|
191
|
+
return g.name === settings.glyph;
|
|
192
|
+
});
|
|
193
|
+
selectedGlyph = index >= 0 ? DATA.glyphs[index] : null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function saveSettings() {
|
|
197
|
+
var settings = {
|
|
198
|
+
ppem: Number(ppemSelect.value),
|
|
199
|
+
font: font,
|
|
200
|
+
filter: filterInput.value,
|
|
201
|
+
text: editedText,
|
|
202
|
+
glyph: selectedGlyph ? selectedGlyph.name : null
|
|
203
|
+
};
|
|
204
|
+
try {
|
|
205
|
+
sessionStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
|
|
206
|
+
} catch (error) {}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
loadSettings();
|
|
210
|
+
textSample.textContent = editedText === null ? DATA.sampleText : editedText;
|
|
211
|
+
|
|
212
|
+
// The value of a parameter in the URL's fragment, e.g. "style" in "#style=Bold"
|
|
213
|
+
function hashParam(name) {
|
|
214
|
+
var pairs = location.hash.slice(1).split("&");
|
|
215
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
216
|
+
var pair = pairs[i].split("=");
|
|
217
|
+
if (decodeURIComponent(pair[0]) !== name) continue;
|
|
218
|
+
try {
|
|
219
|
+
return decodeURIComponent((pair[1] || "").replace(/\+/g, " "));
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// A page that shows this one in a frame can pick a variable font's instance by
|
|
228
|
+
// its name (e.g. "#style=A%20Regular"), which hides this page's own menu
|
|
229
|
+
function applyStyleFromUrl() {
|
|
230
|
+
var style = hashParam("style");
|
|
231
|
+
var index = indexWhere(DATA.instances, function (i) {
|
|
232
|
+
return i.name === style;
|
|
233
|
+
});
|
|
234
|
+
if (index >= 0) instanceSelect.value = String(index);
|
|
235
|
+
setHidden(
|
|
236
|
+
document.getElementById("instance-item"),
|
|
237
|
+
!DATA.instances.length || index >= 0
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
applyStyleFromUrl();
|
|
241
|
+
window.addEventListener("hashchange", function () {
|
|
242
|
+
applyStyleFromUrl();
|
|
243
|
+
render();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// CSS pixels are device pixels times the zoom and display scaling, so sizes are
|
|
247
|
+
// divided by the ratio to get the size in device pixels per em
|
|
248
|
+
function pixelRatio() {
|
|
249
|
+
return window.devicePixelRatio || 1;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function cssSize(ppem) {
|
|
253
|
+
return ppem / pixelRatio() + "px";
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function variationSettings() {
|
|
257
|
+
var instance = DATA.instances[Number(instanceSelect.value)];
|
|
258
|
+
if (!instance) return "normal";
|
|
259
|
+
var settings = [];
|
|
260
|
+
for (var tag in instance.coords) {
|
|
261
|
+
if (Object.prototype.hasOwnProperty.call(instance.coords, tag)) {
|
|
262
|
+
settings.push('"' + tag + '" ' + instance.coords[tag]);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return settings.join(", ");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function styleSample(element, ppem) {
|
|
269
|
+
element.className = element.className.replace(/(^| )font-(old|new)\b/g, "");
|
|
270
|
+
element.className += " font-" + font;
|
|
271
|
+
element.style.fontSize = cssSize(ppem);
|
|
272
|
+
// Browsers without variable fonts ignore it
|
|
273
|
+
element.style.fontVariationSettings = variationSettings();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function glyphSample(glyph, ppem) {
|
|
277
|
+
var span = document.createElement("span");
|
|
278
|
+
if (glyph[font] === null) {
|
|
279
|
+
span.className = "missing";
|
|
280
|
+
span.textContent = "not in " + font;
|
|
281
|
+
return span;
|
|
282
|
+
}
|
|
283
|
+
span.className = "sample";
|
|
284
|
+
span.textContent = codepointString(glyph[font]);
|
|
285
|
+
styleSample(span, ppem);
|
|
286
|
+
return span;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function title(parts) {
|
|
290
|
+
var instance = DATA.instances[Number(instanceSelect.value)];
|
|
291
|
+
return [font, TITLE, instance ? instance.name : null]
|
|
292
|
+
.concat(parts)
|
|
293
|
+
.filter(Boolean)
|
|
294
|
+
.join(" ");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function renderWaterfall() {
|
|
298
|
+
setHidden(document.getElementById("waterfall"), !selectedGlyph);
|
|
299
|
+
if (!selectedGlyph) return;
|
|
300
|
+
document.getElementById("waterfall-title").textContent = title([
|
|
301
|
+
selectedGlyph.name,
|
|
302
|
+
WATERFALL_SIZES[0] + "–" + WATERFALL_SIZES[WATERFALL_SIZES.length - 1] + " ppem"
|
|
303
|
+
]);
|
|
304
|
+
setChildren(
|
|
305
|
+
document.getElementById("waterfall-samples"),
|
|
306
|
+
WATERFALL_SIZES.map(function (ppem) {
|
|
307
|
+
var cell = document.createElement("span");
|
|
308
|
+
var label = document.createElement("span");
|
|
309
|
+
label.className = "size-label";
|
|
310
|
+
label.textContent = String(ppem);
|
|
311
|
+
cell.appendChild(glyphSample(selectedGlyph, ppem));
|
|
312
|
+
cell.appendChild(label);
|
|
313
|
+
return cell;
|
|
314
|
+
})
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Wide enough for most glyphs, which are cut off rather than overlapping
|
|
319
|
+
function setGlyphCellSize(ppem) {
|
|
320
|
+
var width = Math.max(40, Math.ceil((ppem / pixelRatio()) * 1.25)) + "px";
|
|
321
|
+
glyphSizeStyle.textContent =
|
|
322
|
+
".glyph { width: " + width + "; }\n" +
|
|
323
|
+
"@supports (display: grid) {\n" +
|
|
324
|
+
" #glyphs { grid-template-columns: repeat(auto-fill, minmax(" + width + ", 1fr)); }\n" +
|
|
325
|
+
" .glyph { width: auto; }\n" +
|
|
326
|
+
"}";
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function glyphButton(glyph, ppem) {
|
|
330
|
+
var button = document.createElement("button");
|
|
331
|
+
button.type = "button";
|
|
332
|
+
button.className = "glyph";
|
|
333
|
+
button.title = glyph.name;
|
|
334
|
+
button.setAttribute("aria-label", glyph.name);
|
|
335
|
+
button.setAttribute("aria-pressed", String(glyph === selectedGlyph));
|
|
336
|
+
button.appendChild(glyphSample(glyph, ppem));
|
|
337
|
+
button.addEventListener("click", function () {
|
|
338
|
+
selectedGlyph = glyph === selectedGlyph ? null : glyph;
|
|
339
|
+
saveSettings();
|
|
340
|
+
renderGlyphs();
|
|
341
|
+
renderWaterfall();
|
|
342
|
+
});
|
|
343
|
+
return button;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function renderGlyphs() {
|
|
347
|
+
var ppem = Number(ppemSelect.value);
|
|
348
|
+
var filter = filterInput.value.replace(/^\s+|\s+$/g, "").toLowerCase();
|
|
349
|
+
document.getElementById("glyphs-title").textContent =
|
|
350
|
+
title([ppem + " ppem"]) + " (click a glyph for a waterfall, hover for its name)";
|
|
351
|
+
setGlyphCellSize(ppem);
|
|
352
|
+
setChildren(
|
|
353
|
+
glyphsDiv,
|
|
354
|
+
DATA.glyphs
|
|
355
|
+
.filter(function (glyph) {
|
|
356
|
+
return !filter || glyph.name.toLowerCase().indexOf(filter) >= 0;
|
|
357
|
+
})
|
|
358
|
+
.map(function (glyph) {
|
|
359
|
+
return glyphButton(glyph, ppem);
|
|
360
|
+
})
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function render() {
|
|
365
|
+
var ppem = Number(ppemSelect.value);
|
|
366
|
+
fontToggle.textContent = font;
|
|
367
|
+
document.getElementById("text-title").textContent = title([ppem + " ppem"]);
|
|
368
|
+
styleSample(textSample, ppem);
|
|
369
|
+
renderWaterfall();
|
|
370
|
+
renderGlyphs();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function change() {
|
|
374
|
+
saveSettings();
|
|
375
|
+
render();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function textChanged() {
|
|
379
|
+
if (textSample.textContent === (editedText === null ? DATA.sampleText : editedText)) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
editedText = textSample.textContent;
|
|
383
|
+
saveSettings();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
fontToggle.addEventListener("click", function () {
|
|
387
|
+
font = font === "old" ? "new" : "old";
|
|
388
|
+
change();
|
|
389
|
+
});
|
|
390
|
+
ppemSelect.addEventListener("change", change);
|
|
391
|
+
instanceSelect.addEventListener("change", render);
|
|
392
|
+
// Internet Explorer doesn't send "input" events for some changes, so "keyup" and
|
|
393
|
+
// "change" are listened to as well
|
|
394
|
+
function filterChanged() {
|
|
395
|
+
saveSettings();
|
|
396
|
+
renderGlyphs();
|
|
397
|
+
}
|
|
398
|
+
var lastFilter = filterInput.value;
|
|
399
|
+
["input", "keyup", "change"].forEach(function (type) {
|
|
400
|
+
filterInput.addEventListener(type, function () {
|
|
401
|
+
if (filterInput.value === lastFilter) return;
|
|
402
|
+
lastFilter = filterInput.value;
|
|
403
|
+
filterChanged();
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
// Internet Explorer doesn't send "input" events for editable elements
|
|
407
|
+
["input", "keyup", "blur", "paste", "cut"].forEach(function (type) {
|
|
408
|
+
textSample.addEventListener(type, function () {
|
|
409
|
+
// After a paste or cut has changed the text
|
|
410
|
+
setTimeout(textChanged, 0);
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
// The pixel ratio changes with the browser's zoom, which resizes the window
|
|
414
|
+
window.addEventListener("resize", render);
|
|
415
|
+
render();
|
|
416
|
+
</script>
|
|
417
|
+
</body>
|
|
418
|
+
</html>
|
hinting_diff/page.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Writes a page to compare the TrueType hinting of two versions of a font in a
|
|
3
|
+
browser.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import html
|
|
7
|
+
import json
|
|
8
|
+
import unicodedata
|
|
9
|
+
import urllib.parse
|
|
10
|
+
from importlib import resources
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from fontTools.ttLib import TTFont
|
|
14
|
+
from fontTools.ttLib.tables._c_m_a_p import CmapSubtable
|
|
15
|
+
|
|
16
|
+
# Each glyph is mapped to a codepoint from here, in Supplementary Private Use
|
|
17
|
+
# Area-A, so unencoded glyphs can be shown in a browser too
|
|
18
|
+
GLYPH_CODEPOINT_START = 0xF0000
|
|
19
|
+
_GLYPH_CODEPOINT_END = 0xFFFFD
|
|
20
|
+
|
|
21
|
+
# Characters left out of the sample text: combining marks, which would stack on
|
|
22
|
+
# the character before them, and characters that show nothing
|
|
23
|
+
_SAMPLE_SKIPPED_CATEGORIES = frozenset({"Mn", "Me", "Cc", "Cf", "Cs", "Zs", "Zl", "Zp"})
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def add_glyph_codepoints(font_path: Path, output_path: Path) -> dict[str, int]:
|
|
27
|
+
"""
|
|
28
|
+
Saves a copy of a font with a Private Use Area codepoint for each glyph, so
|
|
29
|
+
unencoded glyphs can be shown in a browser too. Only the cmap table changes, so
|
|
30
|
+
the hinting is kept. Returns the codepoint of each glyph.
|
|
31
|
+
"""
|
|
32
|
+
# Tables that aren't loaded are saved as they are, e.g. glyf, fpgm, prep and cvt.
|
|
33
|
+
# The glyph order is read from another copy, as reading it loads the post table,
|
|
34
|
+
# which would then be recompiled.
|
|
35
|
+
glyph_order_font = TTFont(font_path, lazy=True)
|
|
36
|
+
glyph_order = glyph_order_font.getGlyphOrder()
|
|
37
|
+
glyph_order_font.close()
|
|
38
|
+
font = TTFont(font_path, lazy=True)
|
|
39
|
+
font.setGlyphOrder(glyph_order)
|
|
40
|
+
if len(glyph_order) > _GLYPH_CODEPOINT_END - GLYPH_CODEPOINT_START:
|
|
41
|
+
raise ValueError(f"{font_path.name} has too many glyphs")
|
|
42
|
+
# Except .notdef: a character mapped to it isn't saved, and browsers show it in
|
|
43
|
+
# another font
|
|
44
|
+
codepoints = {
|
|
45
|
+
glyph_name: GLYPH_CODEPOINT_START + glyph_id
|
|
46
|
+
for glyph_id, glyph_name in enumerate(glyph_order)
|
|
47
|
+
if glyph_id != 0
|
|
48
|
+
}
|
|
49
|
+
cmap_table = font["cmap"]
|
|
50
|
+
# A (3, 10) subtable is needed for codepoints above U+FFFF. Windows prefers it
|
|
51
|
+
# to the (3, 1) subtable, so it needs the font's own mappings too.
|
|
52
|
+
subtable = cmap_table.getcmap(3, 10)
|
|
53
|
+
if subtable is None:
|
|
54
|
+
subtable = CmapSubtable.newSubtable(12)
|
|
55
|
+
subtable.platformID = 3
|
|
56
|
+
subtable.platEncID = 10
|
|
57
|
+
subtable.language = 0
|
|
58
|
+
subtable.cmap = dict(font.getBestCmap())
|
|
59
|
+
cmap_table.tables.append(subtable)
|
|
60
|
+
subtable.cmap.update({codepoint: name for name, codepoint in codepoints.items()})
|
|
61
|
+
font.save(output_path)
|
|
62
|
+
font.close()
|
|
63
|
+
return codepoints
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def get_sample_text(font: TTFont) -> str:
|
|
67
|
+
"""
|
|
68
|
+
Returns every character a font encodes, in codepoint order, for an overview of
|
|
69
|
+
its glyph set, without combining marks or characters that show nothing.
|
|
70
|
+
"""
|
|
71
|
+
return "".join(
|
|
72
|
+
char
|
|
73
|
+
for char in map(chr, sorted(font.getBestCmap()))
|
|
74
|
+
if unicodedata.category(char) not in _SAMPLE_SKIPPED_CATEGORIES
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def get_named_instances(font: TTFont) -> list[tuple[str, dict[str, float]]]:
|
|
79
|
+
"""
|
|
80
|
+
Returns a variable font's named instances as (name, coordinates). Instances
|
|
81
|
+
without a Windows English name are left out.
|
|
82
|
+
"""
|
|
83
|
+
if "fvar" not in font:
|
|
84
|
+
return []
|
|
85
|
+
instances: list[tuple[str, dict[str, float]]] = []
|
|
86
|
+
for instance in font["fvar"].instances:
|
|
87
|
+
name = font["name"].getName(instance.subfamilyNameID, 3, 1, 0x409)
|
|
88
|
+
if name is not None:
|
|
89
|
+
instances.append((name.toUnicode(), instance.coordinates))
|
|
90
|
+
return instances
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _css_url(filename: str) -> str:
|
|
94
|
+
"""
|
|
95
|
+
Returns a file's name for a CSS url() in a page's <style>, where HTML entities
|
|
96
|
+
aren't decoded, so it's URL-encoded instead (e.g. "#" would start a fragment).
|
|
97
|
+
"""
|
|
98
|
+
return urllib.parse.quote(filename)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _script_json(value: object) -> str:
|
|
102
|
+
# Escape "</" so the data can't close the script element
|
|
103
|
+
return json.dumps(value).replace("</", "<\\/")
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def write_hinting_page(
|
|
107
|
+
before_path: Path,
|
|
108
|
+
after_path: Path,
|
|
109
|
+
output_path: Path,
|
|
110
|
+
page_name: str | None = None,
|
|
111
|
+
) -> Path:
|
|
112
|
+
"""
|
|
113
|
+
Writes a page to inspect the TrueType hinting of two versions of a font on
|
|
114
|
+
Windows: every glyph, encoded or not, in both fonts at a chosen size in pixels
|
|
115
|
+
per em, and a waterfall of a glyph's sizes. The page and copies of the fonts are
|
|
116
|
+
saved in `output_path`, and the page is named `page_name` (by default, the new
|
|
117
|
+
font's name with "-hinting.html"). Returns the page's path.
|
|
118
|
+
"""
|
|
119
|
+
output_path.mkdir(parents=True, exist_ok=True)
|
|
120
|
+
page_path = output_path.joinpath(page_name or f"{after_path.stem}-hinting.html")
|
|
121
|
+
before_font_name = f"hinting-old-{after_path.name}"
|
|
122
|
+
after_font_name = f"hinting-new-{after_path.name}"
|
|
123
|
+
before_codepoints = add_glyph_codepoints(
|
|
124
|
+
before_path, output_path.joinpath(before_font_name)
|
|
125
|
+
)
|
|
126
|
+
after_codepoints = add_glyph_codepoints(
|
|
127
|
+
after_path, output_path.joinpath(after_font_name)
|
|
128
|
+
)
|
|
129
|
+
# The new font's glyph order, then glyphs that were removed
|
|
130
|
+
glyphs = [
|
|
131
|
+
{"name": name, "old": before_codepoints.get(name), "new": codepoint}
|
|
132
|
+
for name, codepoint in after_codepoints.items()
|
|
133
|
+
] + [
|
|
134
|
+
{"name": name, "old": codepoint, "new": None}
|
|
135
|
+
for name, codepoint in before_codepoints.items()
|
|
136
|
+
if name not in after_codepoints
|
|
137
|
+
]
|
|
138
|
+
after_font = TTFont(after_path, lazy=True)
|
|
139
|
+
instances = [
|
|
140
|
+
{"name": name, "coords": coords}
|
|
141
|
+
for name, coords in get_named_instances(after_font)
|
|
142
|
+
]
|
|
143
|
+
sample_text = get_sample_text(after_font)
|
|
144
|
+
after_font.close()
|
|
145
|
+
data = {"glyphs": glyphs, "instances": instances, "sampleText": sample_text}
|
|
146
|
+
template = resources.files("hinting_diff").joinpath("page.html").read_text("utf-8")
|
|
147
|
+
page_path.write_text(
|
|
148
|
+
template.replace("{{title}}", html.escape(after_path.name))
|
|
149
|
+
.replace("{{title_json}}", _script_json(after_path.stem))
|
|
150
|
+
.replace("{{before_font}}", _css_url(before_font_name))
|
|
151
|
+
.replace("{{after_font}}", _css_url(after_font_name))
|
|
152
|
+
.replace("{{hinting_json}}", _script_json(data)),
|
|
153
|
+
encoding="utf-8",
|
|
154
|
+
)
|
|
155
|
+
return page_path
|
hinting_diff/py.typed
ADDED
|
File without changes
|
|
@@ -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
|
+
[](https://pypi.org/project/hinting-diff/)
|
|
33
|
+
[](https://pypi.org/project/hinting-diff/)
|
|
34
|
+
[](https://github.com/klim-type-foundry/hinting-diff/actions/workflows/check.yml)
|
|
35
|
+
[](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
|
+

|
|
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,11 @@
|
|
|
1
|
+
hinting_diff/__init__.py,sha256=SL_qteNqJq3XMMs_QMEPCTFsFIkoNiOzQ8FqRnq4nro,623
|
|
2
|
+
hinting_diff/cli.py,sha256=WIIqM_WT5p-CSY0-toRyEJwHDGoZc36rfa9dkFc7O0U,1403
|
|
3
|
+
hinting_diff/page.html,sha256=hMMS-joo0e0awj1JMb9aE6nxdREZ1YVrzGV4sAZ02Ns,14586
|
|
4
|
+
hinting_diff/page.py,sha256=TXl5f4xNJa06X5rSaFDZAC-xXlGDXFoCmycKdd-iStQ,6090
|
|
5
|
+
hinting_diff/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
hinting_diff-0.1.1.dist-info/licenses/LICENSE.txt,sha256=yVuuHRzgI17MzTVgt3LsHvuX80innw--CmNPDCzO_iw,11358
|
|
7
|
+
hinting_diff-0.1.1.dist-info/METADATA,sha256=egkVCR_-iun742L-GzkOBRntz7ofiVauBAmoj4ASCgs,8787
|
|
8
|
+
hinting_diff-0.1.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
+
hinting_diff-0.1.1.dist-info/entry_points.txt,sha256=794P8DMXHh-M0FOt5r38G25Z_GrQKnFeCahmrz6O550,55
|
|
10
|
+
hinting_diff-0.1.1.dist-info/top_level.txt,sha256=9qYQ_zX0GPtsjNWN5D3vW_DQFQPR0j1sxZA3CV7ms8A,13
|
|
11
|
+
hinting_diff-0.1.1.dist-info/RECORD,,
|
|
@@ -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 @@
|
|
|
1
|
+
hinting_diff
|