fontist 3.0.38 → 3.0.40
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/rake-metanorma.yaml +0 -2
- data/.github/workflows/release.yml +1 -0
- data/README.adoc +42 -0
- data/lib/fontist/cli.rb +20 -0
- data/lib/fontist/font.rb +33 -1
- data/lib/fontist/font_installer.rb +65 -52
- data/lib/fontist/format_matcher.rb +21 -9
- data/lib/fontist/format_spec.rb +28 -3
- data/lib/fontist/formula.rb +15 -0
- 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 +60 -16
- data/lib/fontist/manifest_cli.rb +19 -1
- data/lib/fontist/system_index.rb +16 -0
- data/lib/fontist/utils/downloader.rb +6 -1
- data/lib/fontist/utils/ui.rb +6 -1
- data/lib/fontist/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce7d7174490910823059c7abf1a6b7d910ad2e383594606df92bad8f8ddb5cad
|
|
4
|
+
data.tar.gz: cfdca82ec87b74d49260146aaaeb5143a8a85008b96dc12a0a54d20a170e8900
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ecae7158189d128ad7ed41bf1cffe119f3656222da9f1eb43fe46bae233bb18f5a9a8e99c2eedc120306d7fc6b9b224de56367d6feb6e5ec1c04394beb22817
|
|
7
|
+
data.tar.gz: 66766185068d24636922d1feb67345a3fb01e7faf53a5e1146389ac2c1db52999e8f7049b47c9bb1eb7babb3ff067fced1744488a21b46d1a0d7aa32eb49a6f4
|
data/README.adoc
CHANGED
|
@@ -371,6 +371,12 @@ Supported options:
|
|
|
371
371
|
`-u, [--update-fontconfig]`:: Update Fontconfig
|
|
372
372
|
`--collection-index=N`, `--format=FORMAT`, `--fallback-to-original`,
|
|
373
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>>
|
|
374
380
|
|
|
375
381
|
|
|
376
382
|
NOTE: The `install` command is similar to the `Font.install` library call.
|
|
@@ -449,6 +455,42 @@ Fontist::Font.install("Lato", format: "woff2", subset_text: "Hello")
|
|
|
449
455
|
|
|
450
456
|
==== Variable-font instancing
|
|
451
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
|
+
|
|
452
494
|
`--instance` installs a static instance of a variable font at the given axis
|
|
453
495
|
values. Tags and ranges are checked against the font's `fvar` table; an
|
|
454
496
|
unknown axis, an out-of-range value or a non-variable font is an error.
|
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"
|
data/lib/fontist/font.rb
CHANGED
|
@@ -69,7 +69,7 @@ module Fontist
|
|
|
69
69
|
def install
|
|
70
70
|
return install_formula if @by_formula
|
|
71
71
|
|
|
72
|
-
(
|
|
72
|
+
(find_installable_font unless @force) || download_font || manual_font ||
|
|
73
73
|
raise_non_supported_font
|
|
74
74
|
end
|
|
75
75
|
|
|
@@ -118,6 +118,38 @@ module Fontist
|
|
|
118
118
|
paths # Return paths after printing
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
+
# Install-time lookup under the static default: a variable font already
|
|
122
|
+
# on disk does not satisfy a plain request when the formula offers
|
|
123
|
+
# static files, so stale variable installs from older fontist versions
|
|
124
|
+
# cannot shadow the statics forever (fontist/fontist#556).
|
|
125
|
+
def find_installable_font
|
|
126
|
+
paths = Fontist::SystemFont.find(name)
|
|
127
|
+
unless paths
|
|
128
|
+
Fontist.ui.say(%(Font "#{name}" not found locally.))
|
|
129
|
+
return
|
|
130
|
+
end
|
|
131
|
+
return if static_variant_shadowed_locally?
|
|
132
|
+
|
|
133
|
+
print_paths(paths)
|
|
134
|
+
paths
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def static_variant_shadowed_locally?
|
|
138
|
+
return false if @format_spec&.variable_requested?
|
|
139
|
+
return false if @format_spec&.all_variants
|
|
140
|
+
return false unless static_variant_locally?
|
|
141
|
+
|
|
142
|
+
Formula.offers_static_variant?(name)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def static_variant_locally?
|
|
146
|
+
located = Fontist::SystemFont.find_styles(name)
|
|
147
|
+
return false if located.nil? || located.empty?
|
|
148
|
+
|
|
149
|
+
located.any?(&:variable_font) &&
|
|
150
|
+
located.none? { |style| !style.variable_font }
|
|
151
|
+
end
|
|
152
|
+
|
|
121
153
|
def print_paths(paths)
|
|
122
154
|
Fontist.ui.say("Fonts found at:")
|
|
123
155
|
paths.each do |path|
|
|
@@ -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
|
|
@@ -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)
|
data/lib/fontist/formula.rb
CHANGED
|
@@ -135,6 +135,21 @@ module Fontist
|
|
|
135
135
|
Indexes::FontIndex.lookup_index.load_formulas(font_name)
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
+
# Whether any formula answering to this font name offers a static
|
|
139
|
+
# (non-variable) file. With the static default (fontist/fontist#556),
|
|
140
|
+
# callers use this to decide whether variable files on disk may satisfy
|
|
141
|
+
# a plain request: when statics exist, they must be preferred even if a
|
|
142
|
+
# stale variable install from an older fontist version is present.
|
|
143
|
+
def offers_static_variant?(font_name)
|
|
144
|
+
find_many(font_name).compact.any? do |formula|
|
|
145
|
+
formula.all_fonts.flat_map(&:styles).any? do |style|
|
|
146
|
+
!style.variable_font?
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
rescue Errors::FormulaNotFoundError, Errors::FontIndexCorrupted
|
|
150
|
+
false
|
|
151
|
+
end
|
|
152
|
+
|
|
138
153
|
def find_fonts(font_name)
|
|
139
154
|
formulas = Indexes::FontIndex.lookup_index.load_formulas(font_name)
|
|
140
155
|
|
|
@@ -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)
|
data/lib/fontist/manifest.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "lutaml/model"
|
|
2
|
+
require_relative "format_matcher"
|
|
2
3
|
require_relative "format_spec"
|
|
3
4
|
|
|
4
5
|
module Fontist
|
|
@@ -10,6 +11,8 @@ module Fontist
|
|
|
10
11
|
attribute :format, :string
|
|
11
12
|
attribute :variable_axes, :string, collection: true
|
|
12
13
|
attribute :prefer_variable, :boolean, default: false
|
|
14
|
+
attribute :variable, :boolean
|
|
15
|
+
attribute :all_variants, :boolean, default: false
|
|
13
16
|
|
|
14
17
|
# Transcoding options
|
|
15
18
|
attribute :transcode_path, :string
|
|
@@ -30,6 +33,8 @@ module Fontist
|
|
|
30
33
|
format: format,
|
|
31
34
|
variable_axes: variable_axes,
|
|
32
35
|
prefer_variable: prefer_variable,
|
|
36
|
+
variable: variable,
|
|
37
|
+
all_variants: all_variants,
|
|
33
38
|
transcode_path: transcode_path,
|
|
34
39
|
keep_original: keep_original,
|
|
35
40
|
collection_index: collection_index,
|
|
@@ -63,6 +68,34 @@ module Fontist
|
|
|
63
68
|
Fontist::SystemFont.find_styles(font, style)
|
|
64
69
|
end
|
|
65
70
|
|
|
71
|
+
# True when every located file fails the font's static/variant spec —
|
|
72
|
+
# e.g. only a variable font's named instance resolves a variable: false
|
|
73
|
+
# request — so installation must fetch files that actually match.
|
|
74
|
+
# With the static default, variable files on disk also do not satisfy a
|
|
75
|
+
# plain request when the formula offers static files: stale variable
|
|
76
|
+
# installs from older fontist versions would otherwise shadow the
|
|
77
|
+
# statics forever.
|
|
78
|
+
def unsatisfied_by_spec?
|
|
79
|
+
located = style_paths
|
|
80
|
+
return true if located.empty?
|
|
81
|
+
|
|
82
|
+
return true if static_default_shadowed_by_variable?(located)
|
|
83
|
+
|
|
84
|
+
return false unless format_spec.has_constraints?
|
|
85
|
+
|
|
86
|
+
matcher = FormatMatcher.new(format_spec)
|
|
87
|
+
located.all? { |indexed| !matcher.matches_indexed_font?(indexed) }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def static_default_shadowed_by_variable?(located)
|
|
91
|
+
return false if format_spec.variable_requested?
|
|
92
|
+
return false if format_spec.all_variants
|
|
93
|
+
|
|
94
|
+
located.all? { |indexed| indexed.variable_font } &&
|
|
95
|
+
located.any? { |indexed| indexed.variable_font } &&
|
|
96
|
+
Fontist::Formula.offers_static_variant?(name)
|
|
97
|
+
end
|
|
98
|
+
|
|
66
99
|
def install(confirmation: "no", hide_licenses: false, no_progress: false,
|
|
67
100
|
location: nil)
|
|
68
101
|
validate_location_parameter!(location)
|
|
@@ -146,7 +179,8 @@ module Fontist
|
|
|
146
179
|
# format: woff2
|
|
147
180
|
#
|
|
148
181
|
# The plain form `Roboto: [Regular, Bold]` stays valid.
|
|
149
|
-
FONT_OPTIONS = %w[format variable_axes prefer_variable
|
|
182
|
+
FONT_OPTIONS = %w[format variable_axes prefer_variable variable
|
|
183
|
+
all_variants transcode_path
|
|
150
184
|
keep_original collection_index subset_unicodes
|
|
151
185
|
subset_text fallback_to_original instance].freeze
|
|
152
186
|
|
|
@@ -193,29 +227,39 @@ module Fontist
|
|
|
193
227
|
def self.from_file(path, locations: false)
|
|
194
228
|
Fontist.ui.debug("Manifest: #{path}")
|
|
195
229
|
|
|
196
|
-
|
|
197
|
-
raise Fontist::Errors::ManifestCouldNotBeFoundError,
|
|
198
|
-
"Manifest file not found: #{path}"
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
file_content = File.read(path).strip
|
|
230
|
+
manifest_model = model_from_file(path)
|
|
202
231
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
232
|
+
# Use performance optimizations for faster manifest compilation
|
|
233
|
+
with_performance_optimizations do
|
|
234
|
+
manifest_model.to_response(locations: locations)
|
|
206
235
|
end
|
|
236
|
+
end
|
|
207
237
|
|
|
208
|
-
|
|
209
|
-
|
|
238
|
+
# The parsed manifest model with per-font options intact — from_file
|
|
239
|
+
# collapses resolved fonts into a response whose entries have lost
|
|
240
|
+
# them, so install flows that honor variable:/all_variants: must
|
|
241
|
+
# start here instead.
|
|
242
|
+
def self.model_from_file(path)
|
|
243
|
+
validate_manifest_path!(path)
|
|
244
|
+
|
|
245
|
+
begin
|
|
246
|
+
from_yaml(File.read(path).strip)
|
|
210
247
|
rescue StandardError => e
|
|
211
248
|
raise Fontist::Errors::ManifestCouldNotBeReadError,
|
|
212
249
|
"Manifest file could not be read: #{e.message}"
|
|
213
250
|
end
|
|
251
|
+
end
|
|
214
252
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
253
|
+
def self.validate_manifest_path!(path)
|
|
254
|
+
unless File.exist?(path)
|
|
255
|
+
raise Fontist::Errors::ManifestCouldNotBeFoundError,
|
|
256
|
+
"Manifest file not found: #{path}"
|
|
218
257
|
end
|
|
258
|
+
|
|
259
|
+
return unless File.read(path).strip.empty?
|
|
260
|
+
|
|
261
|
+
raise Fontist::Errors::ManifestCouldNotBeReadError,
|
|
262
|
+
"Manifest file is empty: #{path}"
|
|
219
263
|
end
|
|
220
264
|
|
|
221
265
|
def self.from_hash(data, options = {})
|
|
@@ -270,7 +314,7 @@ location: nil)
|
|
|
270
314
|
fonts_casted.each do |font|
|
|
271
315
|
paths = font.group_paths
|
|
272
316
|
|
|
273
|
-
if paths.empty?
|
|
317
|
+
if paths.empty? || font.unsatisfied_by_spec?
|
|
274
318
|
font.install(confirmation: confirmation,
|
|
275
319
|
hide_licenses: hide_licenses,
|
|
276
320
|
no_progress: no_progress,
|
data/lib/fontist/manifest_cli.rb
CHANGED
|
@@ -13,9 +13,27 @@ module Fontist
|
|
|
13
13
|
type: :string, aliases: :l,
|
|
14
14
|
enum: ["fontist", "user", "system"],
|
|
15
15
|
desc: "Install location: fontist (default), user, system"
|
|
16
|
+
option :static, type: :boolean,
|
|
17
|
+
desc: "Install static fonts for entries that do not " \
|
|
18
|
+
"set variable: themselves"
|
|
19
|
+
option :both, type: :boolean,
|
|
20
|
+
desc: "Install both variants for entries that do not " \
|
|
21
|
+
"set all_variants: themselves"
|
|
16
22
|
def install(manifest)
|
|
17
23
|
handle_class_options(options)
|
|
18
|
-
instance = Fontist::Manifest.
|
|
24
|
+
instance = Fontist::Manifest.model_from_file(manifest)
|
|
25
|
+
|
|
26
|
+
if options[:static]
|
|
27
|
+
instance.fonts.each do |font|
|
|
28
|
+
font.variable = false if font.variable.nil?
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
if options[:both]
|
|
32
|
+
instance.fonts.each do |font|
|
|
33
|
+
font.all_variants = true unless font.all_variants
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
19
37
|
paths = instance.install(
|
|
20
38
|
confirmation: options[:accept_all_licenses] ? "yes" : "no",
|
|
21
39
|
hide_licenses: options[:hide_licenses],
|
data/lib/fontist/system_index.rb
CHANGED
|
@@ -190,6 +190,22 @@ module Fontist
|
|
|
190
190
|
map_instances to: :fonts
|
|
191
191
|
end
|
|
192
192
|
|
|
193
|
+
# Older fontist versions serialized the entries under a `fonts:` key
|
|
194
|
+
# together with inline scan metadata. Accept that shape so an index
|
|
195
|
+
# written by a released gem parses as its entry list instead of a
|
|
196
|
+
# single blank entry (which check_index reports as corruption).
|
|
197
|
+
def self.from_yaml(content, options = {})
|
|
198
|
+
legacy = legacy_font_entries(content)
|
|
199
|
+
super(legacy ? Array(legacy).to_yaml : content, options)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def self.legacy_font_entries(content)
|
|
203
|
+
data = YAML.safe_load(content, aliases: true)
|
|
204
|
+
data.is_a?(Hash) ? data["fonts"] : nil
|
|
205
|
+
rescue StandardError
|
|
206
|
+
nil
|
|
207
|
+
end
|
|
208
|
+
|
|
193
209
|
# Don't rebuild index more frequently than this (in seconds)
|
|
194
210
|
INDEX_REBUILD_THRESHOLD = 30 * 60 # 30 minutes
|
|
195
211
|
|
|
@@ -6,7 +6,12 @@ module Fontist
|
|
|
6
6
|
RATE_LIMITED_HTTP_STATUS = 429
|
|
7
7
|
BACKOFF = {
|
|
8
8
|
rate_limited: [10, 20, 40, 60, 90].freeze,
|
|
9
|
-
|
|
9
|
+
# Two quick retries give snappy hosts a second chance, and the
|
|
10
|
+
# slower tail absorbs large shared archives: web.archive.org and
|
|
11
|
+
# similar mirror hosts routinely fail single requests with
|
|
12
|
+
# timeouts or reset connections and recover within seconds
|
|
13
|
+
# (metanorma S-201 builds hit this on EUupdate.EXE).
|
|
14
|
+
transient: [2, 4, 8, 15].freeze,
|
|
10
15
|
}.freeze
|
|
11
16
|
MAX_RETRY_AFTER = 120
|
|
12
17
|
JITTER_RATIO = 0.25
|
data/lib/fontist/utils/ui.rb
CHANGED
|
@@ -35,8 +35,13 @@ module Fontist
|
|
|
35
35
|
new.say(message, :green) if log_levels.include?(:info)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
# Errors go to stderr so that callers who redirect stdout — pipelines
|
|
39
|
+
# that capture fontist YAML output into a file — never receive error
|
|
40
|
+
# prose in place of data (metanorma/mn2pdf#466).
|
|
38
41
|
def self.error(message)
|
|
39
|
-
|
|
42
|
+
return unless log_levels.include?(:warn)
|
|
43
|
+
|
|
44
|
+
$stderr.puts new.set_color(message, :red)
|
|
40
45
|
end
|
|
41
46
|
|
|
42
47
|
def self.warn(message)
|
data/lib/fontist/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fontist
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.40
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: down
|