fontist 1.21.4 → 2.0.1
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.yml +4 -0
- data/Gemfile +11 -0
- data/README.adoc +6 -6
- data/docs/guide/api-ruby.md +8 -9
- data/fontist.gemspec +14 -24
- data/formula_filename_index.yml +6210 -0
- data/formula_index.yml +2568 -0
- data/lib/fontist/cli.rb +14 -14
- data/lib/fontist/config.rb +75 -14
- data/lib/fontist/errors.rb +2 -0
- data/lib/fontist/extract.rb +25 -0
- data/lib/fontist/font.rb +6 -8
- data/lib/fontist/font_collection.rb +16 -0
- data/lib/fontist/font_installer.rb +4 -4
- data/lib/fontist/font_model.rb +15 -0
- data/lib/fontist/font_path.rb +1 -1
- data/lib/fontist/font_style.rb +37 -0
- data/lib/fontist/formula.rb +169 -112
- data/lib/fontist/import/formula_serializer.rb +4 -4
- data/lib/fontist/import/google_import.rb +1 -1
- data/lib/fontist/index.rb +47 -8
- data/lib/fontist/indexes/default_family_font_index.rb +28 -9
- data/lib/fontist/indexes/filename_index.rb +45 -8
- data/lib/fontist/indexes/font_index.rb +3 -3
- data/lib/fontist/indexes/formula_key_to_path.rb +35 -0
- data/lib/fontist/indexes/index_mixin.rb +109 -0
- data/lib/fontist/indexes/preferred_family_font_index.rb +28 -9
- data/lib/fontist/manifest.rb +144 -2
- data/lib/fontist/manifest_request.rb +64 -0
- data/lib/fontist/manifest_response.rb +66 -0
- data/lib/fontist/repo.rb +1 -1
- data/lib/fontist/system_font.rb +7 -25
- data/lib/fontist/system_index.rb +137 -126
- data/lib/fontist/utils/cache.rb +54 -4
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +33 -13
- metadata +16 -136
- data/lib/fontist/indexes/base_index.rb +0 -92
- data/lib/fontist/indexes/index_formula.rb +0 -36
- data/lib/fontist/manifest/install.rb +0 -35
- data/lib/fontist/manifest/locations.rb +0 -84
data/lib/fontist/formula.rb
CHANGED
|
@@ -1,23 +1,104 @@
|
|
|
1
|
-
require "
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
require "lutaml/model"
|
|
2
|
+
require_relative "font_model"
|
|
3
|
+
require_relative "font_collection"
|
|
4
|
+
require_relative "extract"
|
|
5
|
+
require_relative "index"
|
|
6
|
+
require_relative "helpers"
|
|
7
|
+
require_relative "update"
|
|
4
8
|
require "git"
|
|
5
9
|
|
|
6
10
|
module Fontist
|
|
7
|
-
|
|
11
|
+
require "lutaml/model"
|
|
12
|
+
|
|
13
|
+
class Resource < Lutaml::Model::Serializable
|
|
14
|
+
attribute :name, :string
|
|
15
|
+
attribute :source, :string
|
|
16
|
+
attribute :urls, :string, collection: true
|
|
17
|
+
attribute :sha256, :string, collection: true
|
|
18
|
+
attribute :file_size, :integer
|
|
19
|
+
attribute :family, :string
|
|
20
|
+
attribute :files, :string, collection: true
|
|
21
|
+
|
|
22
|
+
def empty?
|
|
23
|
+
Array(urls).empty? && Array(files).empty?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class ResourceCollection < Lutaml::Model::Collection
|
|
28
|
+
instances :resources, Resource
|
|
29
|
+
|
|
30
|
+
key_value do
|
|
31
|
+
root "resources"
|
|
32
|
+
map to: :resources
|
|
33
|
+
map_key to_instance: :name
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def empty?
|
|
37
|
+
resources.nil? || Array(resources).all?(&:empty?)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Formula < Lutaml::Model::Serializable
|
|
8
42
|
NAMESPACES = {
|
|
9
43
|
"sil" => "SIL",
|
|
10
44
|
"macos" => "macOS",
|
|
11
45
|
}.freeze
|
|
12
46
|
|
|
47
|
+
attribute :name, :string
|
|
48
|
+
attribute :path, :string
|
|
49
|
+
attribute :description, :string
|
|
50
|
+
attribute :homepage, :string
|
|
51
|
+
attribute :display_progress_bar, :boolean
|
|
52
|
+
attribute :repository, :string
|
|
53
|
+
attribute :copyright, :string
|
|
54
|
+
attribute :license_url, :string
|
|
55
|
+
attribute :open_license, :string
|
|
56
|
+
attribute :requires_license_agreement, :string
|
|
57
|
+
attribute :platforms, :string, collection: true
|
|
58
|
+
attribute :min_fontist, :string
|
|
59
|
+
attribute :digest, :string
|
|
60
|
+
attribute :instructions, :string
|
|
61
|
+
attribute :resources, ResourceCollection, collection: true
|
|
62
|
+
attribute :font_collections, FontCollection, collection: true
|
|
63
|
+
attribute :fonts, FontModel, collection: true, default: []
|
|
64
|
+
attribute :extract, Extract, collection: true
|
|
65
|
+
attribute :command, :string
|
|
66
|
+
|
|
67
|
+
key_value do
|
|
68
|
+
map "name", to: :name
|
|
69
|
+
map "description", to: :description
|
|
70
|
+
map "homepage", to: :homepage
|
|
71
|
+
map "display_progress_bar", to: :display_progress_bar
|
|
72
|
+
map "repository", to: :repository
|
|
73
|
+
map "platforms", to: :platforms
|
|
74
|
+
map "resources", to: :resources, value_map: {
|
|
75
|
+
to: { empty: :empty, omitted: :omitted, nil: :nil },
|
|
76
|
+
}
|
|
77
|
+
map "digest", to: :digest
|
|
78
|
+
map "instructions", to: :instructions
|
|
79
|
+
map "font_collections", to: :font_collections
|
|
80
|
+
map "fonts", to: :fonts
|
|
81
|
+
map "extract", to: :extract, value_map: {
|
|
82
|
+
to: { empty: :empty, omitted: :omitted, nil: :nil },
|
|
83
|
+
}
|
|
84
|
+
map "min_fontist", to: :min_fontist
|
|
85
|
+
map "copyright", to: :copyright
|
|
86
|
+
map "requires_license_agreement", to: :requires_license_agreement
|
|
87
|
+
map "license_url", to: :license_url
|
|
88
|
+
map "open_license", to: :open_license
|
|
89
|
+
map "command", to: :command
|
|
90
|
+
end
|
|
91
|
+
|
|
13
92
|
def self.update_formulas_repo
|
|
14
93
|
Update.call
|
|
15
94
|
end
|
|
16
95
|
|
|
17
96
|
def self.all
|
|
18
|
-
Dir[Fontist.formulas_path.join("**/*.yml").to_s].map do |path|
|
|
19
|
-
Formula.
|
|
97
|
+
formulas = Dir[Fontist.formulas_path.join("**/*.yml").to_s].map do |path|
|
|
98
|
+
Formula.from_file(path)
|
|
20
99
|
end
|
|
100
|
+
|
|
101
|
+
FormulaCollection.new(formulas)
|
|
21
102
|
end
|
|
22
103
|
|
|
23
104
|
def self.all_keys
|
|
@@ -27,28 +108,28 @@ module Fontist
|
|
|
27
108
|
end
|
|
28
109
|
|
|
29
110
|
def self.find(font_name)
|
|
30
|
-
Indexes::FontIndex.
|
|
111
|
+
Indexes::FontIndex.from_file.load_formulas(font_name).first
|
|
31
112
|
end
|
|
32
113
|
|
|
33
114
|
def self.find_many(font_name)
|
|
34
|
-
Indexes::FontIndex.
|
|
115
|
+
Indexes::FontIndex.from_file.load_formulas(font_name)
|
|
35
116
|
end
|
|
36
117
|
|
|
37
118
|
def self.find_fonts(font_name)
|
|
38
|
-
formulas = Indexes::FontIndex.
|
|
119
|
+
formulas = Indexes::FontIndex.from_file.load_formulas(font_name)
|
|
39
120
|
|
|
40
121
|
formulas.map do |formula|
|
|
41
|
-
formula.
|
|
122
|
+
formula.all_fonts.select do |f|
|
|
42
123
|
f.name.casecmp?(font_name)
|
|
43
124
|
end
|
|
44
125
|
end.flatten
|
|
45
126
|
end
|
|
46
127
|
|
|
47
128
|
def self.find_styles(font_name, style_name)
|
|
48
|
-
formulas = Indexes::FontIndex.
|
|
129
|
+
formulas = Indexes::FontIndex.from_file.load_formulas(font_name)
|
|
49
130
|
|
|
50
131
|
formulas.map do |formula|
|
|
51
|
-
formula.
|
|
132
|
+
formula.all_fonts.map do |f|
|
|
52
133
|
f.styles.select do |s|
|
|
53
134
|
f.name.casecmp?(font_name) && s.type.casecmp?(style_name)
|
|
54
135
|
end
|
|
@@ -64,7 +145,7 @@ module Fontist
|
|
|
64
145
|
path = Fontist.formulas_path.join("#{key}.yml")
|
|
65
146
|
return unless File.exist?(path)
|
|
66
147
|
|
|
67
|
-
|
|
148
|
+
from_file(path)
|
|
68
149
|
end
|
|
69
150
|
|
|
70
151
|
def self.find_by_name(name)
|
|
@@ -78,30 +159,32 @@ module Fontist
|
|
|
78
159
|
end
|
|
79
160
|
|
|
80
161
|
def self.find_by_font_file(font_file)
|
|
81
|
-
key = Indexes::FilenameIndex
|
|
82
|
-
.from_yaml
|
|
162
|
+
key = Indexes::FilenameIndex.from_file
|
|
83
163
|
.load_index_formulas(File.basename(font_file))
|
|
84
|
-
.
|
|
164
|
+
.flat_map(&:name)
|
|
85
165
|
.first
|
|
86
166
|
|
|
87
167
|
find_by_key(key)
|
|
88
168
|
end
|
|
89
169
|
|
|
90
|
-
def self.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
170
|
+
def self.from_file(path)
|
|
171
|
+
unless File.exist?(path)
|
|
172
|
+
raise Fontist::Errors::FormulaCouldNotBeFoundError,
|
|
173
|
+
"Formula file not found: #{path}"
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
content = File.read(path)
|
|
97
177
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
178
|
+
from_yaml(content).tap do |formula|
|
|
179
|
+
formula.path = path
|
|
180
|
+
formula.name = titleize(formula.key_from_path) if formula.name.nil?
|
|
181
|
+
end
|
|
101
182
|
end
|
|
102
183
|
|
|
103
|
-
def
|
|
104
|
-
|
|
184
|
+
def self.titleize(str)
|
|
185
|
+
str.split("/").map do |part|
|
|
186
|
+
part.tr("_", " ").split.map(&:capitalize).join(" ")
|
|
187
|
+
end.join("/")
|
|
105
188
|
end
|
|
106
189
|
|
|
107
190
|
def manual?
|
|
@@ -109,118 +192,81 @@ module Fontist
|
|
|
109
192
|
end
|
|
110
193
|
|
|
111
194
|
def downloadable?
|
|
112
|
-
|
|
195
|
+
!resources.nil? && !resources.empty?
|
|
113
196
|
end
|
|
114
197
|
|
|
115
198
|
def source
|
|
116
|
-
return
|
|
199
|
+
return nil if resources.empty?
|
|
117
200
|
|
|
118
|
-
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def path
|
|
122
|
-
@path
|
|
201
|
+
resources.first.source
|
|
123
202
|
end
|
|
124
203
|
|
|
125
204
|
def key
|
|
126
|
-
@key ||=
|
|
127
|
-
@key[@path] ||= key_from_path
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def name
|
|
131
|
-
@name ||= {}
|
|
132
|
-
@name[key] ||= namespace.empty? ? base_name : "#{namespace}/#{base_name}"
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def description
|
|
136
|
-
@data["description"]
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def homepage
|
|
140
|
-
@data["homepage"]
|
|
205
|
+
@key ||= key_from_path
|
|
141
206
|
end
|
|
142
207
|
|
|
143
|
-
def
|
|
144
|
-
|
|
145
|
-
end
|
|
208
|
+
def key_from_path
|
|
209
|
+
return "" unless @path
|
|
146
210
|
|
|
147
|
-
|
|
148
|
-
@
|
|
211
|
+
escaped = Regexp.escape("#{Fontist.formulas_path}/")
|
|
212
|
+
@path.sub(Regexp.new("^#{escaped}"), "").sub(/\.yml$/, "").to_s
|
|
149
213
|
end
|
|
150
214
|
|
|
151
215
|
def license
|
|
152
|
-
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def license_required
|
|
156
|
-
@data["requires_license_agreement"] ? true : false
|
|
216
|
+
open_license || requires_license_agreement
|
|
157
217
|
end
|
|
158
218
|
|
|
159
|
-
def
|
|
160
|
-
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def min_fontist
|
|
164
|
-
@data["min_fontist"]
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def extract
|
|
168
|
-
Helpers.parse_to_object(@data["extract"])
|
|
219
|
+
def license_required?
|
|
220
|
+
requires_license_agreement ? true : false
|
|
169
221
|
end
|
|
170
222
|
|
|
171
223
|
def file_size
|
|
172
|
-
return
|
|
224
|
+
return nil if resources.nil? || resources.empty?
|
|
173
225
|
|
|
174
|
-
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
def resources
|
|
178
|
-
Helpers.parse_to_object(@data["resources"]&.values)
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def instructions
|
|
182
|
-
@data["instructions"]
|
|
226
|
+
resources.first.file_size
|
|
183
227
|
end
|
|
184
228
|
|
|
185
229
|
def font_by_name(name)
|
|
186
|
-
|
|
230
|
+
all_fonts.find do |font|
|
|
187
231
|
font.name.casecmp?(name)
|
|
188
232
|
end
|
|
189
233
|
end
|
|
190
234
|
|
|
191
235
|
def fonts_by_name(name)
|
|
192
|
-
|
|
236
|
+
all_fonts.select do |font|
|
|
193
237
|
font.name.casecmp?(name)
|
|
194
238
|
end
|
|
195
239
|
end
|
|
196
240
|
|
|
197
|
-
def
|
|
198
|
-
|
|
241
|
+
def all_fonts
|
|
242
|
+
Array(fonts) + collection_fonts
|
|
199
243
|
end
|
|
200
244
|
|
|
201
|
-
def
|
|
202
|
-
|
|
245
|
+
def collection_fonts
|
|
246
|
+
Array(font_collections).flat_map do |c|
|
|
247
|
+
c.fonts.flat_map do |f|
|
|
248
|
+
f.styles.each do |s|
|
|
249
|
+
s.font = c.filename
|
|
250
|
+
s.source_font = c.source_filename
|
|
251
|
+
end
|
|
252
|
+
f
|
|
253
|
+
end
|
|
254
|
+
end
|
|
203
255
|
end
|
|
204
256
|
|
|
205
257
|
def style_override(font)
|
|
206
|
-
|
|
258
|
+
all_fonts
|
|
207
259
|
.map(&:styles)
|
|
208
260
|
.flatten
|
|
209
|
-
.detect { |s| s.family_name == font }
|
|
210
|
-
&.dig(:override) || {}
|
|
261
|
+
.detect { |s| s.family_name == font }&.override || {}
|
|
211
262
|
end
|
|
212
263
|
|
|
213
264
|
private
|
|
214
265
|
|
|
215
|
-
def real_path
|
|
266
|
+
def real_path
|
|
216
267
|
Dir.glob(path).first
|
|
217
268
|
end
|
|
218
269
|
|
|
219
|
-
def key_from_path
|
|
220
|
-
escaped = Regexp.escape("#{Fontist.formulas_path}/")
|
|
221
|
-
@path.sub(Regexp.new("^#{escaped}"), "").sub(/\.yml$/, "").to_s
|
|
222
|
-
end
|
|
223
|
-
|
|
224
270
|
def namespace
|
|
225
271
|
namespace_from_mappings || namespace_from_key
|
|
226
272
|
end
|
|
@@ -248,14 +294,14 @@ module Fontist
|
|
|
248
294
|
.split.map(&:capitalize).join(" ")
|
|
249
295
|
end
|
|
250
296
|
|
|
251
|
-
def fonts_by_family
|
|
252
|
-
return hash_all_fonts unless Fontist.preferred_family?
|
|
297
|
+
def fonts_by_family(data)
|
|
298
|
+
return hash_all_fonts(data) unless Fontist.preferred_family?
|
|
253
299
|
|
|
254
|
-
preferred_family_fonts
|
|
300
|
+
preferred_family_fonts(data)
|
|
255
301
|
end
|
|
256
302
|
|
|
257
|
-
def preferred_family_fonts
|
|
258
|
-
groups = preferred_family_styles.group_by do |style|
|
|
303
|
+
def preferred_family_fonts(data)
|
|
304
|
+
groups = preferred_family_styles(data).group_by do |style|
|
|
259
305
|
style["family_name"]
|
|
260
306
|
end
|
|
261
307
|
|
|
@@ -264,8 +310,8 @@ module Fontist
|
|
|
264
310
|
end
|
|
265
311
|
end
|
|
266
312
|
|
|
267
|
-
def preferred_family_styles
|
|
268
|
-
hash_all_fonts.flat_map do |font|
|
|
313
|
+
def preferred_family_styles(data)
|
|
314
|
+
hash_all_fonts(data).flat_map do |font|
|
|
269
315
|
font["styles"].map do |style|
|
|
270
316
|
style.merge(preferred_style(style))
|
|
271
317
|
end
|
|
@@ -273,20 +319,22 @@ module Fontist
|
|
|
273
319
|
end
|
|
274
320
|
|
|
275
321
|
def preferred_style(style)
|
|
276
|
-
{
|
|
322
|
+
{
|
|
323
|
+
"family_name" => style["preferred_family_name"] || style["family_name"],
|
|
277
324
|
"type" => style["preferred_type"] || style["type"],
|
|
278
325
|
"default_family_name" => style["family_name"],
|
|
279
|
-
"default_type" => style["type"]
|
|
326
|
+
"default_type" => style["type"],
|
|
327
|
+
}
|
|
280
328
|
end
|
|
281
329
|
|
|
282
|
-
def hash_all_fonts
|
|
283
|
-
hash_collection_fonts + hash_fonts
|
|
330
|
+
def hash_all_fonts(data)
|
|
331
|
+
hash_collection_fonts(data) + hash_fonts(data)
|
|
284
332
|
end
|
|
285
333
|
|
|
286
|
-
def hash_collection_fonts
|
|
287
|
-
return [] unless
|
|
334
|
+
def hash_collection_fonts(data)
|
|
335
|
+
return [] unless data["font_collections"]
|
|
288
336
|
|
|
289
|
-
|
|
337
|
+
data["font_collections"].flat_map do |coll|
|
|
290
338
|
filenames = { "font" => coll["filename"],
|
|
291
339
|
"source_font" => coll["source_filename"] }
|
|
292
340
|
|
|
@@ -296,10 +344,19 @@ module Fontist
|
|
|
296
344
|
end
|
|
297
345
|
end
|
|
298
346
|
|
|
299
|
-
def hash_fonts
|
|
300
|
-
return [] unless
|
|
347
|
+
def hash_fonts(data)
|
|
348
|
+
return [] unless data["fonts"]
|
|
349
|
+
|
|
350
|
+
data["fonts"]
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
class FormulaCollection < Lutaml::Model::Collection
|
|
355
|
+
instances :formulas, Formula
|
|
301
356
|
|
|
302
|
-
|
|
357
|
+
key_value do
|
|
358
|
+
map "name", to: :name
|
|
359
|
+
map "formula", to: :formula
|
|
303
360
|
end
|
|
304
361
|
end
|
|
305
362
|
end
|
|
@@ -26,8 +26,8 @@ module Fontist
|
|
|
26
26
|
def fonts_attributes
|
|
27
27
|
{ display_progress_bar: formula_progress_bar(@formula),
|
|
28
28
|
resources: @formula.resources,
|
|
29
|
-
font_collections: font_collections(@formula.
|
|
30
|
-
fonts: standalone_fonts(@formula.
|
|
29
|
+
font_collections: font_collections(@formula.all_fonts),
|
|
30
|
+
fonts: standalone_fonts(@formula.all_fonts),
|
|
31
31
|
extract: extract_type(@code) }
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -122,11 +122,11 @@ module Fontist
|
|
|
122
122
|
# rubocop:enable Metrics/MethodLength, Metrics/LineLength
|
|
123
123
|
|
|
124
124
|
def requires_license_agreement(formula)
|
|
125
|
-
formula.license if formula.license && formula.license_required
|
|
125
|
+
formula.license if formula.license && formula.license_required?
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
def open_license(formula)
|
|
129
|
-
formula.license if formula.license && !formula.license_required
|
|
129
|
+
formula.license if formula.license && !formula.license_required?
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
end
|
data/lib/fontist/index.rb
CHANGED
|
@@ -1,20 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
require "lutaml/model"
|
|
2
2
|
require_relative "indexes/filename_index"
|
|
3
|
+
require_relative "indexes/font_index"
|
|
4
|
+
require_relative "indexes/default_family_font_index"
|
|
5
|
+
require_relative "indexes/preferred_family_font_index"
|
|
3
6
|
|
|
4
7
|
module Fontist
|
|
5
|
-
class
|
|
8
|
+
class IndexEntry < Lutaml::Model::Serializable
|
|
9
|
+
attribute :path, :string
|
|
10
|
+
attribute :full_name, :string
|
|
11
|
+
attribute :family_name, :string
|
|
12
|
+
attribute :style, :string
|
|
13
|
+
attribute :type, :string
|
|
14
|
+
attribute :source_font, :string
|
|
15
|
+
|
|
16
|
+
key_value do
|
|
17
|
+
map "path", to: :path
|
|
18
|
+
map "full_name", to: :full_name
|
|
19
|
+
map "family_name", to: :family_name
|
|
20
|
+
map "style", to: :style
|
|
21
|
+
map "type", to: :type
|
|
22
|
+
map "source_font", to: :source_font
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class Index < Lutaml::Model::Collection
|
|
27
|
+
instances :entries, IndexEntry
|
|
28
|
+
|
|
29
|
+
key_value do
|
|
30
|
+
map_instances to: :entries
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.from_file(path)
|
|
34
|
+
return new unless File.exist?(path)
|
|
35
|
+
|
|
36
|
+
content = File.read(path)
|
|
37
|
+
from_yaml(content)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_file(path)
|
|
41
|
+
File.write(path, to_yaml)
|
|
42
|
+
end
|
|
43
|
+
|
|
6
44
|
def self.rebuild
|
|
7
|
-
Fontist::Indexes::DefaultFamilyFontIndex.rebuild
|
|
8
|
-
Fontist::Indexes::PreferredFamilyFontIndex.rebuild
|
|
9
|
-
Fontist::Indexes::FilenameIndex.rebuild
|
|
45
|
+
Fontist::Indexes::DefaultFamilyFontIndex.rebuild.to_file
|
|
46
|
+
Fontist::Indexes::PreferredFamilyFontIndex.rebuild.to_file
|
|
47
|
+
Fontist::Indexes::FilenameIndex.rebuild.to_file
|
|
10
48
|
|
|
11
49
|
reset_cache
|
|
12
50
|
end
|
|
13
51
|
|
|
52
|
+
# TODO: Uncomment all lines when each fixed
|
|
14
53
|
def self.reset_cache
|
|
15
|
-
Fontist::Indexes::DefaultFamilyFontIndex.reset_cache
|
|
16
|
-
Fontist::Indexes::PreferredFamilyFontIndex.reset_cache
|
|
17
|
-
Fontist::Indexes::FilenameIndex.reset_cache
|
|
54
|
+
# Fontist::Indexes::DefaultFamilyFontIndex.reset_cache
|
|
55
|
+
# Fontist::Indexes::PreferredFamilyFontIndex.reset_cache
|
|
56
|
+
# Fontist::Indexes::FilenameIndex.reset_cache
|
|
18
57
|
end
|
|
19
58
|
end
|
|
20
59
|
end
|
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
require "lutaml/model"
|
|
2
|
+
require_relative "index_mixin"
|
|
3
|
+
require_relative "formula_key_to_path"
|
|
2
4
|
|
|
3
5
|
module Fontist
|
|
4
6
|
module Indexes
|
|
5
|
-
|
|
7
|
+
# YAML file structure:
|
|
8
|
+
# ---
|
|
9
|
+
# adobe arabic:
|
|
10
|
+
# - adobe_reader_19.yml
|
|
11
|
+
# myriad pro:
|
|
12
|
+
# - adobe_reader_20.yml
|
|
13
|
+
# akabara-cinderella:
|
|
14
|
+
# - akabara-cinderella.yml
|
|
15
|
+
# andale mono:
|
|
16
|
+
# - andale.yml
|
|
17
|
+
# - macos/andale_mono.yml
|
|
18
|
+
# - opensuse_webcore_fonts.yml
|
|
19
|
+
# - pclinuxos_webcore_fonts.yml
|
|
20
|
+
class DefaultFamilyFontIndex < Lutaml::Model::Collection
|
|
21
|
+
include IndexMixin
|
|
22
|
+
instances :entries, FormulaKeyToPath
|
|
23
|
+
|
|
24
|
+
key_value do
|
|
25
|
+
map_key to_instance: :key
|
|
26
|
+
map_value as_attribute: :formula_path
|
|
27
|
+
map_instances to: :entries
|
|
28
|
+
end
|
|
29
|
+
|
|
6
30
|
def self.path
|
|
7
31
|
Fontist.formula_index_path
|
|
8
32
|
end
|
|
9
33
|
|
|
10
|
-
def
|
|
11
|
-
|
|
12
|
-
font.styles.each do |style|
|
|
13
|
-
font_name = style.default_family_name || font.name
|
|
14
|
-
add_index_formula(font_name, formula.to_index_formula)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
34
|
+
def index_key_for_style(style)
|
|
35
|
+
style.default_family_name || style.family_name
|
|
17
36
|
end
|
|
18
37
|
|
|
19
38
|
def normalize_key(key)
|
|
@@ -1,18 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
require "lutaml/model"
|
|
2
|
+
require_relative "index_mixin"
|
|
3
|
+
require_relative "formula_key_to_path"
|
|
2
4
|
|
|
3
5
|
module Fontist
|
|
4
6
|
module Indexes
|
|
5
|
-
|
|
7
|
+
# YAML file structure:
|
|
8
|
+
# ---
|
|
9
|
+
# AdobeArabic_Bold.otf:
|
|
10
|
+
# - adobe_reader_19.yml
|
|
11
|
+
# AdobeArabic_BoldItalic.otf:
|
|
12
|
+
# - adobe_reader_19.yml
|
|
13
|
+
# AdobeArabic_Italic.otf:
|
|
14
|
+
# - adobe_reader_19.yml
|
|
15
|
+
# AdobeArabic_Regular.otf:
|
|
16
|
+
# - adobe_reader_19.yml
|
|
17
|
+
# adobedevanagari_bold.otf:
|
|
18
|
+
# - adobe_reader_19.yml
|
|
19
|
+
class FilenameIndex < Lutaml::Model::Collection
|
|
20
|
+
include IndexMixin
|
|
21
|
+
instances :entries, FormulaKeyToPath
|
|
22
|
+
|
|
23
|
+
key_value do
|
|
24
|
+
map_key to_instance: :key
|
|
25
|
+
map_value as_attribute: :formula_path
|
|
26
|
+
map_instances to: :entries
|
|
27
|
+
end
|
|
28
|
+
|
|
6
29
|
def self.path
|
|
7
30
|
Fontist.formula_filename_index_path
|
|
8
31
|
end
|
|
9
32
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
## Fonts
|
|
34
|
+
# fonts:
|
|
35
|
+
# - name: Adobe Pi Std
|
|
36
|
+
# styles:
|
|
37
|
+
# - family_name: Adobe Pi Std
|
|
38
|
+
# type: Regular
|
|
39
|
+
|
|
40
|
+
## Font collections
|
|
41
|
+
# font_collections:
|
|
42
|
+
# - filename: AdelleSans.ttc
|
|
43
|
+
# fonts:
|
|
44
|
+
# - name: Adelle Sans Devanagari
|
|
45
|
+
# styles:
|
|
46
|
+
|
|
47
|
+
def index_key_for_style(style)
|
|
48
|
+
style.font
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def normalize_key(key)
|
|
52
|
+
key
|
|
16
53
|
end
|
|
17
54
|
end
|
|
18
55
|
end
|
|
@@ -4,11 +4,11 @@ require_relative "preferred_family_font_index"
|
|
|
4
4
|
module Fontist
|
|
5
5
|
module Indexes
|
|
6
6
|
class FontIndex
|
|
7
|
-
def self.
|
|
7
|
+
def self.from_file
|
|
8
8
|
if Fontist.preferred_family?
|
|
9
|
-
PreferredFamilyFontIndex.
|
|
9
|
+
PreferredFamilyFontIndex.from_file
|
|
10
10
|
else
|
|
11
|
-
DefaultFamilyFontIndex.
|
|
11
|
+
DefaultFamilyFontIndex.from_file
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|