fontist 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02323a2a83176e79be999c101277ab2d777986b07185ca8d18bbd47c0bae88ec
4
- data.tar.gz: c5909e4220f762be25a22fe776f4273ef2affa44b68c3f16d6d181b83cfcf287
3
+ metadata.gz: 398c687688ac621dd160d7245b073764e5203ec1993b4d0db185e9b1ba82ec78
4
+ data.tar.gz: 20222086aaa6372fcab4c4f8726821bbeffc1808f939b498bfb369130da9218c
5
5
  SHA512:
6
- metadata.gz: 831d21fc0882000bf30003193d8b4bacf8bbe002c8d07bebb1b36ab05cf552cbd844f0ddd0998beb59bc059e54ed365f92e79020c673130a90b61d3db515a2d7
7
- data.tar.gz: 88f6a870cda4177824d9c5499250e5a45a088afc269e185a942c71bd02ea4589539473e72445a13c38265e7de091a6ca95ffcbde37c4bed08c87c251a02f4cb8
6
+ metadata.gz: 60cae1ca82451a485a94ef95c9472dfe78e7dc8d30df79b3bcf44eb9c4861826ab6f59f8caf030008af2278bed8b2eb0a6ac061e8556c73949fb359b0bfc85c8
7
+ data.tar.gz: b702b24e7da4f8ac71ad0fa347a50e73d09171954b986fc2c0cbf8cd206642aed6b770de7e32db4f86e2e409289d401cd9c7d09fe64f775769c38b03038b585e
data/README.md CHANGED
@@ -132,6 +132,182 @@ The return values are ` OpenStruct` object, so you can easily do any other
132
132
  operation you would do in any ruby object.
133
133
 
134
134
 
