fontist 1.1.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/check_google.yml +28 -0
- data/.github/workflows/macosx.yml +3 -0
- data/.github/workflows/ubuntu.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/.gitignore +6 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +22 -0
- data/README.md +224 -0
- data/bin/check_google +8 -0
- data/bin/convert_formulas +8 -0
- data/bin/fontist +8 -0
- data/bin/generate_otfinfo +8 -0
- data/bin/import_google +8 -0
- data/fontist.gemspec +16 -1
- data/lib/fontist.rb +23 -13
- data/lib/fontist/cli.rb +156 -0
- data/lib/fontist/errors.rb +7 -1
- data/lib/fontist/font.rb +165 -6
- data/lib/fontist/font_formula.rb +8 -4
- data/lib/fontist/fontist_font.rb +70 -0
- data/lib/fontist/formula.rb +27 -9
- data/lib/fontist/formula_template.rb +108 -0
- data/lib/fontist/formulas.rb +41 -0
- data/lib/fontist/import.rb +9 -0
- data/lib/fontist/import/convert_formulas.rb +65 -0
- data/lib/fontist/import/create_formula.rb +74 -0
- data/lib/fontist/import/extractors.rb +5 -0
- data/lib/fontist/import/extractors/cab_extractor.rb +37 -0
- data/lib/fontist/import/extractors/extractor.rb +19 -0
- data/lib/fontist/import/extractors/ole_extractor.rb +41 -0
- data/lib/fontist/import/extractors/seven_zip_extractor.rb +44 -0
- data/lib/fontist/import/extractors/zip_extractor.rb +31 -0
- data/lib/fontist/import/files/collection_file.rb +47 -0
- data/lib/fontist/import/formula_builder.rb +156 -0
- data/lib/fontist/import/formula_serializer.rb +133 -0
- data/lib/fontist/import/google.rb +16 -0
- data/lib/fontist/import/google/fonts_public.md +10 -0
- data/lib/fontist/import/google/fonts_public.pb.rb +71 -0
- data/lib/fontist/import/google/fonts_public.proto +46 -0
- data/lib/fontist/import/google/new_fonts_fetcher.rb +121 -0
- data/lib/fontist/import/google/skiplist.yml +6 -0
- data/lib/fontist/import/google_check.rb +34 -0
- data/lib/fontist/import/google_import.rb +180 -0
- data/lib/fontist/import/helpers/hash_helper.rb +13 -0
- data/lib/fontist/import/helpers/system_helper.rb +23 -0
- data/lib/fontist/import/otf/font_file.rb +89 -0
- data/lib/fontist/import/otf_parser.rb +25 -0
- data/lib/fontist/import/otf_style.rb +29 -0
- data/lib/fontist/import/otfinfo/otfinfo_requirement.rb +22 -0
- data/lib/fontist/import/otfinfo/template.erb +20 -0
- data/lib/fontist/import/otfinfo_generate.rb +45 -0
- data/lib/fontist/import/recursive_extraction.rb +101 -0
- data/lib/fontist/import/template_helper.rb +19 -0
- data/lib/fontist/import/text_helper.rb +30 -0
- data/lib/fontist/manifest.rb +2 -0
- data/lib/fontist/manifest/common.rb +60 -0
- data/lib/fontist/manifest/install.rb +36 -0
- data/lib/fontist/manifest/locations.rb +13 -0
- data/lib/fontist/registry.rb +1 -0
- data/lib/fontist/system.yml +4 -1
- data/lib/fontist/system_font.rb +62 -22
- data/lib/fontist/utils.rb +5 -0
- data/lib/fontist/utils/cache.rb +69 -0
- data/lib/fontist/utils/downloader.rb +24 -4
- data/lib/fontist/utils/dsl.rb +4 -0
- data/lib/fontist/utils/dsl/font.rb +37 -0
- data/lib/fontist/utils/exe_extractor.rb +12 -19
- data/lib/fontist/utils/msi_extractor.rb +31 -0
- data/lib/fontist/utils/seven_zip_extractor.rb +41 -0
- data/lib/fontist/utils/system.rb +23 -0
- data/lib/fontist/utils/ui.rb +23 -0
- data/lib/fontist/utils/zip_extractor.rb +9 -4
- data/lib/fontist/version.rb +1 -1
- metadata +186 -49
- data/lib/fontist/formulas/andale_font.rb +0 -79
- data/lib/fontist/formulas/arial_black_font.rb +0 -78
- data/lib/fontist/formulas/cleartype_fonts.rb +0 -226
- data/lib/fontist/formulas/comic_font.rb +0 -77
- data/lib/fontist/formulas/courier_font.rb +0 -80
- data/lib/fontist/formulas/euphemia_font.rb +0 -85
- data/lib/fontist/formulas/georgia_font.rb +0 -79
- data/lib/fontist/formulas/impact_font.rb +0 -77
- data/lib/fontist/formulas/montserrat_font.rb +0 -132
- data/lib/fontist/formulas/ms_truetype_fonts.rb +0 -124
- data/lib/fontist/formulas/open_sans_fonts.rb +0 -263
- data/lib/fontist/formulas/overpass_font.rb +0 -73
- data/lib/fontist/formulas/source_fonts.rb +0 -109
- data/lib/fontist/formulas/stix_fonts.rb +0 -108
- data/lib/fontist/formulas/tahoma_font.rb +0 -147
- data/lib/fontist/formulas/webding_font.rb +0 -77
- data/spec/fontist/font_formula_spec.rb +0 -67
- data/spec/fontist/font_spec.rb +0 -87
- data/spec/fontist/formula_spec.rb +0 -67
- data/spec/fontist/formulas/andale_font_spec.rb +0 -29
- data/spec/fontist/formulas/arial_black_font_spec.rb +0 -29
- data/spec/fontist/formulas/cleartype_fonts_spec.rb +0 -38
- data/spec/fontist/formulas/comic_font_spec.rb +0 -29
- data/spec/fontist/formulas/courier_font_spec.rb +0 -29
- data/spec/fontist/formulas/euphemia_font_spec.rb +0 -29
- data/spec/fontist/formulas/georgia_font_spec.rb +0 -29
- data/spec/fontist/formulas/impact_font_spec.rb +0 -29
- data/spec/fontist/formulas/montserrat_font_spec.rb +0 -29
- data/spec/fontist/formulas/ms_truetype_fonts_spec.rb +0 -29
- data/spec/fontist/formulas/open_sans_fonts_spec.rb +0 -29
- data/spec/fontist/formulas/overpass_font_spec.rb +0 -29
- data/spec/fontist/formulas/source_fonts_spec.rb +0 -31
- data/spec/fontist/formulas/stix_fonts_spec.rb +0 -29
- data/spec/fontist/formulas/tahoma_font_spec.rb +0 -29
- data/spec/fontist/formulas/webding_font_spec.rb +0 -29
- data/spec/fontist/registry_spec.rb +0 -47
- data/spec/fontist/system_font_spec.rb +0 -44
- data/spec/fontist/utils/downloader_spec.rb +0 -35
- data/spec/fontist_spec.rb +0 -5
- data/spec/spec_helper.rb +0 -22
- data/spec/support/fontist_helper.rb +0 -10
data/lib/fontist/cli.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module Fontist
|
4
|
+
class CLI < Thor
|
5
|
+
STATUS_SUCCESS = 0
|
6
|
+
STATUS_ERROR = 1
|
7
|
+
|
8
|
+
def self.exit_on_failure?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "install FONT", "Install font by font or formula"
|
13
|
+
option :force, type: :boolean, aliases: :f,
|
14
|
+
desc: "Install even if it's already installed in system"
|
15
|
+
def install(font)
|
16
|
+
fonts_paths = Fontist::Font.install(font, force: options[:force])
|
17
|
+
Fontist.ui.success("These fonts are found or installed:")
|
18
|
+
Fontist.ui.success(fonts_paths.join("\n"))
|
19
|
+
STATUS_SUCCESS
|
20
|
+
rescue Fontist::Errors::NonSupportedFontError
|
21
|
+
Fontist.ui.error("Could not find font '#{font}'.")
|
22
|
+
STATUS_ERROR
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "uninstall/remove FONT", "Uninstall font by font or formula"
|
26
|
+
def uninstall(font)
|
27
|
+
fonts_paths = Fontist::Font.uninstall(font)
|
28
|
+
Fontist.ui.success("These fonts are removed:")
|
29
|
+
Fontist.ui.success(fonts_paths.join("\n"))
|
30
|
+
STATUS_SUCCESS
|
31
|
+
rescue Fontist::Errors::MissingFontError => e
|
32
|
+
Fontist.ui.error(e.message)
|
33
|
+
STATUS_ERROR
|
34
|
+
rescue Fontist::Errors::NonSupportedFontError
|
35
|
+
Fontist.ui.error("Could not find font '#{font}'.")
|
36
|
+
STATUS_ERROR
|
37
|
+
end
|
38
|
+
map remove: :uninstall
|
39
|
+
|
40
|
+
desc "status [FONT]", "Show status of FONT or all fonts in fontist"
|
41
|
+
def status(font = nil)
|
42
|
+
formulas = Fontist::Font.status(font)
|
43
|
+
return error("No font is installed.") if formulas.empty?
|
44
|
+
|
45
|
+
print_formulas(formulas)
|
46
|
+
success
|
47
|
+
rescue Fontist::Errors::MissingFontError => e
|
48
|
+
error(e.message)
|
49
|
+
rescue Fontist::Errors::NonSupportedFontError
|
50
|
+
error("Could not find font '#{font}'.")
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "list [FONT]", "List installation status of FONT or fonts in fontist"
|
54
|
+
def list(font = nil)
|
55
|
+
formulas = Fontist::Font.list(font)
|
56
|
+
print_list(formulas)
|
57
|
+
success
|
58
|
+
rescue Fontist::Errors::NonSupportedFontError
|
59
|
+
error("Could not find font '#{font}'.")
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "update", "Update formulas"
|
63
|
+
def update
|
64
|
+
Formulas.fetch_formulas
|
65
|
+
Fontist.ui.say("Formulas have been successfully updated")
|
66
|
+
STATUS_SUCCESS
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "manifest-locations MANIFEST",
|
70
|
+
"Get locations of fonts from MANIFEST (yaml)"
|
71
|
+
def manifest_locations(manifest)
|
72
|
+
paths = Fontist::Manifest::Locations.call(manifest)
|
73
|
+
print_yaml(paths)
|
74
|
+
success
|
75
|
+
rescue Fontist::Errors::ManifestCouldNotBeFoundError
|
76
|
+
error("Manifest could not be found.")
|
77
|
+
rescue Fontist::Errors::ManifestCouldNotBeReadError
|
78
|
+
error("Manifest could not be read.")
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "manifest-install MANIFEST", "Install fonts from MANIFEST (yaml)"
|
82
|
+
option :confirm_license, type: :boolean, desc: "Confirm license agreement"
|
83
|
+
def manifest_install(manifest)
|
84
|
+
paths = Fontist::Manifest::Install.call(
|
85
|
+
manifest,
|
86
|
+
confirmation: options[:confirm_license] ? "yes" : "no"
|
87
|
+
)
|
88
|
+
|
89
|
+
print_yaml(paths)
|
90
|
+
success
|
91
|
+
rescue Fontist::Errors::ManifestCouldNotBeFoundError
|
92
|
+
error("Manifest could not be found.")
|
93
|
+
rescue Fontist::Errors::ManifestCouldNotBeReadError
|
94
|
+
error("Manifest could not be read.")
|
95
|
+
end
|
96
|
+
|
97
|
+
desc "create-formula URL", "Create a new formula with fonts from URL"
|
98
|
+
option :name, desc: "Example: Times New Roman"
|
99
|
+
option :mirror, repeatable: true
|
100
|
+
def create_formula(url)
|
101
|
+
require "fontist/import/create_formula"
|
102
|
+
name = Fontist::Import::CreateFormula.new(url, options).call
|
103
|
+
Fontist.ui.say("#{name} formula has been successfully created")
|
104
|
+
STATUS_SUCCESS
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def success
|
110
|
+
STATUS_SUCCESS
|
111
|
+
end
|
112
|
+
|
113
|
+
def error(message)
|
114
|
+
Fontist.ui.error(message)
|
115
|
+
STATUS_ERROR
|
116
|
+
end
|
117
|
+
|
118
|
+
def print_yaml(object)
|
119
|
+
Fontist.ui.say(YAML.dump(object))
|
120
|
+
end
|
121
|
+
|
122
|
+
def print_formulas(formulas)
|
123
|
+
formulas.each do |formula, fonts|
|
124
|
+
Fontist.ui.success(formula.installer)
|
125
|
+
|
126
|
+
fonts.each do |font, styles|
|
127
|
+
Fontist.ui.success(" #{font.name}")
|
128
|
+
|
129
|
+
styles.each do |style, path|
|
130
|
+
Fontist.ui.success(" #{style.type} (#{path})")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
137
|
+
def print_list(formulas)
|
138
|
+
formulas.each do |formula, fonts|
|
139
|
+
Fontist.ui.say(formula.installer)
|
140
|
+
|
141
|
+
fonts.each do |font, styles|
|
142
|
+
Fontist.ui.say(" #{font.name}")
|
143
|
+
|
144
|
+
styles.each do |style, installed|
|
145
|
+
if installed
|
146
|
+
Fontist.ui.success(" #{style.type} (installed)")
|
147
|
+
else
|
148
|
+
Fontist.ui.error(" #{style.type} (uninstalled)")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
155
|
+
end
|
156
|
+
end
|
data/lib/fontist/errors.rb
CHANGED
@@ -3,7 +3,13 @@ module Fontist
|
|
3
3
|
class LicensingError < StandardError; end
|
4
4
|
class MissingFontError < StandardError; end
|
5
5
|
class NonSupportedFontError < StandardError; end
|
6
|
-
class
|
6
|
+
class TamperedFileError < StandardError; end
|
7
7
|
class InvalidResourceError < StandardError; end
|
8
|
+
class TimeoutError < StandardError; end
|
9
|
+
class MissingAttributeError < StandardError; end
|
10
|
+
class FontNotFoundError < StandardError; end
|
11
|
+
class BinaryCallError < StandardError; end
|
12
|
+
class ManifestCouldNotBeReadError < StandardError; end
|
13
|
+
class ManifestCouldNotBeFoundError < StandardError; end
|
8
14
|
end
|
9
15
|
end
|
data/lib/fontist/font.rb
CHANGED
@@ -3,6 +3,7 @@ module Fontist
|
|
3
3
|
def initialize(options = {})
|
4
4
|
@name = options.fetch(:name, nil)
|
5
5
|
@confirmation = options.fetch(:confirmation, "no")
|
6
|
+
@force = options.fetch(:force, false)
|
6
7
|
|
7
8
|
check_or_create_fontist_path!
|
8
9
|
end
|
@@ -15,8 +16,24 @@ module Fontist
|
|
15
16
|
new(name: name).find
|
16
17
|
end
|
17
18
|
|
18
|
-
def self.install(name, confirmation: "no")
|
19
|
-
new(name: name, confirmation: confirmation).install
|
19
|
+
def self.install(name, confirmation: "no", force: false)
|
20
|
+
new(name: name, confirmation: confirmation, force: force).install
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.try_install(name, confirmation: "no")
|
24
|
+
new(name: name, confirmation: confirmation).try_install
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.uninstall(name)
|
28
|
+
new(name: name).uninstall
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.status(name)
|
32
|
+
new(name: name).status
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.list(name)
|
36
|
+
new(name: name).list
|
20
37
|
end
|
21
38
|
|
22
39
|
def find
|
@@ -26,11 +43,35 @@ module Fontist
|
|
26
43
|
end
|
27
44
|
|
28
45
|
def install
|
29
|
-
find_system_font || download_font || raise(
|
46
|
+
(find_system_font unless @force) || download_font || raise(
|
47
|
+
Fontist::Errors::NonSupportedFontError
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def try_install
|
52
|
+
download_font
|
53
|
+
end
|
54
|
+
|
55
|
+
def uninstall
|
56
|
+
uninstall_font || downloadable_font || raise(
|
30
57
|
Fontist::Errors::NonSupportedFontError
|
31
58
|
)
|
32
59
|
end
|
33
60
|
|
61
|
+
def status
|
62
|
+
return installed_statuses unless @name
|
63
|
+
|
64
|
+
font_status || downloadable_font || raise(
|
65
|
+
Fontist::Errors::NonSupportedFontError
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def list
|
70
|
+
return all_list unless @name
|
71
|
+
|
72
|
+
font_list || raise(Fontist::Errors::NonSupportedFontError)
|
73
|
+
end
|
74
|
+
|
34
75
|
def all
|
35
76
|
Fontist::Formula.all.to_h.map { |_name, formula| formula.fonts }.flatten
|
36
77
|
end
|
@@ -62,17 +103,135 @@ module Fontist
|
|
62
103
|
if formula
|
63
104
|
raise(
|
64
105
|
Fontist::Errors::MissingFontError,
|
65
|
-
"
|
66
|
-
"
|
67
|
-
"download the font"
|
106
|
+
"#{name} fonts are missing, please run " \
|
107
|
+
"`fontist install '#{name}'` to " \
|
108
|
+
"download the font."
|
68
109
|
)
|
69
110
|
end
|
70
111
|
end
|
71
112
|
|
72
113
|
def download_font
|
73
114
|
if formula
|
115
|
+
check_and_confirm_required_license(formula)
|
74
116
|
font_installer(formula).fetch_font(name, confirmation: confirmation)
|
75
117
|
end
|
76
118
|
end
|
119
|
+
|
120
|
+
def check_and_confirm_required_license(formula)
|
121
|
+
if formula.license_required && !confirmation.casecmp("yes").zero?
|
122
|
+
@confirmation = show_license_and_ask_for_input(formula.license)
|
123
|
+
|
124
|
+
if !confirmation.casecmp("yes").zero?
|
125
|
+
raise Fontist::Errors::LicensingError.new(
|
126
|
+
"Fontist will not download these fonts unless you accept the terms."
|
127
|
+
)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def show_license_and_ask_for_input(license)
|
133
|
+
Fontist.ui.say(license_agrement_message(license))
|
134
|
+
Fontist.ui.ask(
|
135
|
+
"\nDo you accept all presented font licenses, and want Fontist " \
|
136
|
+
"to download these fonts for you? => TYPE 'Yes' or 'No':"
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
def license_agrement_message(license)
|
141
|
+
<<~MSG
|
142
|
+
FONT LICENSE ACCEPTANCE REQUIRED FOR "#{name}":
|
143
|
+
|
144
|
+
Fontist can install this font if you accept its licensing conditions.
|
145
|
+
|
146
|
+
FONT LICENSE BEGIN ("#{name}")
|
147
|
+
-----------------------------------------------------------------------
|
148
|
+
#{license}
|
149
|
+
-----------------------------------------------------------------------
|
150
|
+
FONT LICENSE END ("#{name}")
|
151
|
+
MSG
|
152
|
+
end
|
153
|
+
|
154
|
+
def uninstall_font
|
155
|
+
paths = find_fontist_font
|
156
|
+
return unless paths
|
157
|
+
|
158
|
+
paths.each do |path|
|
159
|
+
File.delete(path)
|
160
|
+
end
|
161
|
+
|
162
|
+
paths
|
163
|
+
end
|
164
|
+
|
165
|
+
def find_fontist_font
|
166
|
+
Fontist::FontistFont.find(name)
|
167
|
+
end
|
168
|
+
|
169
|
+
def installed_statuses
|
170
|
+
installed_styles(all_formulas)
|
171
|
+
end
|
172
|
+
|
173
|
+
def all_formulas
|
174
|
+
Fontist::Formula.all.to_h.values
|
175
|
+
end
|
176
|
+
|
177
|
+
def font_status
|
178
|
+
return unless formula
|
179
|
+
|
180
|
+
statuses = installed_styles([formula])
|
181
|
+
statuses.empty? ? nil : statuses
|
182
|
+
end
|
183
|
+
|
184
|
+
def installed_styles(formulas)
|
185
|
+
filter_blank(formulas) do |formula|
|
186
|
+
filter_blank(formula.fonts) do |font|
|
187
|
+
filter_blank(font.styles) do |style|
|
188
|
+
path(style)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def filter_blank(elements)
|
195
|
+
elements.map { |e| [e, yield(e)] }
|
196
|
+
.to_h
|
197
|
+
.reject { |_k, v| v.nil? || v.empty? }
|
198
|
+
end
|
199
|
+
|
200
|
+
def path(style)
|
201
|
+
font_paths.grep(/#{style.font}/i).first
|
202
|
+
end
|
203
|
+
|
204
|
+
def font_paths
|
205
|
+
@font_paths ||= Dir.glob(Fontist.fonts_path.join("**"))
|
206
|
+
end
|
207
|
+
|
208
|
+
def all_list
|
209
|
+
list_styles(all_formulas)
|
210
|
+
end
|
211
|
+
|
212
|
+
def font_list
|
213
|
+
return unless formula
|
214
|
+
|
215
|
+
list_styles([formula])
|
216
|
+
end
|
217
|
+
|
218
|
+
def list_styles(formulas)
|
219
|
+
map_to_hash(formulas) do |formula|
|
220
|
+
map_to_hash(formula.fonts) do |font|
|
221
|
+
map_to_hash(font.styles) do |style|
|
222
|
+
installed(style)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def map_to_hash(elements)
|
229
|
+
elements.map { |e| [e, yield(e)] }.to_h
|
230
|
+
end
|
231
|
+
|
232
|
+
def installed(style)
|
233
|
+
path(style) ? true : false
|
234
|
+
end
|
235
|
+
|
77
236
|
end
|
78
237
|
end
|
data/lib/fontist/font_formula.rb
CHANGED
@@ -4,8 +4,10 @@ module Fontist
|
|
4
4
|
extend Fontist::Utils::Dsl
|
5
5
|
include Fontist::Utils::ZipExtractor
|
6
6
|
include Fontist::Utils::ExeExtractor
|
7
|
+
include Fontist::Utils::MsiExtractor
|
8
|
+
include Fontist::Utils::SevenZipExtractor
|
7
9
|
|
8
|
-
attr_accessor :license, :license_url, :license_required
|
10
|
+
attr_accessor :license, :license_url, :license_required, :copyright
|
9
11
|
attr_accessor :key, :homepage, :description, :options, :temp_resource
|
10
12
|
|
11
13
|
def font_list
|
@@ -55,7 +57,7 @@ module Fontist
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def fonts_path
|
58
|
-
@fonts_path
|
60
|
+
@fonts_path = Fontist.fonts_path
|
59
61
|
end
|
60
62
|
|
61
63
|
def default_font
|
@@ -75,7 +77,9 @@ module Fontist
|
|
75
77
|
styles = options.fetch(:match_styles_from_file, [])
|
76
78
|
|
77
79
|
unless styles.empty?
|
78
|
-
styles.map
|
80
|
+
styles.map do |attributes|
|
81
|
+
Fontist::Utils::Dsl::Font.new(attributes).attributes
|
82
|
+
end
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
@@ -106,7 +110,7 @@ module Fontist
|
|
106
110
|
|
107
111
|
def download_file(source)
|
108
112
|
downloaded_file = Fontist::Utils::Downloader.download(
|
109
|
-
source[:urls].
|
113
|
+
source[:urls].first,
|
110
114
|
sha: source[:sha256],
|
111
115
|
file_size: source[:file_size],
|
112
116
|
progress_bar: is_progress_bar_enabled
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Fontist
|
2
|
+
class FontistFont
|
3
|
+
def initialize(font_name:)
|
4
|
+
@font_name = font_name
|
5
|
+
|
6
|
+
check_and_register_font_formulas
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.find(name)
|
10
|
+
new(font_name: name).find
|
11
|
+
end
|
12
|
+
|
13
|
+
def find
|
14
|
+
return unless @font_name
|
15
|
+
|
16
|
+
filenames = fonts_filenames
|
17
|
+
return if filenames.empty?
|
18
|
+
|
19
|
+
paths = font_paths.select do |path|
|
20
|
+
filenames.any? { |f| File.basename(path).casecmp?(f) }
|
21
|
+
end
|
22
|
+
|
23
|
+
paths.empty? ? nil : paths
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def fonts_filenames
|
29
|
+
fonts.map { |font| font.styles.map(&:font) }.flatten
|
30
|
+
end
|
31
|
+
|
32
|
+
def fonts
|
33
|
+
by_key || by_name || []
|
34
|
+
end
|
35
|
+
|
36
|
+
def by_key
|
37
|
+
_key, formula = formulas.detect do |key, _value|
|
38
|
+
key.to_s.casecmp?(@font_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
return unless formula
|
42
|
+
|
43
|
+
formula.fonts
|
44
|
+
end
|
45
|
+
|
46
|
+
def by_name
|
47
|
+
_key, formula = formulas.detect do |_key, value|
|
48
|
+
value.fonts.map(&:name).map(&:downcase).include?(@font_name.downcase)
|
49
|
+
end
|
50
|
+
|
51
|
+
return unless formula
|
52
|
+
|
53
|
+
formula.fonts.select do |font|
|
54
|
+
font.name.casecmp?(@font_name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def formulas
|
59
|
+
@formulas ||= Fontist::Registry.instance.formulas.to_h
|
60
|
+
end
|
61
|
+
|
62
|
+
def font_paths
|
63
|
+
Dir.glob(Fontist.fonts_path.join("**"))
|
64
|
+
end
|
65
|
+
|
66
|
+
def check_and_register_font_formulas
|
67
|
+
$check_and_register_font_formulas ||= Fontist::Formulas.register_formulas
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|