ufo-tdkit-tools 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.
- ufo_tdkit_tools-0.2.0/.gitignore +8 -0
- ufo_tdkit_tools-0.2.0/CHANGELOG.md +57 -0
- ufo_tdkit_tools-0.2.0/LICENSE +190 -0
- ufo_tdkit_tools-0.2.0/Makefile +155 -0
- ufo_tdkit_tools-0.2.0/PKG-INFO +154 -0
- ufo_tdkit_tools-0.2.0/README.md +109 -0
- ufo_tdkit_tools-0.2.0/docs/API.md +613 -0
- ufo_tdkit_tools-0.2.0/pyproject.toml +84 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/__init__.py +48 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/__main__.py +13 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/cli.py +245 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/compilation/__init__.py +54 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/compilation/compiler.py +604 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/compilation/legacy_kern.py +267 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/compilation/preserve.py +253 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/constants.py +80 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/extraction/__init__.py +24 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/extraction/cff_hints.py +468 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/extraction/converter.py +774 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/extraction/warnings.py +27 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/pipeline.py +392 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/ps_hints/OPTIMIZER_ALGORITHM.md +576 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/ps_hints/__init__.py +47 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/ps_hints/analyzer.py +220 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/ps_hints/batch.py +212 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/ps_hints/converter.py +319 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/ps_hints/optimizer.py +1479 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/ps_hints/parser.py +591 -0
- ufo_tdkit_tools-0.2.0/src/ufo_tdkit_tools/ps_hints/validator.py +210 -0
- ufo_tdkit_tools-0.2.0/tests/__init__.py +0 -0
- ufo_tdkit_tools-0.2.0/tests/test_batch.py +194 -0
- ufo_tdkit_tools-0.2.0/tests/test_cff_hints.py +184 -0
- ufo_tdkit_tools-0.2.0/tests/test_cli.py +132 -0
- ufo_tdkit_tools-0.2.0/tests/test_compilation.py +102 -0
- ufo_tdkit_tools-0.2.0/tests/test_constants.py +118 -0
- ufo_tdkit_tools-0.2.0/tests/test_extraction_features.py +325 -0
- ufo_tdkit_tools-0.2.0/tests/test_legacy_kern.py +228 -0
- ufo_tdkit_tools-0.2.0/tests/test_os2_selection.py +118 -0
- ufo_tdkit_tools-0.2.0/tests/test_parser.py +127 -0
- ufo_tdkit_tools-0.2.0/tests/test_pipeline.py +191 -0
- ufo_tdkit_tools-0.2.0/tests/test_pipeline_e2e.py +554 -0
- ufo_tdkit_tools-0.2.0/tests/test_public_api.py +123 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.2.0] - 2026-09-22
|
|
10
|
+
|
|
11
|
+
First release published on PyPI.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- **Preserve mode dropped the hints of every production-renamed glyph** ([#1](https://github.com/typedev/ufo-tdkit-tools/issues/1)). The per-glyph charstring merge matches by glyph name, but the two halves of the compile used different name sets: the ufo2ft shell was built with production names (`uni0100`) while the `tx -t1` + `makeotf` donor ignores `public.postscriptNames` and keeps source names (`Amacron`). Every renamed glyph failed the `glyph_name not in hinted_cs` test and was silently skipped — on DIN 2014 that is 488 of 829 glyphs per face, shipping OTFs with 32.5 % of glyphs hinted against 99.3 % for the same sources built with the external autohinter. The shell is now compiled with `useProductionNames=False` so both sides share the UFO's source namespace, and renaming is deferred to after the merge, delegated to ufo2ft's own `PostProcessor` (same code path a plain `compileOTF` runs: lib mapping, `uniXXXX` derivation, collision suffixes, invalid-character stripping) which also performs the `cffsubr` subroutinization. New e2e regression test `test_production_renamed_glyphs_keep_hints`.
|
|
16
|
+
- **Merged charstrings reported a bogus advance width in the CFF.** A Type 2 charstring may open with a width operand encoded as `width - Private.nominalWidthX`, and the merge copies charstrings between two fonts with unrelated Private dicts (here: shell `nominalWidthX=500 / defaultWidthX=600`, donor `0 / 0`). Every transferred glyph therefore decoded to a wrong CFF width — `tx -dump -6` reported `1100 width` for a 600-unit glyph — while `hmtx` stayed correct, so layout engines were unaffected but CFF-level consumers (`tx`, subsetters, CFF→CFF2 conversion) were not. The new `_split_width_prefix` helper strips the donor's width prefix and splices the shell's own onto the donor's body. This defect was previously masked by the name bug (it only affected the third of glyphs that were merged at all). New e2e regression test `test_transferred_charstrings_keep_their_width`.
|
|
17
|
+
- **The autohint gate was per font, not per glyph** ([#1](https://github.com/typedev/ufo-tdkit-tools/issues/1), second defect). `detect_font_source` returns a source as soon as **one** glyph has hints, and the pipeline only called the autohinter when the whole font came up empty. A partially hinted master — the normal shape of a FontLab source, where hints are authored on base forms and not on composites — was therefore treated as fully hinted, and every unhinted glyph went into the OTF unhinted (`source=public_ps glyphs=829 with_hints=408 autohinted=False`). `process_font` gained an `autohint` argument: `"fill"` (new default) autohints exactly the drawable glyphs the chosen source does not cover and keeps the authored hints of the rest; `"all"` discards authored hints and re-hints everything; `"off"` restores the old leave-it-alone behaviour and turns "no hints anywhere" into a failure instead of silently hinting the whole font. The autohinter runs with `glyphList` restricted to the gap glyphs and `explicitGlyphs` set, so its own `maxSegments` heuristic cannot skip complex glyphs.
|
|
18
|
+
- **Silent hint loss now surfaces in the log.** The merge warns when the shell and donor name sets disagree on more than 5 % of glyphs (with a sample of the unmatched names), and when hinted donor glyphs have no shell counterpart. `stats` gained `donor_hinted` and `name_mismatch` alongside `hints_transferred` / `total_glyphs`.
|
|
19
|
+
- **Preserve mode could fail to compile UFOs with features (platform-dependent).** `_compile_makeotf_hinted` passed the UFO's `features.fea` to the donor compile via `-ff`; on some platforms `makeotfexe` aborts with `std::system_error` whenever `-ff` is present — even for an empty file (reproduced deterministically on Fedora 44 / AFDKO 4.0.3, and reported intermittently under parallel load on AFDKO 5.0.0; not reproduced on 5.0.0 here across ~250 serial and oversubscribed-parallel invocations). When the abort fires, `_compile_makeotf_hinted` returns `False`, so `compile_otf_preserve_optimized` returns `False` and `process_font` reports `success=False` / `"OTF compilation failed"` — a hard failure, not a silent unhinted output. (A caller that catches that `False` and falls back to a plain ufo2ft compile is what turns it into silently unhinted output downstream.) The donor font exists only as a source of hinted charstrings and PrivateDict hint parameters — its GSUB/GPOS are discarded by the per-glyph merge — so the donor is now compiled with **no features file at all** (wrapper auto-discovery is moot: the tx-emitted `.ps` sits alone in a temp directory). Output features are unaffected: they come from the ufo2ft shell. Removing `-ff` also skips donor feature compilation that the merge discards anyway (~4% of the makeotf step on a 600-glyph / 42 KB feature file here). New e2e regression test compiles a hinted UFO **with** features and asserts the hints actually reach the output CFF (`test_hints_survive_with_features_present`).
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **Legacy `kern` table synthesis** (`compilation.legacy_kern`, also re-exported as `ufo_tdkit_tools.add_legacy_kern`). Microsoft Word and other Office rendering paths read kerning from the old-style `kern` table rather than from GPOS, so fonts built by ufo2ft/fontmake lose kerning there. `add_legacy_kern(ttf)` flattens the font's GPOS `kern` feature into a format-0 `kern` table and rewrites the binary so that only `kern` changes (GPOS is flattened on a throwaway lazy `TTFont`; every other table is written back verbatim and `head.modified` is preserved — `head.checkSumAdjustment` is the one unavoidable side effect). Pairs resolve first-wins in feature order, values are clamped to int16, and the table splits across several subtables past the uint16 `nPairs` limit. Contextual lookups inside the `kern` feature (kerning exceptions) have no format-0 equivalent and are skipped with a log line instead of being mistaken for pair positioning — reading them as `PairPos` used to raise `AttributeError: PairSet` and abort the whole flatten. Depends only on fontTools, so it works without the `compilation` extra.
|
|
24
|
+
- **`ProcessResult` build counters.** `autohinted_count` (glyphs the autohinter filled in), plus `otf_glyphs_hinted` / `otf_glyphs_total` taken from the compiler's `stats` — what actually reached the binary, which is what a build-level regression guard should assert on. The CLI prints them per file (`... -> otf 823/829`).
|
|
25
|
+
- **`--autohint {fill,all,off}` CLI flag** on `optimize-otf`, forwarded to `process_font`.
|
|
26
|
+
- **`ps_hints.batch.glyphs_missing_source(font, source)`** — names of drawable glyphs (contours or components) with no hints in a source; `export_all_from_processed` gained an optional `names` filter.
|
|
27
|
+
- **Multi-entry `hintSetList` extraction.** `cff_hints.py` now parses CFF charstrings via `afdko.otfautohint.otfFont.convertT2ToGlyphData` and emits one `autohint.v2` hint set per `hintmask` event in the source, anchored on the canonical UFO point per AFDKO's `addUfoHints` algorithm. Hint substitution is preserved through OTF → UFO → OTF on glyphs whose substitution points lie inside contours.
|
|
28
|
+
- **Counter-mask preservation.** `cntrmask` operators round-trip via `hstem3` / `vstem3` triplets in the `stems` array, mirroring AFDKO's `addUfoMask` triplet encoding.
|
|
29
|
+
- **`StdHW` / `StdVW` round-trip.** UFO has no dedicated field for these scalars, so extraction reorders `postscriptStemSnapH` / `postscriptStemSnapV` to put the CFF `StdHW` / `StdVW` value at index 0; ufo2ft picks `StdHW = StemSnapH[0]` at compile time.
|
|
30
|
+
- **FEA post-processing.** `_unify_feature_blocks` collapses `fontFeatures.unparse` output (one block per `(feature, script, language)` tuple) into one block per tag with internal `script` / `language` scoping. `_inline_aalt_lookups` rewrites `lookup NAME;` references inside `aalt` to inline `sub` statements (the Adobe FEA spec rejects lookup references in `aalt`; `addfeatures` errors out otherwise). `_strip_lookup_noise` and `_strip_empty_gdef` clean up artefacts. On a representative font this reduces feature-block count from 116 to one per tag.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- **`process_font` autohints by default** (`autohint="fill"`). Previously the autohinter only ran when the font had no hints at all; now it also fills per-glyph gaps. Callers that want the old behaviour pass `autohint="off"` — with the caveat that "no hints anywhere" then fails instead of falling back to the autohinter.
|
|
35
|
+
- **`_resolve_source` returns `None` for a binary input whose extraction yielded no hints** (it used to return `AUTOHINT_V2` unconditionally); the pipeline treats that as "the autohinter supplies everything", which is what it did before by a separate branch.
|
|
36
|
+
- **Compilation now uses the `makeotf` wrapper** instead of the deprecated `makeotfexe` binary, which is a stub on AFDKO releases scheduling its removal after March 2027 (returns exit 1 with a deprecation message and produces no output). `_compile_makeotf_hinted` resolves and subprocess-runs `makeotf`, sets `PATH` so the wrapper finds its own `tx` / `addfeatures` / `spot`, and asserts the output file exists after a returncode-0 to guard against future stub regressions.
|
|
37
|
+
- **`afdko` is capped at `<6`** in the `extraction` and `compilation` extras. AFDKO 6 drops the bare `tx` / `makeotf` command wrappers in favour of `afdko tx` / `afdko makeotf`, which the compiler does not call yet.
|
|
38
|
+
- **Packaging**: `__version__` is read from the installed package metadata (`pyproject.toml` is the single source), the license is declared as an SPDX expression, and Python 3.13 is listed and tested in CI.
|
|
39
|
+
- **API rename**: `makeotfexe_path` → `makeotf_path` on `compile_otf_preserve`, `compile_otf_preserve_optimized`, `preserve_compile`, `preserve_compile_batch`. Auto-detection now resolves `makeotf` via `shutil.which`.
|
|
40
|
+
|
|
41
|
+
### Removed
|
|
42
|
+
|
|
43
|
+
- **`compilation.generate_goadb` and `compilation.prepare_processedglyphs`** (and their private helpers). Neither was called anywhere: the per-glyph merge matches by name, so the donor glyph order no longer needs a GlyphOrderAndAliasDB, and the compiler reads hints from default-layer `autohint.v2` only — a processedglyphs layer built for `tx` would carry decomposed outlines whose hint point references no longer match.
|
|
44
|
+
- The in-house `HintExtractingDecompiler` (subclass of `SimpleT2Decompiler`) is replaced by `convertT2ToGlyphData` from `afdko.otfautohint`, which already parses stems, `startmasks`, per-pathElement masks, and counter masks correctly.
|
|
45
|
+
|
|
46
|
+
## [0.1.0] - 2026-04-03
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- Initial release: extracted from ufo-widgets-gtk4 and TDKit
|
|
51
|
+
- `constants` module: shared PS hint constants and outline hash computation
|
|
52
|
+
- `extraction` module: binary font (OTF/TTF/WOFF/WOFF2) to UFO conversion with CFF hint extraction and feature cleanup
|
|
53
|
+
- `ps_hints` module: PS hint parsing, optimization, layer conversion, and structural validation
|
|
54
|
+
- `compilation` module: UFO to OTF compilation with PS hint preservation (preserve-optimized mode)
|
|
55
|
+
|
|
56
|
+
[Unreleased]: https://github.com/typedev/ufo-tdkit-tools/compare/v0.2.0...HEAD
|
|
57
|
+
[0.2.0]: https://github.com/typedev/ufo-tdkit-tools/releases/tag/v0.2.0
|
|
@@ -0,0 +1,190 @@
|
|
|
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 Support. 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
|
+
Copyright 2024 TypeDev
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Release plumbing for ufo-tdkit-tools.
|
|
2
|
+
#
|
|
3
|
+
# `make publish` is the only irreversible target in here, and PyPI is unusually
|
|
4
|
+
# unforgiving about it: a version number can be yanked but never re-uploaded, so a
|
|
5
|
+
# wrong artefact is permanent under that number. Everything before the upload is
|
|
6
|
+
# therefore a gate, and each one exists because it is cheap here and expensive after.
|
|
7
|
+
#
|
|
8
|
+
# Credentials are never stored in this file, and never asked for until the moment they
|
|
9
|
+
# are used: UV_PUBLISH_TOKEN if set, else ~/.pypirc, else a hidden prompt. Better still,
|
|
10
|
+
# publish from CI with Trusted Publishing and keep no token anywhere -- see the bottom.
|
|
11
|
+
|
|
12
|
+
# bash, not /bin/sh -- and not incidentally: the hidden token prompt below uses
|
|
13
|
+
# `read -rs -p`, and dash (which /bin/sh is on Debian and Ubuntu) supports neither -s
|
|
14
|
+
# nor -p. Under dash the read silently yields an empty string, so the prompt would look
|
|
15
|
+
# like it worked and then abort. Removing this line breaks `make publish` on the systems
|
|
16
|
+
# most likely to run it.
|
|
17
|
+
SHELL := bash
|
|
18
|
+
.SHELLFLAGS := -eu -o pipefail -c
|
|
19
|
+
|
|
20
|
+
NAME := ufo-tdkit-tools
|
|
21
|
+
VERSION := $(shell sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml | head -1)
|
|
22
|
+
TAG := v$(VERSION)
|
|
23
|
+
|
|
24
|
+
.DEFAULT_GOAL := help
|
|
25
|
+
.PHONY: help test lint check build verify clean guard-clean guard-tag guard-unpublished publish-test publish release-checklist
|
|
26
|
+
|
|
27
|
+
help: ## Show this list
|
|
28
|
+
@grep -hE '^[a-z][a-zA-Z0-9_-]*:.*?## ' $(MAKEFILE_LIST) \
|
|
29
|
+
| awk -F':.*?## ' '{printf " \033[1m%-20s\033[0m %s\n", $$1, $$2}'
|
|
30
|
+
@echo
|
|
31
|
+
@echo " $(NAME) $(VERSION) (tag $(TAG))"
|
|
32
|
+
|
|
33
|
+
test: ## Run the full suite
|
|
34
|
+
uv run pytest -q
|
|
35
|
+
|
|
36
|
+
lint: ## Ruff
|
|
37
|
+
uv run ruff check src/ tests/
|
|
38
|
+
|
|
39
|
+
check: test lint ## Suite + lint
|
|
40
|
+
|
|
41
|
+
clean: ## Remove built artefacts
|
|
42
|
+
rm -rf dist build *.egg-info
|
|
43
|
+
|
|
44
|
+
build: clean ## Build the sdist and the wheel from a clean dist/
|
|
45
|
+
uv build
|
|
46
|
+
@ls -1 dist/
|
|
47
|
+
|
|
48
|
+
# --- gates -------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
guard-clean: ## Fail unless the working tree is clean and matches origin/main
|
|
51
|
+
@test -z "$$(git status --porcelain)" \
|
|
52
|
+
|| { echo "error: working tree is dirty; publishing it would ship something no commit records"; exit 1; }
|
|
53
|
+
@test "$$(git rev-parse --abbrev-ref HEAD)" = "main" \
|
|
54
|
+
|| { echo "error: not on main (on $$(git rev-parse --abbrev-ref HEAD))"; exit 1; }
|
|
55
|
+
@git fetch --quiet origin main
|
|
56
|
+
@test "$$(git rev-parse HEAD)" = "$$(git rev-parse origin/main)" \
|
|
57
|
+
|| { echo "error: HEAD and origin/main differ; push or pull first"; exit 1; }
|
|
58
|
+
|
|
59
|
+
guard-tag: ## Fail unless tag v<version> exists and points at HEAD
|
|
60
|
+
@git rev-parse -q --verify "refs/tags/$(TAG)" >/dev/null \
|
|
61
|
+
|| { echo "error: tag $(TAG) does not exist. Cut the release first (make release-checklist), then publish."; exit 1; }
|
|
62
|
+
@test "$$(git rev-parse "$(TAG)^{commit}")" = "$$(git rev-parse HEAD)" \
|
|
63
|
+
|| { echo "error: $(TAG) does not point at HEAD -- you would publish code the tag does not describe"; exit 1; }
|
|
64
|
+
|
|
65
|
+
guard-unpublished: ## Fail if this version is already on PyPI
|
|
66
|
+
@code=$$(curl -sS -o /dev/null -w '%{http_code}' "https://pypi.org/pypi/$(NAME)/$(VERSION)/json" || echo 000); \
|
|
67
|
+
if [ "$$code" = "200" ]; then \
|
|
68
|
+
echo "error: $(NAME) $(VERSION) is already on PyPI. A version can be yanked but never re-uploaded -- bump the version."; exit 1; \
|
|
69
|
+
elif [ "$$code" != "404" ]; then \
|
|
70
|
+
echo "error: could not reach PyPI to check (HTTP $$code); refusing to guess"; exit 1; \
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
verify: build ## Check the metadata renders, and that the built wheel actually runs
|
|
74
|
+
uvx twine check --strict dist/*
|
|
75
|
+
@tmp=$$(mktemp -d); \
|
|
76
|
+
uv venv --quiet "$$tmp/venv"; \
|
|
77
|
+
VIRTUAL_ENV="$$tmp/venv" uv pip install --quiet dist/*.whl; \
|
|
78
|
+
got=$$("$$tmp/venv/bin/ufo-tdkit-tools" --version); \
|
|
79
|
+
bare=$$("$$tmp/venv/bin/python" -c "import ufo_tdkit_tools.compilation, ufo_tdkit_tools.ps_hints; print('ok')" 2>&1); \
|
|
80
|
+
rm -rf "$$tmp"; \
|
|
81
|
+
test "$$got" = "ufo-tdkit-tools $(VERSION)" \
|
|
82
|
+
|| { echo "error: installed wheel reports '$$got', expected 'ufo-tdkit-tools $(VERSION)'"; exit 1; }; \
|
|
83
|
+
test "$$bare" = "ok" \
|
|
84
|
+
|| { echo "error: bare install (no extras) cannot import the package: $$bare"; exit 1; }
|
|
85
|
+
@echo "ok: wheel installs clean, the entry point runs, and a bare install imports"
|
|
86
|
+
|
|
87
|
+
# --- publishing --------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
# How the token reaches `uv publish`, in order of preference:
|
|
90
|
+
# 1. UV_PUBLISH_TOKEN already in the environment (CI);
|
|
91
|
+
# 2. ~/.pypirc, which uv reads by itself;
|
|
92
|
+
# 3. a hidden prompt, right before the upload and nowhere else.
|
|
93
|
+
#
|
|
94
|
+
# The prompt is the default for a person at a terminal, because the alternatives leak:
|
|
95
|
+
# `export` puts the token in the shell history and then in the environment of every
|
|
96
|
+
# later command, and `--token` on a command line is visible in `ps` to anyone on the
|
|
97
|
+
# box. Passing it as a per-command environment variable is neither. It is read with
|
|
98
|
+
# `read -rs`, so a paste shows nothing at all .
|
|
99
|
+
define upload
|
|
100
|
+
@if [ -n "$${UV_PUBLISH_TOKEN:-}" ] || [ -f "$$HOME/.pypirc" ]; then \
|
|
101
|
+
uv publish $(1) dist/*; \
|
|
102
|
+
else \
|
|
103
|
+
if [ ! -t 0 ]; then \
|
|
104
|
+
echo "error: no UV_PUBLISH_TOKEN, no ~/.pypirc, and no terminal to ask on."; \
|
|
105
|
+
echo " In CI, set UV_PUBLISH_TOKEN -- or better, use Trusted Publishing (see below)."; \
|
|
106
|
+
exit 1; \
|
|
107
|
+
fi; \
|
|
108
|
+
read -rs -p " API token (input is hidden -- paste and press Enter): " token; echo; \
|
|
109
|
+
test -n "$$token" || { echo " aborted: empty token"; exit 1; }; \
|
|
110
|
+
case "$$token" in pypi-*) ;; *) echo " note: that does not start with 'pypi-'; tokens do. Continuing anyway." ;; esac; \
|
|
111
|
+
UV_PUBLISH_TOKEN="$$token" uv publish $(1) dist/*; \
|
|
112
|
+
fi
|
|
113
|
+
endef
|
|
114
|
+
|
|
115
|
+
publish-test: verify ## Upload to TestPyPI (safe rehearsal; asks for a TestPyPI token)
|
|
116
|
+
$(call upload,--publish-url https://test.pypi.org/legacy/)
|
|
117
|
+
@echo
|
|
118
|
+
@echo "Installed check:"
|
|
119
|
+
@echo " uv tool install --index-url https://test.pypi.org/simple/ \\"
|
|
120
|
+
@echo " --extra-index-url https://pypi.org/simple/ $(NAME)==$(VERSION)"
|
|
121
|
+
|
|
122
|
+
publish: guard-clean guard-tag guard-unpublished check verify ## Upload to PyPI (IRREVERSIBLE)
|
|
123
|
+
@echo
|
|
124
|
+
@echo " About to publish $(NAME) $(VERSION) to PyPI from $(TAG)."
|
|
125
|
+
@echo " This cannot be undone: the version can be yanked, never replaced."
|
|
126
|
+
@echo
|
|
127
|
+
@if [ "$${CONFIRM:-}" != "yes" ]; then \
|
|
128
|
+
read -r -p " Type the version to confirm: " answer; \
|
|
129
|
+
test "$$answer" = "$(VERSION)" || { echo " aborted"; exit 1; }; \
|
|
130
|
+
fi
|
|
131
|
+
$(call upload,)
|
|
132
|
+
@echo
|
|
133
|
+
@echo "Published. Remaining steps that PyPI does not do for you:"
|
|
134
|
+
@echo " - gh release create $(TAG) ... (its publish.yml run will fail on the existing version; expected)"
|
|
135
|
+
@echo " - tell TDKit the new version range"
|
|
136
|
+
|
|
137
|
+
release-checklist: ## Print the order of operations, without doing anything
|
|
138
|
+
@echo " 1. move [Unreleased] into [X.Y.Z] - <today> in CHANGELOG.md, add the compare link"
|
|
139
|
+
@echo " 2. bump version in pyproject.toml, then: uv lock"
|
|
140
|
+
@echo " 3. make check verify"
|
|
141
|
+
@echo " 4. git commit -am 'chore(release): X.Y.Z' && git tag -a vX.Y.Z -m vX.Y.Z"
|
|
142
|
+
@echo " 5. git push origin main --follow-tags"
|
|
143
|
+
@echo " 6. make publish-test # optional rehearsal on TestPyPI"
|
|
144
|
+
@echo " 7. gh release create vX.Y.Z --title vX.Y.Z --notes-file <CHANGELOG section> --verify-tag --latest"
|
|
145
|
+
@echo " -> publishing the Release runs .github/workflows/publish.yml, which uploads to PyPI"
|
|
146
|
+
@echo " 8. tell TDKit the new version range"
|
|
147
|
+
@echo
|
|
148
|
+
@echo " 'make publish' is the manual fallback for step 7's upload only; if you use it,"
|
|
149
|
+
@echo " the later Release will re-run publish.yml, which then fails on the existing version."
|
|
150
|
+
|
|
151
|
+
# Trusted Publishing (the default path, see .github/workflows/publish.yml)
|
|
152
|
+
# ------------------------------------------------------------------------------------
|
|
153
|
+
# One-time setup: https://pypi.org/manage/account/publishing/ -> add a pending publisher
|
|
154
|
+
# (project ufo-tdkit-tools, owner typedev, repo ufo-tdkit-tools, workflow publish.yml,
|
|
155
|
+
# environment pypi), and create the `pypi` environment in the GitHub repo settings.
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ufo-tdkit-tools
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: PS hints extraction, optimization, and preserve-mode compilation for UFO fonts
|
|
5
|
+
Project-URL: Homepage, https://github.com/typedev/ufo-tdkit-tools
|
|
6
|
+
Project-URL: Repository, https://github.com/typedev/ufo-tdkit-tools
|
|
7
|
+
Project-URL: Issues, https://github.com/typedev/ufo-tdkit-tools/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/typedev/ufo-tdkit-tools/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Alexander Lubovenko <lubovenko@gmail.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: cff,compilation,font,hints,otf,postscript,ttf,typedev,typography,ufo
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Multimedia :: Graphics :: Editors :: Vector-Based
|
|
21
|
+
Classifier: Topic :: Text Processing :: Fonts
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: fonttools>=4.38.0
|
|
24
|
+
Provides-Extra: all
|
|
25
|
+
Requires-Dist: afdko<6,>=5.0.0; extra == 'all'
|
|
26
|
+
Requires-Dist: cffsubr; extra == 'all'
|
|
27
|
+
Requires-Dist: defcon; extra == 'all'
|
|
28
|
+
Requires-Dist: fontparts>=0.10.0; extra == 'all'
|
|
29
|
+
Requires-Dist: typing-extensions>=4.15.0; extra == 'all'
|
|
30
|
+
Requires-Dist: ufo-extractor>=0.8.1; extra == 'all'
|
|
31
|
+
Requires-Dist: ufo2ft>=3.0.0; extra == 'all'
|
|
32
|
+
Provides-Extra: compilation
|
|
33
|
+
Requires-Dist: afdko<6,>=5.0.0; extra == 'compilation'
|
|
34
|
+
Requires-Dist: cffsubr; extra == 'compilation'
|
|
35
|
+
Requires-Dist: defcon; extra == 'compilation'
|
|
36
|
+
Requires-Dist: fontparts>=0.10.0; extra == 'compilation'
|
|
37
|
+
Requires-Dist: ufo2ft>=3.0.0; extra == 'compilation'
|
|
38
|
+
Provides-Extra: extraction
|
|
39
|
+
Requires-Dist: afdko<6,>=5.0.0; extra == 'extraction'
|
|
40
|
+
Requires-Dist: defcon; extra == 'extraction'
|
|
41
|
+
Requires-Dist: fontparts>=0.10.0; extra == 'extraction'
|
|
42
|
+
Requires-Dist: typing-extensions>=4.15.0; extra == 'extraction'
|
|
43
|
+
Requires-Dist: ufo-extractor>=0.8.1; extra == 'extraction'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# ufo-tdkit-tools
|
|
47
|
+
|
|
48
|
+
[](https://pypi.org/project/ufo-tdkit-tools/)
|
|
49
|
+
[](https://github.com/typedev/ufo-tdkit-tools/actions/workflows/ci.yml)
|
|
50
|
+
|
|
51
|
+
PS hints extraction, optimization, and preserve-mode compilation for UFO fonts.
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
- **extraction** -- Convert binary fonts (OTF/TTF/WOFF/WOFF2) to UFO with full PS hint preservation (multi-entry `hintSetList`, counter triplets `hstem3`/`vstem3`, font-level Private dict including `StdHW`/`StdVW`) and FEA post-processing (one feature block per tag, inlined `aalt` for spec compliance).
|
|
56
|
+
- **ps_hints** -- Parse, optimize, analyze, and validate PostScript hints in UFO fonts; move hints between processedglyphs / glyph lib / default layers.
|
|
57
|
+
- **compilation** -- Compile UFO back to OTF preserving PS hints (via AFDKO `makeotf` + per-glyph charstring merge, then production glyph names + `cffsubr` subroutinization). Parallel batch via `ProcessPoolExecutor`.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install ufo-tdkit-tools # core (constants, ps_hints parser)
|
|
63
|
+
pip install ufo-tdkit-tools[extraction] # + binary font conversion
|
|
64
|
+
pip install ufo-tdkit-tools[compilation] # + OTF compilation with hints
|
|
65
|
+
pip install ufo-tdkit-tools[all] # everything
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The `extraction` and `compilation` extras pull in [AFDKO](https://github.com/adobe-type-tools/afdko) (`>=5,<6`), whose wheels ship the `tx` and `makeotf` executables the compiler runs — nothing needs to be installed separately.
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
71
|
+
|
|
72
|
+
The simplest path is the `process_font` pipeline — any input (binary or
|
|
73
|
+
UFO, hinted or not) becomes a hinted OTF + a clean UFO:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from ufo_tdkit_tools import process_font
|
|
77
|
+
|
|
78
|
+
result = process_font(
|
|
79
|
+
"input.otf", # OTF / TTF / WOFF / WOFF2 / UFO
|
|
80
|
+
"out.otf",
|
|
81
|
+
"out.ufo",
|
|
82
|
+
hint_source="auto", # priority: processed > v2 > public_ps
|
|
83
|
+
autohint="fill", # "fill" | "all" | "off"
|
|
84
|
+
optimize=False, # set True to run the ps_hints optimizer
|
|
85
|
+
)
|
|
86
|
+
assert result.success
|
|
87
|
+
print(result.glyphs_with_hints, "/", result.glyphs_total,
|
|
88
|
+
"autohinted=", result.autohinted_count,
|
|
89
|
+
"in otf=", result.otf_glyphs_hinted)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Glyphs the chosen source does not hint are autohinted individually with
|
|
93
|
+
`afdko.otfautohint` — a partially hinted master (base forms hinted,
|
|
94
|
+
composites not) comes out fully hinted, with the authored hints kept.
|
|
95
|
+
`autohint="all"` re-hints everything instead, `autohint="off"` leaves the
|
|
96
|
+
gaps alone.
|
|
97
|
+
|
|
98
|
+
For the lower-level entry points (`extraction.convert_binary_to_ufo`,
|
|
99
|
+
`compilation.compile_otf_preserve_optimized`, the `ps_hints` parser /
|
|
100
|
+
optimizer / validator / batch wrappers), see [`docs/API.md`](docs/API.md).
|
|
101
|
+
|
|
102
|
+
### Legacy `kern` table for Word
|
|
103
|
+
|
|
104
|
+
Modern build tools emit kerning only as GPOS, which Microsoft Word ignores.
|
|
105
|
+
`add_legacy_kern` regenerates the old-style `kern` table from the font's own
|
|
106
|
+
GPOS `kern` feature, rewriting the binary so that nothing but `kern` changes:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from ufo_tdkit_tools import add_legacy_kern
|
|
110
|
+
|
|
111
|
+
pairs = add_legacy_kern("Sans-Regular.ttf") # 0 if the font has no GPOS kerning
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
It needs only fontTools — no extras required.
|
|
115
|
+
|
|
116
|
+
## Command line
|
|
117
|
+
|
|
118
|
+
Installing the package (`uv sync` / `pip install`) provides the
|
|
119
|
+
`ufo-tdkit-tools` console script (also runnable as
|
|
120
|
+
`python -m ufo_tdkit_tools`). It wraps `process_font` for batch builds:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# Re-hint/optimize a batch of OTFs in place (temp UFO created & discarded)
|
|
124
|
+
ufo-tdkit-tools optimize-otf --in-place *.otf
|
|
125
|
+
|
|
126
|
+
# Or write fresh <stem>.otf + <stem>.ufo pairs into a directory
|
|
127
|
+
ufo-tdkit-tools optimize-otf -o build/ Sans-Regular.otf Sans-Bold.otf
|
|
128
|
+
|
|
129
|
+
# Skip the ps_hints optimizer (autohint + compile only)
|
|
130
|
+
ufo-tdkit-tools optimize-otf --in-place --no-optimize *.otf
|
|
131
|
+
|
|
132
|
+
# Keep only the authored hints, never call the autohinter
|
|
133
|
+
ufo-tdkit-tools optimize-otf -o build/ --autohint off Src.ufo
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Every run prints one machine-parseable summary line and exits non-zero if
|
|
137
|
+
any input failed — convenient inside a build log:
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
optimized=36 autohinted=0 failed=0
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`--in-place` only rewrites `.otf` inputs (atomically, so a mid-pipeline
|
|
144
|
+
failure never corrupts the source). UFO and other binary inputs use `-o DIR`.
|
|
145
|
+
|
|
146
|
+
## Round-trip fidelity
|
|
147
|
+
|
|
148
|
+
OTF → UFO → OTF preserves declared `hstem`/`vstem` positions and widths byte-for-byte, hint substitution between drawing operations, counter-mask grouping, and font-level Private dict scalars. The one structural exception is hint substitution that fires *between* subpaths (a `hintmask` immediately before a `moveto`, common on disconnected glyphs like `i`, `j`, dieresis-bearing letters): the `autohint.v2` format has no anchor for these and AFDKO's own autohint produces the same flattening.
|
|
149
|
+
|
|
150
|
+
Metadata (OS/2, `head`, `name`) also round-trips: `fsType`, weight/width class, vendor ID, Unicode/code-page ranges, PANOSE, typo/win/hhea metrics, sub/superscript and strikeout, `head.macStyle`/`head.flags`, and all name records. The `OS/2.fsSelection` flags `USE_TYPO_METRICS` (bit 7), `WWS` (bit 8) and `OBLIQUE` (bit 9) are restored during extraction — `ufo-extractor` (≤ 0.8.1) drops them, so they are re-read straight from the source `OS/2` table.
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
Apache-2.0
|