135
+ ### Manifest
136
+
137
+ #### Locations
138
+
139
+ Fontist lets find font locations from a YAML manifest of the following format:
140
+
141
+ ```yml
142
+ Segoe UI:
143
+ - Regular
144
+ - Bold
145
+ Roboto Mono:
146
+ - Regular
147
+ ```
148
+
149
+ Calling the following code returns a nested hash with font paths.
150
+
151
+ ```ruby
152
+ Fontist::Manifest::Locations.call(manifest_path)
153
+ ```
154
+
155
+ ```ruby
156
+ {"Segoe UI"=>
157
+ {"Regular"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"],
158
+ "Bold"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]},
159
+ "Roboto Mono"=>
160
+ {"Regular"=>[]}}
161
+ ```
162
+
163
+ #### Install
164
+
165
+ Fontist lets not only to get font locations but also to install fonts from the
166
+ manifest:
167
+
168
+ ```ruby
169
+ Fontist::Manifest::Install.call(manifest, confirmation: "yes")
170
+ ```
171
+
172
+ It will install fonts and return their locations:
173
+
174
+ ```ruby
175
+ {"Segoe UI"=>
176
+ {"Regular"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"],
177
+ "Bold"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]},
178
+ "Roboto Mono"=>
179
+ {"Regular"=>["/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"]}}
180
+ ```
181
+
182
+ ### CLI
183
+
184
+ These commands makes possible to operate with fonts via command line. The CLI
185
+ properly supports exit status, so in a case of error it returns a status code
186
+ higher or equal than 1.
187
+
188
+ All searches are case-insensitive for ease of use.
189
+
190
+ #### Install
191
+
192
+ The `install` command is similar to the `Font.install` call. It first checks
193
+ whether this font is already installed, and if not, then installs the font and
194
+ returns its paths. Font or formula could be specified as a name.
195
+
196
+ ```
197
+ $ fontist install "segoe ui"
198
+ These fonts are found or installed:
199
+ /Users/user/.fontist/fonts/SEGOEUI.TTF
200
+ /Users/user/.fontist/fonts/SEGOEUIB.TTF
201
+ /Users/user/.fontist/fonts/SEGOEUII.TTF
202
+ /Users/user/.fontist/fonts/SEGOEUIZ.TTF
203
+ ```
204
+
205
+ #### Uninstall
206
+
207
+ Uninstalls any font supported by Fontist. Returns paths of an uninstalled font,
208
+ or prints an error telling that the font isn't installed or could not be found
209
+ in Fontist formulas. Aliased as `remove`.
210
+
211
+ ```
212
+ $ fontist uninstall "segoe ui"
213
+ These fonts are removed:
214
+ /Users/user/.fontist/fonts/SEGOEUII.TTF
215
+ /Users/user/.fontist/fonts/SEGOEUIZ.TTF
216
+ /Users/user/.fontist/fonts/SEGOEUIB.TTF
217
+ /Users/user/.fontist/fonts/SEGOEUI.TTF
218
+ ```
219
+
220
+ #### Status
221
+
222
+ Prints installed font paths grouped by formula and font.
223
+
224
+ ```
225
+ $ fontist status "segoe ui"
226
+ Fontist::Formulas::SegoeUIFont
227
+ Segoe UI
228
+ Regular (/Users/user/.fontist/fonts/SEGOEUI.TTF)
229
+ Bold (/Users/user/.fontist/fonts/SEGOEUIB.TTF)
230
+ Italic (/Users/user/.fontist/fonts/SEGOEUII.TTF)
231
+ Bold Italic (/Users/user/.fontist/fonts/SEGOEUIZ.TTF)
232
+ ```
233
+
234
+ #### List
235
+
236
+ Lists installation status of fonts supported by Fontist.
237
+
238
+ ```
239
+ $ fontist list "segoe ui"
240
+ Fontist::Formulas::SegoeUIFont
241
+ Segoe UI
242
+ Regular (installed)
243
+ Bold (installed)
244
+ Italic (installed)
245
+ Bold Italic (installed)
246
+ ```
247
+
248
+ ```
249
+ $ fontist list "roboto mono"
250
+ Fontist::Formulas::RobotoMonoFont
251
+ Roboto Mono
252
+ Regular (uninstalled)
253
+ Italic (uninstalled)
254
+ ```
255
+
256
+ #### Locations from manifest
257
+
258
+ Returns locations of fonts specified in a YAML file as an input.
259
+
260
+ For example, if there is a file `manifest.yml`:
261
+
262
+ ```yml
263
+ Segoe UI:
264
+ - Regular
265
+ - Bold
266
+ Roboto Mono:
267
+ - Regular
268
+ ```
269
+
270
+ Then the command will return the following YAML output:
271
+
272
+ ```yml
273
+ $ fontist manifest-locations manifest.yml
274
+ ---
275
+ Segoe UI:
276
+ Regular:
277
+ - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
278
+ Bold:
279
+ - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
280
+ Roboto Mono:
281
+ Regular: []
282
+ ```
283
+
284
+ Since Segoe UI is installed, but Roboto Mono is not.
285
+
286
+ #### Install from manifest
287
+
288
+ Install fonts from a YAML manifest:
289
+
290
+ ```yml
291
+ $ fontist manifest-install --confirm-license manifest.yml
292
+ ---
293
+ Segoe UI:
294
+ Regular:
295
+ - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
296
+ Bold:
297
+ - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
298
+ Roboto Mono:
299
+ Regular:
300
+ - "/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"
301
+ ```
302
+
303
+ #### Help
304
+
305
+ List of all commands could be seen by:
306
+
307
+ ```
308
+ fontist help
309
+ ```
310
+
135
311
  ## Development
136
312
 
137
313
  We are following Sandi Metz's Rules for this gem, you can read the
@@ -197,12 +373,6 @@ git commit -m "Google Fonts update"
197
373
  git push
