fontist 3.0.37 → 3.0.39
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.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +1 -0
- data/.github/workflows/tebako-pack.yml +43 -4
- data/Gemfile +4 -5
- data/README.adoc +52 -2
- data/fontist.gemspec +2 -1
- data/lib/fontist/cli.rb +20 -0
- data/lib/fontist/font_installer.rb +65 -52
- data/lib/fontist/font_operations/convert.rb +1 -3
- data/lib/fontist/font_operations/extract.rb +3 -3
- data/lib/fontist/font_operations/instance.rb +7 -3
- data/lib/fontist/font_operations/subset.rb +7 -11
- data/lib/fontist/format_matcher.rb +21 -9
- data/lib/fontist/format_spec.rb +28 -3
- data/lib/fontist/import/google/font_database.rb +1 -0
- data/lib/fontist/import/google/formula_builders/formula_builder_v4.rb +6 -1
- data/lib/fontist/import/google/formula_builders/formula_builder_v5.rb +12 -0
- data/lib/fontist/import/sil_importer.rb +1 -0
- data/lib/fontist/manifest.rb +42 -16
- data/lib/fontist/manifest_cli.rb +19 -1
- data/lib/fontist/scan_row_fonts.rb +82 -0
- data/lib/fontist/system_index.rb +63 -5
- data/lib/fontist/validator.rb +64 -33
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +1 -0
- data/packaging/nfpm.yaml +6 -1
- data/packaging/scripts/postinstall.sh +5 -0
- data/packaging/scripts/preremove.sh +12 -0
- data/script/tebako/git-prep.sh +25 -0
- data/script/tebako/package-smoke.sh +7 -2
- data/script/tebako/package.sh +3 -0
- data/script/tebako/smoke.sh +12 -1
- metadata +22 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e03c9358f15f7d26cf72315b563b764abe153d5c298829dcebdc8747718f2091
|
|
4
|
+
data.tar.gz: dd8324d23bf57a9be39f0e6f9d56c2ffac617ecf54547e8f2cc809b6a0c8a187
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ff07d8998d064496efb6802911f38d0ab579e4ddbaf30edb2ad5a57824db866ca9089b3f5962ef61d6ae77f7ee415730fcd9f26b5aa4813b7b2d85b8423525d
|
|
7
|
+
data.tar.gz: 1b1996c3d76481ac58f4ce7de3d1da760e3d148f4e5a077148fb7bf8160fd2f7e7a8aa820ba231ba75ebdb69be5a34ed668ad7beaff12d6bfb256ad6ef278e56
|
|
@@ -55,8 +55,11 @@ jobs:
|
|
|
55
55
|
- id: tag
|
|
56
56
|
env:
|
|
57
57
|
GH_TOKEN: ${{ github.token }}
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
# A called workflow sees the caller's event (release.yml runs on
|
|
59
|
+
# workflow_dispatch), so tell the triggers apart by their inputs:
|
|
60
|
+
# only workflow_call has `publish`, only workflow_dispatch has `tag`.
|
|
61
|
+
CALLED: ${{ inputs.publish == true }}
|
|
62
|
+
INPUT_TAG: ${{ inputs.tag || '' }}
|
|
60
63
|
run: |
|
|
61
64
|
if [ "$CALLED" = true ]; then
|
|
62
65
|
tag="v$(sed -n 's/.*VERSION = "\(.*\)".*/\1/p' lib/fontist/version.rb)"
|
|
@@ -183,7 +186,10 @@ jobs:
|
|
|
183
186
|
matrix:
|
|
184
187
|
# Distros whose git meets the git gem's >= 2.43; older ones refuse
|
|
185
188
|
# the package on its git dependency.
|
|
186
|
-
|
|
189
|
+
# ubuntu:22.04 ships an older git and first gets a newer one the
|
|
190
|
+
# documented way (git-prep.sh, see README.adoc). debian:12 has no leg:
|
|
191
|
+
# bookworm-backports carries no git package, so no >= 2.43 exists there.
|
|
192
|
+
image: [ 'ubuntu:24.04', 'debian:13', 'fedora:latest', 'rockylinux:9', 'ubuntu:22.04' ]
|
|
187
193
|
arch: [ amd64 ]
|
|
188
194
|
runner: [ ubuntu-24.04 ]
|
|
189
195
|
include:
|
|
@@ -207,13 +213,46 @@ jobs:
|
|
|
207
213
|
fi
|
|
208
214
|
ls -l pkg
|
|
209
215
|
|
|
216
|
+
- name: Get git 2.43 or newer
|
|
217
|
+
if: matrix.image == 'ubuntu:22.04'
|
|
218
|
+
run: script/tebako/git-prep.sh
|
|
219
|
+
|
|
210
220
|
- name: Install, use, remove
|
|
211
221
|
run: script/tebako/package-smoke.sh pkg
|
|
212
222
|
|
|
223
|
+
# Test-only: the packed executables again, on runners other than the ones
|
|
224
|
+
# that packed them. No macOS leg: macos-14 is not offered to this repo
|
|
225
|
+
# (run 42989415969: "The configuration 'macos-14-arm64-us-default' is not
|
|
226
|
+
# supported") and macos-13 is a label GitHub has retired; the macOS
|
|
227
|
+
# binaries are smoke-tested on their packing runners in `pack`.
|
|
228
|
+
binary-smoke:
|
|
229
|
+
name: run ${{ matrix.name }} on ${{ matrix.os }}
|
|
230
|
+
needs: pack
|
|
231
|
+
runs-on: ${{ matrix.os }}
|
|
232
|
+
strategy:
|
|
233
|
+
fail-fast: false
|
|
234
|
+
matrix:
|
|
235
|
+
include:
|
|
236
|
+
- { os: ubuntu-24.04, name: linux-x86_64 }
|
|
237
|
+
steps:
|
|
238
|
+
- uses: actions/checkout@v4
|
|
239
|
+
|
|
240
|
+
- uses: actions/download-artifact@v4
|
|
241
|
+
with:
|
|
242
|
+
name: fontist-${{ matrix.name }}
|
|
243
|
+
path: out
|
|
244
|
+
|
|
245
|
+
- name: Smoke test
|
|
246
|
+
run: |
|
|
247
|
+
chmod +x "out/fontist-${{ matrix.name }}"
|
|
248
|
+
git_dir="$(dirname "$(command -v git)")"
|
|
249
|
+
env -i HOME="$HOME" PATH="$git_dir:/usr/bin:/bin:/usr/sbin:/sbin" \
|
|
250
|
+
script/tebako/smoke.sh "out/fontist-${{ matrix.name }}"
|
|
251
|
+
|
|
213
252
|
publish:
|
|
214
253
|
name: attach to release
|
|
215
254
|
if: needs.resolve.outputs.tag != ''
|
|
216
|
-
needs: [ resolve, pack, package-smoke ]
|
|
255
|
+
needs: [ resolve, pack, package-smoke, binary-smoke ]
|
|
217
256
|
runs-on: ubuntu-24.04
|
|
218
257
|
permissions:
|
|
219
258
|
contents: write
|
data/Gemfile
CHANGED
|
@@ -18,11 +18,10 @@ gem "simplecov"
|
|
|
18
18
|
gem "vcr"
|
|
19
19
|
gem "webmock"
|
|
20
20
|
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
gem "yeptris", require: false
|
|
21
|
+
# yeptris is a runtime dependency (see the gemspec): the JSON backend in
|
|
22
|
+
# lib/fontist/json.rb loads it unconditionally. The optional YAML engine
|
|
23
|
+
# activated with FONTIST_YAML=yeptris stays off by default pending
|
|
24
|
+
# leptris/yeptris#863 (linux scalar-parity fix).
|
|
26
25
|
|
|
27
26
|
# Profiling tools (development only)
|
|
28
27
|
# gem "ruby-prof", "~> 1.7"
|
data/README.adoc
CHANGED
|
@@ -78,8 +78,16 @@ macOS is older, so install a current one first (for example
|
|
|
78
78
|
`brew install git`).
|
|
79
79
|
|
|
80
80
|
On Debian and Ubuntu, install the `.deb` package. On Fedora and RHEL, install
|
|
81
|
-
the `.rpm` package. Both
|
|
82
|
-
|
|
81
|
+
the `.rpm` package. Both install the executable to `/usr/lib/fontist/fontist` and link it from
|
|
82
|
+
`/usr/local/bin/fontist` (the link is removed with the package). They depend on
|
|
83
|
+
git 2.43 or newer, which Ubuntu 24.04, Debian 13, Fedora and RHEL 9 provide.
|
|
84
|
+
|
|
85
|
+
Ubuntu 22.04 ships an older git, so get a newer one once before installing the
|
|
86
|
+
`.deb`: `sudo add-apt-repository ppa:git-core/ppa && sudo apt-get update && sudo apt-get install git`.
|
|
87
|
+
Debian 12 has no git 2.43 or newer in its archive or in bookworm-backports, so
|
|
88
|
+
the package cannot be installed there.
|
|
89
|
+
|
|
90
|
+
`script/tebako/git-prep.sh` does exactly this and is what CI runs.
|
|
83
91
|
|
|
84
92
|
[source,sh]
|
|
85
93
|
----
|
|
@@ -363,6 +371,12 @@ Supported options:
|
|
|
363
371
|
`-u, [--update-fontconfig]`:: Update Fontconfig
|
|
364
372
|
`--collection-index=N`, `--format=FORMAT`, `--fallback-to-original`,
|
|
365
373
|
`--subset-unicodes=LIST`, `--subset-text=TEXT`:: See <<Font operations>>
|
|
374
|
+
`--static`:: Install static fonts instead of variable fonts (the default
|
|
375
|
+
when a formula offers both variants)
|
|
376
|
+
`--variable`:: Install variable fonts instead of static fonts
|
|
377
|
+
`--both`:: Install both the static and the variable variants in one call
|
|
378
|
+
`--variable-axes=LIST`, `--prefer-variable`, `--prefer-format=FORMAT`,
|
|
379
|
+
`--instance=AXES`:: See <<Variable-font instancing>>
|
|
366
380
|
|
|
367
381
|
|
|
368
382
|
NOTE: The `install` command is similar to the `Font.install` library call.
|
|
@@ -441,6 +455,42 @@ Fontist::Font.install("Lato", format: "woff2", subset_text: "Hello")
|
|
|
441
455
|
|
|
442
456
|
==== Variable-font instancing
|
|
443
457
|
|
|
458
|
+
===== Static vs variable fonts
|
|
459
|
+
|
|
460
|
+
Google Fonts formulas carry two sources: per-weight **static** files served
|
|
461
|
+
by the Google Fonts API, and the genuine **variable** files published in the
|
|
462
|
+
google/fonts repository. Every style records which resource its file lives
|
|
463
|
+
in (`source_resource`), and fontist downloads each requested style from its
|
|
464
|
+
own resource. By default fontist installs the static files; pass `--variable`
|
|
465
|
+
to install the variable files instead, `--both` to install both kinds, or
|
|
466
|
+
`--instance "wght=300"` to cut a static instance from a variable font at
|
|
467
|
+
specific axis values.
|
|
468
|
+
|
|
469
|
+
[source,sh]
|
|
470
|
+
----
|
|
471
|
+
fontist install "Work Sans Black" # static files
|
|
472
|
+
fontist install "Work Sans" --variable # variable files
|
|
473
|
+
fontist install "Work Sans" --both # both kinds
|
|
474
|
+
----
|
|
475
|
+
|
|
476
|
+
[source,ruby]
|
|
477
|
+
----
|
|
478
|
+
Fontist::Font.install("Work Sans Black", static: true)
|
|
479
|
+
Fontist::Font.install("Work Sans", variable: true)
|
|
480
|
+
Fontist::Font.install("Work Sans", both: true)
|
|
481
|
+
----
|
|
482
|
+
|
|
483
|
+
Manifests support the same choice per font (`variable: false` or
|
|
484
|
+
`all_variants: true` next to `styles:`) or for all fonts at once
|
|
485
|
+
(`fontist manifest install --static` / `--both`):
|
|
486
|
+
|
|
487
|
+
[source,yaml]
|
|
488
|
+
----
|
|
489
|
+
Work Sans Black:
|
|
490
|
+
styles: [Regular, Italic]
|
|
491
|
+
variable: false
|
|
492
|
+
----
|
|
493
|
+
|
|
444
494
|
`--instance` installs a static instance of a variable font at the given axis
|
|
445
495
|
values. Tags and ranges are checked against the font's `fvar` table; an
|
|
446
496
|
unknown axis, an out-of-range value or a non-variable font is an error.
|
data/fontist.gemspec
CHANGED
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
|
33
33
|
|
|
34
34
|
spec.add_dependency "down", "~> 5.0"
|
|
35
35
|
spec.add_dependency "excavate", "~> 1.0", ">= 1.0.3"
|
|
36
|
-
spec.add_dependency "fontisan", "~> 0.4", ">= 0.4.
|
|
36
|
+
spec.add_dependency "fontisan", "~> 0.4", ">= 0.4.48"
|
|
37
37
|
spec.add_dependency "fuzzy_match", "~> 2.1"
|
|
38
38
|
spec.add_dependency "git", "~> 6.0"
|
|
39
39
|
spec.add_dependency "lutaml-model", "~> 0.8.164"
|
|
@@ -46,4 +46,5 @@ Gem::Specification.new do |spec|
|
|
|
46
46
|
spec.add_dependency "socksify", "~> 1.7"
|
|
47
47
|
spec.add_dependency "thor", "~> 1.4"
|
|
48
48
|
spec.add_dependency "unibuf", "~> 0.1"
|
|
49
|
+
spec.add_dependency "yeptris", "~> 0.6.55"
|
|
49
50
|
end
|
data/lib/fontist/cli.rb
CHANGED
|
@@ -139,6 +139,12 @@ module Fontist
|
|
|
139
139
|
option :prefer_format,
|
|
140
140
|
type: :string,
|
|
141
141
|
desc: "Preferred format when multiple available"
|
|
142
|
+
option :static, type: :boolean,
|
|
143
|
+
desc: "Install static fonts instead of variable fonts"
|
|
144
|
+
option :variable, type: :boolean,
|
|
145
|
+
desc: "Install variable fonts instead of static fonts"
|
|
146
|
+
option :both, type: :boolean,
|
|
147
|
+
desc: "Install both the static and the variable variants"
|
|
142
148
|
option :transcode_path,
|
|
143
149
|
type: :string,
|
|
144
150
|
desc: "Directory to save transcoded fonts (default: same as install location)"
|
|
@@ -171,6 +177,9 @@ module Fontist
|
|
|
171
177
|
STATUS_UNKNOWN_ERROR)
|
|
172
178
|
end
|
|
173
179
|
|
|
180
|
+
selection_error = validate_variant_selection(options)
|
|
181
|
+
return selection_error if selection_error
|
|
182
|
+
|
|
174
183
|
# For backward compatibility, use original behavior for single font
|
|
175
184
|
if fonts.size == 1
|
|
176
185
|
confirmation = options[:accept_all_licenses] ? "yes" : "no"
|
|
@@ -539,6 +548,17 @@ module Fontist
|
|
|
539
548
|
status
|
|
540
549
|
end
|
|
541
550
|
|
|
551
|
+
def validate_variant_selection(options)
|
|
552
|
+
if options[:static] && options[:instance]
|
|
553
|
+
error("--static cannot be combined with --instance: " \
|
|
554
|
+
"instancing already produces a static font from a " \
|
|
555
|
+
"variable font.", STATUS_UNKNOWN_ERROR)
|
|
556
|
+
elsif options[:both] && (options[:static] || options[:variable])
|
|
557
|
+
error("--both cannot be combined with --static or --variable: " \
|
|
558
|
+
"--both already installs both variants.", STATUS_UNKNOWN_ERROR)
|
|
559
|
+
end
|
|
560
|
+
end
|
|
561
|
+
|
|
542
562
|
def format_bytes(bytes)
|
|
543
563
|
if bytes < 1024
|
|
544
564
|
"#{bytes} B"
|
|
@@ -76,50 +76,84 @@ module Fontist
|
|
|
76
76
|
Fontist.ui.say(%(Installing from formula "#{@formula.key}".))
|
|
77
77
|
|
|
78
78
|
Array.new.tap do |fonts_paths|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
installed_path = install_font_file(path)
|
|
82
|
-
fonts_paths << installed_path if installed_path
|
|
83
|
-
end
|
|
79
|
+
style_resource_groups.each do |resource, styles|
|
|
80
|
+
install_style_group(resource, styles, fonts_paths)
|
|
84
81
|
end
|
|
85
82
|
end
|
|
86
83
|
end
|
|
87
84
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
Resources::AppleCDNResource
|
|
93
|
-
elsif @formula.source == "windows_fod"
|
|
94
|
-
Resources::WindowsFodResource
|
|
95
|
-
else
|
|
96
|
-
Resources::ArchiveResource
|
|
97
|
-
end
|
|
85
|
+
# Groups the selected styles by the resource each one's file lives in.
|
|
86
|
+
def style_resource_groups
|
|
87
|
+
selected_styles.group_by { |style| resource_for_style(style) }
|
|
88
|
+
end
|
|
98
89
|
|
|
99
|
-
|
|
90
|
+
def selected_styles
|
|
91
|
+
styles = filtered_styles
|
|
92
|
+
styles = styles_in_requested_format(styles) if @formula.v5?
|
|
93
|
+
prefer_static_styles(styles)
|
|
100
94
|
end
|
|
101
95
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
96
|
+
# With no explicit static/variable request, styles of a font that
|
|
97
|
+
# offers both variants collapse to the static ones. An explicit
|
|
98
|
+
# variable request was already filtered by the matcher; --both keeps
|
|
99
|
+
# all variants.
|
|
100
|
+
def prefer_static_styles(styles)
|
|
101
|
+
return styles if @format_spec&.variable == true
|
|
102
|
+
return styles if @format_spec&.all_variants
|
|
103
|
+
return styles unless @formula.v5?
|
|
104
|
+
|
|
105
|
+
by_font = styles.group_by(&:family_name)
|
|
106
|
+
styles.reject do |style|
|
|
107
|
+
siblings = by_font[style.family_name]
|
|
108
|
+
siblings.any? { |s| !s.variable_font? } && style.variable_font?
|
|
109
|
+
end
|
|
111
110
|
end
|
|
112
111
|
|
|
113
|
-
def
|
|
114
|
-
|
|
112
|
+
def install_style_group(resource, styles, fonts_paths)
|
|
113
|
+
expected = styles.map { |s| s.source_font || s.font }
|
|
114
|
+
seen = []
|
|
115
|
+
|
|
116
|
+
resource_for(resource).files(expected) do |path|
|
|
117
|
+
basename = File.basename(path)
|
|
118
|
+
seen << basename
|
|
119
|
+
next unless expected.include?(basename) && font_directory?(path)
|
|
120
|
+
|
|
121
|
+
installed_path = install_font_file(path)
|
|
122
|
+
fonts_paths << installed_path if installed_path
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
(expected - seen).each do |name|
|
|
126
|
+
Fontist.ui.warn("Font file not found in #{resource.name}: #{name}")
|
|
127
|
+
end
|
|
115
128
|
end
|
|
116
129
|
|
|
117
|
-
|
|
118
|
-
|
|
130
|
+
# Resolution order: named by the style, then by file membership, then
|
|
131
|
+
# by the requested format (conversion path), then the first resource.
|
|
132
|
+
def resource_for_style(style)
|
|
133
|
+
named = style.source_resource &&
|
|
134
|
+
@formula.resources.find { |r| r.name == style.source_resource }
|
|
135
|
+
return named if named
|
|
136
|
+
|
|
137
|
+
source_name = style.source_font || style.font
|
|
138
|
+
by_file = @formula.resources.find do |r|
|
|
139
|
+
Array(r.files).any? { |f| File.basename(f) == source_name }
|
|
140
|
+
end
|
|
141
|
+
return by_file if by_file
|
|
142
|
+
|
|
143
|
+
by_format = @formula.resources.find do |r|
|
|
144
|
+
@format_spec&.format && r.format == @format_spec.format
|
|
145
|
+
end
|
|
146
|
+
by_format || @formula.resources.first
|
|
119
147
|
end
|
|
120
148
|
|
|
121
|
-
def
|
|
122
|
-
|
|
149
|
+
def resource_for(resource)
|
|
150
|
+
klass = case resource.source
|
|
151
|
+
when "google" then Resources::GoogleResource
|
|
152
|
+
when "apple_cdn" then Resources::AppleCDNResource
|
|
153
|
+
when "windows_fod" then Resources::WindowsFodResource
|
|
154
|
+
else Resources::ArchiveResource
|
|
155
|
+
end
|
|
156
|
+
klass.new(resource, no_progress: @no_progress)
|
|
123
157
|
end
|
|
124
158
|
|
|
125
159
|
# Styles already in the requested format. When none is, a plain format
|
|
@@ -133,27 +167,6 @@ module Fontist
|
|
|
133
167
|
@format_spec.format ? styles : matching
|
|
134
168
|
end
|
|
135
169
|
|
|
136
|
-
def source_files
|
|
137
|
-
@source_files ||= begin
|
|
138
|
-
styles = filtered_styles
|
|
139
|
-
|
|
140
|
-
styles = styles_in_requested_format(styles) if @formula.v5?
|
|
141
|
-
|
|
142
|
-
file_names = styles.map { |s| s.source_font || s.font }
|
|
143
|
-
|
|
144
|
-
if @formula.v5? && resource_options&.source == "google" && file_names.any?
|
|
145
|
-
resource_basenames = Array(resource_options.files).map do |f|
|
|
146
|
-
File.basename(f)
|
|
147
|
-
end
|
|
148
|
-
unless file_names.any? { |f| resource_basenames.include?(f) }
|
|
149
|
-
return resource_basenames
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
file_names
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
170
|
def filtered_styles
|
|
158
171
|
fonts.flat_map(&:styles)
|
|
159
172
|
end
|
|
@@ -39,9 +39,7 @@ module Fontist
|
|
|
39
39
|
|
|
40
40
|
def run(source, target, output)
|
|
41
41
|
FileUtils.mkdir_p(File.dirname(output))
|
|
42
|
-
Fontisan::
|
|
43
|
-
source, to: target, output: output, quiet: true
|
|
44
|
-
).run
|
|
42
|
+
Fontisan::Reference.convert(source, to: target, output: output)
|
|
45
43
|
end
|
|
46
44
|
|
|
47
45
|
def verify!(path, target)
|
|
@@ -18,9 +18,9 @@ module Fontist
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def unpack(collection_path, index, output_dir)
|
|
21
|
-
Fontisan::
|
|
22
|
-
collection_path,
|
|
23
|
-
)
|
|
21
|
+
Fontisan::Reference.extract(
|
|
22
|
+
collection_path, index: index, output_dir: output_dir
|
|
23
|
+
)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def check_index!(path, index)
|
|
@@ -59,13 +59,17 @@ module Fontist
|
|
|
59
59
|
"#{File.basename(source)} is not a variable font"
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
validate!(Fontisan::Variable::Instancer.new(font), coords,
|
|
63
|
+
File.basename(source))
|
|
64
64
|
FileUtils.mkdir_p(File.dirname(output))
|
|
65
|
-
File.binwrite(output,
|
|
65
|
+
File.binwrite(output, instance_bytes(source, coords))
|
|
66
66
|
output
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
def instance_bytes(source, coords)
|
|
70
|
+
Fontisan::Reference.instance(source, coords: coords)
|
|
71
|
+
end
|
|
72
|
+
|
|
69
73
|
def validate!(instancer, coords, name)
|
|
70
74
|
axes = instancer.axes.to_h { |axis| [axis.tag, axis] }
|
|
71
75
|
coords.each do |tag, value|
|
|
@@ -4,6 +4,7 @@ module Fontist
|
|
|
4
4
|
module FontOperations
|
|
5
5
|
# Keeps only the glyphs for the given characters.
|
|
6
6
|
module Subset
|
|
7
|
+
NO_GLYPHS = "None of the requested characters exist in".freeze
|
|
7
8
|
UNICODE_PART = /\A(u\+)?\h+(-(u\+)?\h+)?\z/i
|
|
8
9
|
|
|
9
10
|
module_function
|
|
@@ -28,21 +29,16 @@ module Fontist
|
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def write(source, output, codepoints)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
binary = Fontisan::Subset::Builder.new(font, gids, options).build
|
|
32
|
+
binary = Fontisan::Reference.subset(
|
|
33
|
+
source, unicodes: codepoints, profile: "web"
|
|
34
|
+
)
|
|
35
35
|
FileUtils.mkdir_p(File.dirname(output))
|
|
36
36
|
File.binwrite(output, binary)
|
|
37
37
|
output
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def glyph_ids(font, codepoints, name)
|
|
41
|
-
mappings = font.table("cmap").unicode_mappings
|
|
42
|
-
gids = codepoints.uniq.filter_map { |cp| mappings[cp] }.uniq.sort
|
|
43
|
-
return gids if gids.any?
|
|
38
|
+
rescue Fontisan::Error => e
|
|
39
|
+
raise unless e.message.start_with?(NO_GLYPHS)
|
|
44
40
|
|
|
45
|
-
raise Error,
|
|
41
|
+
raise Error, e.message
|
|
46
42
|
end
|
|
47
43
|
|
|
48
44
|
# "U+0020-007E,U+00E9" => [32..126, 233].flatten
|
|
@@ -27,7 +27,9 @@ module Fontist
|
|
|
27
27
|
return false
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
if @spec.
|
|
30
|
+
if @spec.static_requested?
|
|
31
|
+
return false if resource.variable_font?
|
|
32
|
+
elsif @spec.variable_requested?
|
|
31
33
|
return false unless resource.variable_font?
|
|
32
34
|
return axes_match?(resource.variable_axes) if @spec.axes.any?
|
|
33
35
|
end
|
|
@@ -45,10 +47,10 @@ module Fontist
|
|
|
45
47
|
return false
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
if @spec.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return false unless
|
|
50
|
+
if @spec.static_requested?
|
|
51
|
+
return false if style.variable_font?
|
|
52
|
+
elsif @spec.variable_requested?
|
|
53
|
+
return false unless style.variable_font?
|
|
52
54
|
|
|
53
55
|
return axes_match?(style.variable_axes) if @spec.axes.any?
|
|
54
56
|
end
|
|
@@ -61,7 +63,9 @@ module Fontist
|
|
|
61
63
|
return true unless @spec.has_constraints?
|
|
62
64
|
return false if @spec.format && indexed_font.format != @spec.format
|
|
63
65
|
|
|
64
|
-
if @spec.
|
|
66
|
+
if @spec.static_requested?
|
|
67
|
+
return false if indexed_font.variable_font
|
|
68
|
+
elsif @spec.variable_requested?
|
|
65
69
|
return false unless indexed_font.variable_font
|
|
66
70
|
|
|
67
71
|
return axes_match?(indexed_font.variable_axes) if @spec.axes.any?
|
|
@@ -88,7 +92,6 @@ module Fontist
|
|
|
88
92
|
# Select best resource based on preferences
|
|
89
93
|
def select_preferred_resource(resources)
|
|
90
94
|
return resources.first if resources.empty?
|
|
91
|
-
return resources.first unless @spec.has_constraints?
|
|
92
95
|
|
|
93
96
|
# Match exact format first (e.g. format: "ttf" selects the ttf resource)
|
|
94
97
|
exact = find_exact_format(resources)
|
|
@@ -97,6 +100,9 @@ module Fontist
|
|
|
97
100
|
preferred = find_preferred_format(resources)
|
|
98
101
|
return preferred if preferred
|
|
99
102
|
|
|
103
|
+
static = find_static_resource(resources)
|
|
104
|
+
return static if static && !@spec.variable_requested?
|
|
105
|
+
|
|
100
106
|
variable = find_variable_resource(resources)
|
|
101
107
|
return variable if variable
|
|
102
108
|
|
|
@@ -163,9 +169,15 @@ module Fontist
|
|
|
163
169
|
end
|
|
164
170
|
|
|
165
171
|
def find_variable_resource(resources)
|
|
166
|
-
return nil unless @spec.
|
|
172
|
+
return nil unless @spec.variable_requested?
|
|
173
|
+
|
|
174
|
+
resources.find do |r|
|
|
175
|
+
r.variable_font? && (@spec.axes.empty? || axes_match?(r.variable_axes))
|
|
176
|
+
end
|
|
177
|
+
end
|
|
167
178
|
|
|
168
|
-
|
|
179
|
+
def find_static_resource(resources)
|
|
180
|
+
resources.reject(&:variable_font?).first
|
|
169
181
|
end
|
|
170
182
|
|
|
171
183
|
def axes_match?(available_axes)
|
data/lib/fontist/format_spec.rb
CHANGED
|
@@ -20,6 +20,13 @@ module Fontist
|
|
|
20
20
|
attribute :variable_axes, :string, collection: true
|
|
21
21
|
attribute :prefer_variable, :boolean, default: false
|
|
22
22
|
|
|
23
|
+
# Static/variable selection: nil = any, true = variable only,
|
|
24
|
+
# false = static only
|
|
25
|
+
attribute :variable, :boolean
|
|
26
|
+
|
|
27
|
+
# Install both static and variable variants in one call (--both)
|
|
28
|
+
attribute :all_variants, :boolean, default: false
|
|
29
|
+
|
|
23
30
|
# Format preferences
|
|
24
31
|
attribute :prefer_format, :string
|
|
25
32
|
|
|
@@ -42,10 +49,14 @@ module Fontist
|
|
|
42
49
|
|
|
43
50
|
# Convenience constructor for CLI
|
|
44
51
|
def self.from_options(options = {})
|
|
52
|
+
preference = parse_variable_preference(options)
|
|
45
53
|
new(
|
|
46
54
|
format: options[:format],
|
|
47
55
|
variable_axes: parse_variable_axes(options[:variable_axes]),
|
|
48
|
-
prefer_variable:
|
|
56
|
+
prefer_variable: preference.nil? &&
|
|
57
|
+
(options[:prefer_variable] || false),
|
|
58
|
+
variable: preference,
|
|
59
|
+
all_variants: options[:both] || false,
|
|
49
60
|
prefer_format: options[:prefer_format],
|
|
50
61
|
transcode_path: options[:transcode_path],
|
|
51
62
|
keep_original: options.fetch(:keep_original, true),
|
|
@@ -54,6 +65,14 @@ module Fontist
|
|
|
54
65
|
)
|
|
55
66
|
end
|
|
56
67
|
|
|
68
|
+
# Explicit --static/--variable flags win over legacy prefer_variable.
|
|
69
|
+
def self.parse_variable_preference(options)
|
|
70
|
+
return true if options[:variable]
|
|
71
|
+
return false if options[:static]
|
|
72
|
+
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
|
|
57
76
|
def self.operation_options(options)
|
|
58
77
|
{
|
|
59
78
|
subset_unicodes: options[:subset_unicodes],
|
|
@@ -72,12 +91,18 @@ module Fontist
|
|
|
72
91
|
|
|
73
92
|
# Check if any format constraints are specified
|
|
74
93
|
def has_constraints?
|
|
75
|
-
!!(format || variable_axes&.any? || prefer_variable ||
|
|
94
|
+
!!(format || variable_axes&.any? || prefer_variable ||
|
|
95
|
+
!variable.nil? || all_variants || prefer_format)
|
|
76
96
|
end
|
|
77
97
|
|
|
78
98
|
# Check if variable font is requested
|
|
79
99
|
def variable_requested?
|
|
80
|
-
!!(variable_axes&.any? || prefer_variable)
|
|
100
|
+
!!(variable == true || variable_axes&.any? || prefer_variable)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Check if a static font is requested
|
|
104
|
+
def static_requested?
|
|
105
|
+
variable == false
|
|
81
106
|
end
|
|
82
107
|
|
|
83
108
|
# Get axes as array (never nil)
|
|
@@ -128,7 +128,12 @@ module Fontist
|
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
def group_fonts_by_subfamily(fonts)
|
|
131
|
-
|
|
131
|
+
# Static styles arrive with symbol keys (build_style_data) while
|
|
132
|
+
# variable styles arrive with string keys (VariableFontSource);
|
|
133
|
+
# group on either so both land in the family's group.
|
|
134
|
+
fonts_by_subfamily = fonts.group_by do |font|
|
|
135
|
+
font[:family_name] || font["family_name"]
|
|
136
|
+
end
|
|
132
137
|
|
|
133
138
|
fonts_by_subfamily.map do |subfamily_name, styles|
|
|
134
139
|
{
|
|
@@ -133,6 +133,8 @@ module Fontist
|
|
|
133
133
|
filename = url.split("/").last
|
|
134
134
|
|
|
135
135
|
style_data = build_style_data(metadata, filename)
|
|
136
|
+
style_data[:source_font] = filename
|
|
137
|
+
style_data[:font] = static_install_name(metadata, filename)
|
|
136
138
|
|
|
137
139
|
# Add v5-specific attributes
|
|
138
140
|
add_v5_style_attributes(style_data, metadata, variant)
|
|
@@ -149,6 +151,16 @@ module Fontist
|
|
|
149
151
|
group_fonts_by_subfamily(parsed_fonts)
|
|
150
152
|
end
|
|
151
153
|
|
|
154
|
+
# Install name for a static instance: PostScript name + the URL's
|
|
155
|
+
# extension. Falls back to the URL basename when the font's name
|
|
156
|
+
# table lacks a PostScript name.
|
|
157
|
+
def static_install_name(metadata, filename)
|
|
158
|
+
ps_name = metadata.postscript_name.to_s.strip
|
|
159
|
+
return filename if ps_name.empty?
|
|
160
|
+
|
|
161
|
+
"#{ps_name}#{File.extname(filename)}"
|
|
162
|
+
end
|
|
163
|
+
|
|
152
164
|
def add_v5_style_attributes(style, _metadata = nil, variant = nil)
|
|
153
165
|
# Add formats available for this style
|
|
154
166
|
style["formats"] = determine_formats_for_style(variant)
|