198
374
  ```
199
375
 
200
- ### TTC extraction
201
-
202
- The stripttc script is used for extraction of TTC files. It's taken from the
203
- https://github.com/DavidBarts/getfonts repository, and placed in the bin/
204
- directory.
205
-
206
376
  ## Contributing
207
377
 
208
378
  First, thank you for contributing! We love pull requests from everyone. By
@@ -5,4 +5,4 @@ require "fontist"
5
5
  require "fontist/cli"
6
6
 
7
7
  status_code = Fontist::CLI.start(ARGV)
8
- exit status_code.is_a?(Integer) ? status_code : 0
8
+ exit status_code.is_a?(Integer) ? status_code : 1
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_runtime_dependency "thor", "~> 1.0.1"
36
36
  spec.add_runtime_dependency "git", "~> 1.0"
37
37
 
38
+ spec.add_development_dependency "extract_ttc", "~> 0.1"
38
39
  spec.add_development_dependency "pry"
39
40
  spec.add_development_dependency "bundler", "~> 2.0"
40
41
  spec.add_development_dependency "rake", "~> 12.3.3"
@@ -13,6 +13,7 @@ require "fontist/formulas"
13
13
  require "fontist/formula"
14
14
  require "fontist/system_font"
15
15
  require "fontist/fontist_font"
16
+ require "fontist/manifest"
16
17
 
17
18
  module Fontist
18
19
  def self.ui
@@ -5,9 +5,15 @@ module Fontist
5
5
  STATUS_SUCCESS = 0
6
6
  STATUS_ERROR = 1
7
7
 
8
+ def self.exit_on_failure?
9
+ false
10
+ end
11
+
8
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"
9
15
  def install(font)
10
- fonts_paths = Fontist::Font.install(font)
16
+ fonts_paths = Fontist::Font.install(font, force: options[:force])
11
17
  Fontist.ui.success("These fonts are found or installed:")
12
18
  Fontist.ui.success(fonts_paths.join("\n"))
13
19
  STATUS_SUCCESS
@@ -60,6 +66,34 @@ module Fontist
60
66
  STATUS_SUCCESS
61
67
  end
62
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
+
63
97
  desc "create-formula URL", "Create a new formula with fonts from URL"
64
98
  option :name, desc: "Example: Times New Roman"
65
99
  option :mirror, repeatable: true
@@ -81,6 +115,10 @@ module Fontist
81
115
  STATUS_ERROR
82
116
  end
83
117
 
118
+ def print_yaml(object)
119
+ Fontist.ui.say(YAML.dump(object))
120
+ end
121
+
84
122
  def print_formulas(formulas)
85
123
  formulas.each do |formula, fonts|
86
124
  Fontist.ui.success(formula.installer)
@@ -9,5 +9,7 @@ module Fontist
9
9
  class MissingAttributeError < StandardError; end
10
10
  class FontNotFoundError < StandardError; end
11
11
  class BinaryCallError < StandardError; end
12
+ class ManifestCouldNotBeReadError < StandardError; end
13
+ class ManifestCouldNotBeFoundError < StandardError; end
12
14
  end
13
15
  end
@@ -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,12 @@ 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
20
25
  end
21
26
 
22
27
  def self.uninstall(name)
@@ -38,11 +43,15 @@ module Fontist
38
43
  end
39
44
 
40
45
  def install
41
- find_system_font || download_font || raise(
46
+ (find_system_font unless @force) || download_font || raise(
42
47
  Fontist::Errors::NonSupportedFontError
43
48
  )
44
49
  end
45
50
 
51
+ def try_install
52
+ download_font
53
+ end
54
+
46
55
  def uninstall
47
56
  uninstall_font || downloadable_font || raise(
48
57
  Fontist::Errors::NonSupportedFontError
@@ -2,6 +2,7 @@ module Fontist
2
2
  class Formula
3
3
  def initialize(options = {})
4
4
  @font_name = options.fetch(:font_name, nil)
5
+ @style_name = options.fetch(:style_name, nil)
5
6
 
6
7
  check_and_register_font_formulas
7
8
  end
@@ -18,6 +19,10 @@ module Fontist
18
19
  new(font_name: name).find_fonts
19
20
  end
20
21
 
22
+ def self.find_styles(font, style)
23
+ new(font_name: font, style_name: style).find_styles
24
+ end
25
+
21
26
  def all
22
27
  @all ||= Fontist::Registry.instance.formulas
23
28
  end
@@ -32,9 +37,19 @@ module Fontist
32
37
  fonts.empty? ? nil : fonts
33
38
  end
34
39
 
40
+ def find_styles
41
+ formulas.values.flat_map do |formula|
42
+ formula.fonts.flat_map do |f|
43
+ f.styles.select do |s|
44
+ f.name.casecmp?(font_name) && s.type.casecmp?(style_name)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
35
50
  private
36
51
 
37
- attr_reader :font_name
52
+ attr_reader :font_name, :style_name
38
53
 
39
54
  def find_formula
40
55
  find_by_key || find_by_font_name || find_by_font || []
@@ -2,9 +2,10 @@ module Fontist
2
2
  class FormulaTemplate
3
3
  def self.create_formula_class(formula)
4
4
  Class.new(FontFormula) do |klass|
5
- cleanname = formula.fonts.first.name.gsub(/ /, "")
5
+ first_font = (formula.fonts || formula.font_collections.first.fonts).first
6
+ cleanname = first_font.name.gsub(/ /, "")
6
7
  resource_name = formula.resources.to_h.keys.first
7
- font_filename = formula.fonts.first.styles.first.font
8
+ font_filename = first_font.styles.first.font
8
9
 
9
10
  key formula.key&.to_sym || formula.name.gsub(/ /, "_").downcase.to_sym
10
11
  display_progress_bar formula.display_progress_bar if formula.display_progress_bar
@@ -31,22 +32,24 @@ module Fontist
31
32
  end
32
33
  end
33
34
 
34
- formula.fonts.each do |font|
35
- provides_font(
36
- font.name,
37
- match_styles_from_file: font.styles.map do |style|
38
- {
39
- family_name: style.family_name,
40
- style: style.type,
41
- full_name: style.full_name,
42
- post_script_name: style.post_script_name,
43
- version: style.version,
44
- description: style.description,
45
- filename: style.font,
46
- copyright: style.copyright,
47
- }
48
- end
49
- )
35
+ if formula.fonts
36
+ formula.fonts.each do |font|
37
+ provides_font(
38
+ font.name,
39
+ match_styles_from_file: font.styles.map do |style|
40
+ {
41
+ family_name: style.family_name,
42
+ style: style.type,
43
+ full_name: style.full_name,
44
+ post_script_name: style.post_script_name,
45
+ version: style.version,
46
+ description: style.description,
47
+ filename: style.font,
48
+ copyright: style.copyright,
49
+ }
50
+ end
51
+ )
52
+ end
50
53
  end
51
54
 
52
55
  klass.define_method :extract do
@@ -61,8 +64,10 @@ module Fontist
61
64
  end
62
65
  end
63
66
 
64
- formula.fonts.each do |font|
65
- match_fonts(resource, font.name)
67
+ if formula.fonts
68
+ formula.fonts.each do |font|
69
+ match_fonts(resource, font.name)
70
+ end
66
71
  end
67
72
 
68
73
  if formula.font_collections
@@ -1,3 +1,4 @@
1
+ require "extract_ttc"
1
2
  require "fontist/import/helpers/system_helper"
2
3
  require_relative "../otf/font_file"
3
4
 
@@ -5,8 +6,6 @@ module Fontist
5
6
  module Import
6
7
  module Files
7
8
  class CollectionFile
8
- STRIP_TTC_BINARY = Fontist.root_path.join("bin", "stripttc")
9
-
10
9
  attr_reader :fonts
11
10
 
12
11
  def initialize(path)
@@ -37,10 +36,10 @@ module Fontist
37
36
  end
38
37
 
39
38
  def extract_ttfs(tmp_dir)
40
- Helpers::SystemHelper.run("#{STRIP_TTC_BINARY} #{@path}")
41
-
42
- basename = File.basename(@path, ".ttc")
43
- Dir.glob(File.join(tmp_dir, "#{basename}_[0-9][0-9].ttf"))
39
+ filenames = ExtractTtc.extract(@path)
40
+ filenames.map do |filename|
41
+ File.join(tmp_dir, filename)
42
+ end
44
43
  end
45
44
  end
46
45
  end
@@ -39,7 +39,7 @@ module Fontist
39
39
 
40
40
  def group_fonts
41
41
  files = (@font_files + @font_collection_files.map(&:fonts)).flatten
42
- raise FontNotFoundError, "No font found" if files.empty?
42
+ raise Errors::FontNotFoundError, "No font found" if files.empty?
43
43
 
44
44
  files
45
45
  end
@@ -55,10 +55,51 @@ module Fontist
55
55
  def resources
56
56
  filename = name.gsub(" ", "_") + "." + @extractor.extension
57
57
 
58
- options = { urls: [@url] + (@options[:mirror] || []),
59
- sha256: Digest::SHA256.file(@archive).to_s }
58
+ { filename => resource_options }
59
+ end
60
+
61
+ def resource_options
62
+ urls = []
63
+ sha = []
64
+ downloads do |url, path|
65
+ urls << url
66
+ sha << Digest::SHA256.file(path).to_s
67
+ end
68
+
69
+ sha = prepare_sha256(sha)
70
+
71
+ { urls: urls, sha256: sha }
72
+ end
73
+
74
+ def downloads
75
+ yield @url, @archive
76
+
77
+ mirrors.each do |url|
78
+ path = download(url)
79
+ next unless path
80
+
81
+ yield url, path
82
+ end
83
+ end
84
+
85
+ def mirrors
86
+ @options[:mirror] || []
87
+ end
88
+
89
+ def download(url)
90
+ Fontist::Utils::Downloader.download(url, progress_bar: true).path
91
+ rescue Errors::InvalidResourceError
92
+ Fontist.ui.say("WARN: a mirror is not found '#{url}'")
93
+ nil
94
+ end
95
+
96
+ def prepare_sha256(input)
97
+ output = input.uniq
98
+ return output.first if output.size == 1
60
99
 
61
- { filename => options }
100
+ checksums = output.join(", ")
101
+ Fontist.ui.say("WARN: SHA256 differs (#{checksums})")
102
+ output
62
103
  end
63
104
 
64
105
  def font_collections
@@ -4,7 +4,10 @@ module Fontist
4
4
  module SystemHelper
5
5
  class << self
6
6
  def run(command)
7
- puts "Run `#{command}`" unless ENV.fetch("TEST_ENV", "") === "CI"
7
+ unless ENV.fetch("TEST_ENV", "") === "CI"
8
+ Fontist.ui.say("Run `#{command}`")
9
+ end
10
+
8
11
  result = `#{command}`
9
12
  unless $CHILD_STATUS.to_i.zero?
10
13
  raise Errors::BinaryCallError,
@@ -0,0 +1,2 @@
1
+ require_relative "manifest/locations"
2
+ require_relative "manifest/install"
@@ -0,0 +1,60 @@
1
+ module Fontist
2
+ module Manifest
3
+ class Common
4
+ def initialize(manifest)
5
+ @manifest = manifest
6
+ end
7
+
8
+ def self.call(manifest)
9
+ new(manifest).call
10
+ end
11
+
12
+ def call
13
+ font_names.zip(font_paths).to_h
14
+ end
15
+
16
+ private
17
+
18
+ def font_names
19
+ fonts.keys
20
+ end
21
+
22
+ def fonts
23
+ @fonts ||= begin
24
+ unless File.exist?(@manifest)
25
+ raise Fontist::Errors::ManifestCouldNotBeFoundError
26
+ end
27
+
28
+ fonts = YAML.load_file(@manifest)
29
+ unless fonts.is_a?(Hash)
30
+ raise Fontist::Errors::ManifestCouldNotBeReadError
31
+ end
32
+
33
+ fonts
34
+ end
35
+ end
36
+
37
+ def font_paths
38
+ fonts.map do |font, styles|
39
+ styles_to_ary = [styles].flatten
40
+ style_paths_map(font, styles_to_ary)
41
+ end
42
+ end
43
+
44
+ def style_paths_map(font, names)
45
+ paths = style_paths(font, names)
46
+ names.zip(paths).to_h
47
+ end
48
+
49
+ def style_paths(font, names)
50
+ names.map do |style|
51
+ file_paths(font, style)
52
+ end
53
+ end
54
+
55
+ def file_paths(_font, _style)
56
+ raise NotImplementedError.new("Implement #file_paths in child class")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,36 @@
1
+ require_relative "common"
2
+
3
+ module Fontist
4
+ module Manifest
5
+ class Install < Common
6
+ def initialize(manifest, confirmation: "no")
7
+ @manifest = manifest
8
+ @confirmation = confirmation
9
+ end
10
+
11
+ def self.call(manifest, confirmation: "no")
12
+ new(manifest, confirmation: confirmation).call
13
+ end
14
+
15
+ private
16
+
17
+ def file_paths(font, style)
18
+ paths = find_installed_font(font, style)
19
+ return paths unless paths.empty?
20
+
21
+ install_font(font)
22
+ find_installed_font(font, style)
23
+ end
24
+
25
+ def find_installed_font(font, style)
26
+ Fontist::SystemFont.find_with_style(font, style)
27
+ end
28
+
29
+ def install_font(font)
30
+ Fontist::Font.try_install(font, confirmation: @confirmation)
31
+ rescue Fontist::Errors::LicensingError
32
+ [] # try to install other fonts
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "common"
2
+
3
+ module Fontist
4
+ module Manifest
5
+ class Locations < Common
6
+ private
7
+
8
+ def file_paths(font, style)
9
+ Fontist::SystemFont.find_with_style(font, style)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,8 @@
1
1
  module Fontist
2
2
  class SystemFont
3
- def initialize(font:, sources: nil)
3
+ def initialize(font:, style: nil, sources: nil)
4
4
  @font = font
5
+ @style = style
5
6
  @user_sources = sources || []
6
7
  end
7
8
 
@@ -9,6 +10,10 @@ module Fontist
9
10
  new(font: font, sources: sources).find
10
11
  end
11
12
 
13
+ def self.find_with_style(font, style)
14
+ new(font: font, style: style).find_with_style
15
+ end
16
+
12
17
  def find
13
18
  paths = grep_font_paths(font)
14
19
  paths = lookup_using_font_name || [] if paths.empty?
@@ -16,9 +21,16 @@ module Fontist
16
21
  paths.empty? ? nil : paths
17
22
  end
18
23
 
24
+ def find_with_style
25
+ paths = lookup_using_font_and_style
26
+ return paths unless paths.empty?
27
+
28
+ grep_font_paths(font, style)
29
+ end
30
+
19
31
  private
20
32
 
21
- attr_reader :font, :user_sources
33
+ attr_reader :font, :style, :user_sources
22
34
 
23
35
  def normalize_default_paths
24
36
  @normalize_default_paths ||= default_sources["paths"].map do |path|
@@ -30,15 +42,27 @@ module Fontist
30
42
  end
31
43
  end
32
44
 
33
- def grep_font_paths(font)
45
+ def grep_font_paths(font, style = nil)
46
+ pattern = prepare_pattern(font, style)
47
+
34
48
  paths = font_paths.map { |path| [File.basename(path), path] }.to_h
35
49
  files = paths.keys
36
- matched = files.grep(/#{font}/i)
50
+ matched = files.grep(pattern)
37
51
  paths.values_at(*matched).compact
38
52
  end
39
53
 
54
+ def prepare_pattern(font, style = nil)
55
+ style = nil if style&.casecmp?("regular")
56
+
57
+ s = [font, style].compact.map { |x| Regexp.quote(x) }
58
+ .join(".*")
59
+ .gsub("\\ ", "\s?") # space independent
60
+
61
+ Regexp.new(s, Regexp::IGNORECASE)
62
+ end
63
+
40
64
  def font_paths
41
- Dir.glob((
65
+ @font_paths ||= Dir.glob((
42
66
  user_sources +
43
67
  normalize_default_paths +
44
68
  [fontist_fonts_path.join("**")]
@@ -54,7 +78,6 @@ module Fontist
54
78
  @fontist_fonts_path ||= Fontist.fonts_path
55
79
  end
56
80
 
57
-
58
81
  def user_os
59
82
  Fontist::Utils::System.user_os
60
83
  end
@@ -71,5 +94,19 @@ module Fontist
71
94
  def default_sources
72
95
  @default_sources ||= YAML.load(system_path_file)["system"][user_os.to_s]
73
96
  end
97
+
98
+ def lookup_using_font_and_style
99
+ styles = Formula.find_styles(font, style)
100
+ filenames = styles.map(&:font)
101
+ filenames.flat_map do |filename|
102
+ search_font_paths(filename)
103
+ end
104
+ end
105
+
106
+ def search_font_paths(filename)
107
+ font_paths.select do |path|
108
+ File.basename(path) == filename
109
+ end
110
+ end
74
111
  end
75
112
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.4.0".freeze
2
+ VERSION = "1.5.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-28 00:00:00.000000000 Z
12
+ date: 2020-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '1.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: extract_ttc
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '0.1'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '0.1'
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: pry
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -250,7 +264,6 @@ files:
250
264
  - bin/import_google
251
265
  - bin/rspec
252
266
  - bin/setup
253
- - bin/stripttc
254
267
  - fontist.gemspec
255
268
  - lib/fontist.rb
256
269
  - lib/fontist/cli.rb
@@ -292,6 +305,10 @@ files:
292
305
  - lib/fontist/import/recursive_extraction.rb
293
306
  - lib/fontist/import/template_helper.rb
294
307
  - lib/fontist/import/text_helper.rb
308
+ - lib/fontist/manifest.rb
309
+ - lib/fontist/manifest/common.rb
310
+ - lib/fontist/manifest/install.rb
311
+ - lib/fontist/manifest/locations.rb
295
312
  - lib/fontist/registry.rb
296
313
  - lib/fontist/system.yml
297
314
  - lib/fontist/system_font.rb
Binary file