fontist 1.7.3 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/release.yml +38 -0
  3. data/.github/workflows/rspec.yml +58 -0
  4. data/README.md +34 -4
  5. data/{bin → exe}/fontist +0 -0
  6. data/fontist.gemspec +3 -2
  7. data/lib/fontist.rb +5 -2
  8. data/lib/fontist/cli.rb +53 -38
  9. data/lib/fontist/errors.rb +14 -12
  10. data/lib/fontist/font.rb +25 -27
  11. data/lib/fontist/font_installer.rb +114 -0
  12. data/lib/fontist/fontist_font.rb +3 -49
  13. data/lib/fontist/formula.rb +101 -35
  14. data/lib/fontist/formula_paths.rb +43 -0
  15. data/lib/fontist/helpers.rb +7 -0
  16. data/lib/fontist/import/google_check.rb +1 -1
  17. data/lib/fontist/import/google_import.rb +3 -4
  18. data/lib/fontist/import/otfinfo_generate.rb +1 -1
  19. data/lib/fontist/import/recursive_extraction.rb +5 -1
  20. data/lib/fontist/index.rb +72 -0
  21. data/lib/fontist/index_formula.rb +30 -0
  22. data/lib/fontist/manifest/install.rb +4 -5
  23. data/lib/fontist/manifest/locations.rb +9 -1
  24. data/lib/fontist/system_font.rb +2 -29
  25. data/lib/fontist/system_index.rb +1 -1
  26. data/lib/fontist/utils/exe_extractor.rb +1 -1
  27. data/lib/fontist/utils/zip_extractor.rb +1 -1
  28. data/lib/fontist/version.rb +1 -1
  29. metadata +27 -19
  30. data/.github/workflows/macosx.yml +0 -33
  31. data/.github/workflows/ubuntu.yml +0 -30
  32. data/.github/workflows/windows.yml +0 -32
  33. data/bin/check_google +0 -8
  34. data/bin/console +0 -11
  35. data/bin/convert_formulas +0 -8
  36. data/bin/generate_otfinfo +0 -8
  37. data/bin/import_google +0 -8
  38. data/bin/rspec +0 -29
  39. data/bin/setup +0 -7
  40. data/lib/fontist/font_formula.rb +0 -169
  41. data/lib/fontist/formula_template.rb +0 -122
  42. data/lib/fontist/formulas.rb +0 -56
  43. data/lib/fontist/registry.rb +0 -43
@@ -0,0 +1,72 @@
1
+ require_relative "index_formula"
2
+
3
+ module Fontist
4
+ class Index
5
+ def self.from_yaml
6
+ unless File.exist?(Fontist.formula_index_path)
7
+ raise Errors::FormulaIndexNotFoundError.new("Please fetch index with `fontist update`.")
8
+ end
9
+
10
+ data = YAML.load_file(Fontist.formula_index_path)
11
+ new(data)
12
+ end
13
+
14
+ def self.rebuild
15
+ index = new
16
+ index.build
17
+ index.to_yaml
18
+ end
19
+
20
+ def initialize(data = {})
21
+ @index = {}
22
+
23
+ data.each_pair do |font, paths|
24
+ paths.each do |path|
25
+ add_index_formula(font, IndexFormula.new(path))
26
+ end
27
+ end
28
+ end
29
+
30
+ def build
31
+ Formula.all.each do |formula|
32
+ add_formula(formula)
33
+ end
34
+ end
35
+
36
+ def add_formula(formula)
37
+ formula.fonts.each do |font|
38
+ add_index_formula(font.name, formula.to_index_formula)
39
+ end
40
+ end
41
+
42
+ def add_index_formula(font_raw, index_formula)
43
+ font = normalize_font(font_raw)
44
+ @index[font] ||= []
45
+ @index[font] << index_formula unless @index[font].include?(index_formula)
46
+ end
47
+
48
+ def load_formulas(font)
49
+ index_formulas(font).map(&:to_full)
50
+ end
51
+
52
+ def to_yaml
53
+ File.write(Fontist.formula_index_path, YAML.dump(to_h))
54
+ end
55
+
56
+ def to_h
57
+ @index.map do |font, index_formulas|
58
+ [font, index_formulas.map(&:to_s)]
59
+ end.to_h
60
+ end
61
+
62
+ private
63
+
64
+ def index_formulas(font)
65
+ @index[normalize_font(font)] || []
66
+ end
67
+
68
+ def normalize_font(font)
69
+ font.downcase
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,30 @@
1
+ module Fontist
2
+ class IndexFormula
3
+ def initialize(path)
4
+ @path = path
5
+ end
6
+
7
+ def to_s
8
+ normalized
9
+ end
10
+
11
+ def to_full
12
+ Formula.new_from_file(full_path)
13
+ end
14
+
15
+ def ==(other)
16
+ to_s == other.to_s
17
+ end
18
+
19
+ private
20
+
21
+ def normalized
22
+ escaped = Regexp.escape(Fontist.formulas_path.to_s + "/")
23
+ @path.sub(Regexp.new("^" + escaped), "")
24
+ end
25
+
26
+ def full_path
27
+ Fontist.formulas_path.join(normalized).to_s
28
+ end
29
+ end
30
+ end
@@ -11,17 +11,16 @@ module Fontist
11
11
  private
12
12
 
13
13
  def file_paths(font, style)
14
- paths = super
14
+ paths = find_font_with_name(font, style)
15
15
  return paths unless paths["paths"].empty?
16
16
 
17
17
  install_font(font)
18
- super
18
+
19
+ find_font_with_name(font, style)
19
20
  end
20
21
 
21
22
  def install_font(font)
22
- Fontist::Font.try_install(font, confirmation: @confirmation)
23
- rescue Fontist::Errors::LicensingError
24
- [] # try to install other fonts
23
+ Fontist::Font.install(font, force: true, confirmation: @confirmation)
25
24
  end
26
25
  end
27
26
  end
@@ -53,7 +53,15 @@ module Fontist
53
53
  end
54
54
 
55
55
  def file_paths(font, style)
56
- Fontist::SystemFont.find_with_name(font, style).transform_keys(&:to_s)
56
+ find_font_with_name(font, style).tap do |x|
57
+ if x["paths"].empty?
58
+ raise Errors::MissingFontError.new("Could not find font #{font} #{style}.")
59
+ end
60
+ end
61
+ end
62
+
63
+ def find_font_with_name(font, style)
64
+ Fontist::SystemFont.find_with_name(font, style).map { |k, v| [k.to_s, v] }.to_h
57
65
  end
58
66
  end
59
67
  end
@@ -1,4 +1,5 @@
1
1
  require_relative "system_index"
2
+ require_relative "formula_paths"
2
3
 
3
4
  module Fontist
4
5
  class SystemFont
@@ -78,35 +79,7 @@ module Fontist
78
79
  end
79
80
 
80
81
  def find_by_formulas
81
- styles = find_styles_by_formulas(font, style)
82
- return if styles.empty?
83
-
84
- fonts = styles.uniq { |s| s["font"] }.flat_map do |s|
85
- paths = search_font_paths(s["font"])
86
- paths.map do |path|
87
- { full_name: s["full_name"],
88
- path: path }
89
- end
90
- end
91
-
92
- fonts.empty? ? nil : fonts
93
- end
94
-
95
- def find_styles_by_formulas(font, style)
96
- if style
97
- Formula.find_styles(font, style)
98
- else
99
- fonts = Formula.find_fonts(font)
100
- return [] unless fonts
101
-
102
- fonts.flat_map(&:styles)
103
- end
104
- end
105
-
106
- def search_font_paths(filename)
107
- font_paths.select do |path|
108
- File.basename(path) == filename
109
- end
82
+ FormulaPaths.new(font_paths).find(font, style)
110
83
  end
111
84
  end
112
85
  end
@@ -45,7 +45,7 @@ module Fontist
45
45
  end
46
46
 
47
47
  def detect_fonts(path)
48
- case File.extname(path).delete_prefix(".").downcase
48
+ case File.extname(path).gsub(/^\./, "").downcase
49
49
  when "ttf", "otf"
50
50
  detect_file_font(path)
51
51
  when "ttc"
@@ -6,7 +6,7 @@ module Fontist
6
6
 
7
7
  exe_file = download_file(exe_file).path if download
8
8
 
9
- Fontist.ui.say(%(Installing font "#{key}".))
9
+ Fontist.ui.say(%(Installing font "#{formula.key}".))
10
10
  cab_file = decompressor.search(exe_file)
11
11
  cabbed_fonts = grep_fonts(cab_file.files) || []
12
12
  fonts_paths = extract_cabbed_fonts_to_assets(cabbed_fonts)
@@ -8,7 +8,7 @@ module Fontist
8
8
  zip_file = download_file(resource) if download
9
9
  zip_file ||= resource.urls.first
10
10
 
11
- Fontist.ui.say(%(Installing font "#{key}".))
11
+ Fontist.ui.say(%(Installing font "#{formula.key}".))
12
12
  fonts_paths = unzip_fonts(zip_file, fonts_sub_dir)
13
13
  block_given? ? yield(fonts_paths) : fonts_paths
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.7.3".freeze
2
+ VERSION = "1.8.1".freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  - Abu Nashir
9
9
  autorequire:
10
- bindir: bin
10
+ bindir: exe
11
11
  cert_chain: []
12
- date: 2020-12-10 00:00:00.000000000 Z
12
+ date: 2020-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down
@@ -165,6 +165,20 @@ dependencies:
165
165
  - - "~>"
166
166
  - !ruby/object:Gem::Version
167
167
  version: '2.0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: gem-release
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
168
182
  - !ruby/object:Gem::Dependency
169
183
  name: rake
170
184
  requirement: !ruby/object:Gem::Requirement
@@ -259,9 +273,8 @@ extensions: []
259
273
  extra_rdoc_files: []
260
274
  files:
261
275
  - ".github/workflows/check_google.yml"
262
- - ".github/workflows/macosx.yml"
263
- - ".github/workflows/ubuntu.yml"
264
- - ".github/workflows/windows.yml"
276
+ - ".github/workflows/release.yml"
277
+ - ".github/workflows/rspec.yml"
265
278
  - ".gitignore"
266
279
  - ".hound.yml"
267
280
  - ".rspec"
@@ -270,24 +283,17 @@ files:
270
283
  - LICENSE.txt
271
284
  - README.md
272
285
  - Rakefile
273
- - bin/check_google
274
- - bin/console
275
- - bin/convert_formulas
276
- - bin/fontist
277
- - bin/generate_otfinfo
278
- - bin/import_google
279
- - bin/rspec
280
- - bin/setup
286
+ - exe/fontist
281
287
  - fontist.gemspec
282
288
  - lib/fontist.rb
283
289
  - lib/fontist/cli.rb
284
290
  - lib/fontist/errors.rb
285
291
  - lib/fontist/font.rb
286
- - lib/fontist/font_formula.rb
292
+ - lib/fontist/font_installer.rb
287
293
  - lib/fontist/fontist_font.rb
288
294
  - lib/fontist/formula.rb
289
- - lib/fontist/formula_template.rb
290
- - lib/fontist/formulas.rb
295
+ - lib/fontist/formula_paths.rb
296
+ - lib/fontist/helpers.rb
291
297
  - lib/fontist/import.rb
292
298
  - lib/fontist/import/convert_formulas.rb
293
299
  - lib/fontist/import/create_formula.rb
@@ -321,10 +327,11 @@ files:
321
327
  - lib/fontist/import/recursive_extraction.rb
322
328
  - lib/fontist/import/template_helper.rb
323
329
  - lib/fontist/import/text_helper.rb
330
+ - lib/fontist/index.rb
331
+ - lib/fontist/index_formula.rb
324
332
  - lib/fontist/manifest.rb
325
333
  - lib/fontist/manifest/install.rb
326
334
  - lib/fontist/manifest/locations.rb
327
- - lib/fontist/registry.rb
328
335
  - lib/fontist/system.yml
329
336
  - lib/fontist/system_font.rb
330
337
  - lib/fontist/system_index.rb
@@ -363,7 +370,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
363
370
  - !ruby/object:Gem::Version
364
371
  version: '0'
365
372
  requirements: []
366
- rubygems_version: 3.0.3
373
+ rubyforge_project:
374
+ rubygems_version: 2.6.14.4
367
375
  signing_key:
368
376
  specification_version: 4
369
377
  summary: A libarary find or download fonts
@@ -1,33 +0,0 @@
1
- name: macos
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: macos-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
-
23
- - name: Install otfinfo
24
- run: brew install lcdf-typetools
25
-
26
- - name: Install bundler
27
- run: gem install bundler
28
-
29
- - name: Setup
30
- run: bin/setup
31
-
32
- - name: Run tests
33
- run: TEST_ENV=CI bin/rspec
@@ -1,30 +0,0 @@
1
- name: ubuntu
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: ubuntu-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
-
23
- - name: Install bundler
24
- run: gem install bundler
25
-
26
- - name: Setup
27
- run: bin/setup
28
-
29
- - name: Run tests
30
- run: TEST_ENV=CI bin/rspec --tag ~dev
@@ -1,32 +0,0 @@
1
- name: windows
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: windows-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
- architecture: "x64"
23
-
24
- - name: Setup
25
- shell: pwsh
26
- run: |
27
- gem install bundler
28
- bundle config --local path vendor/bundle
29
- bundle install --jobs 4 --retry 3
30
-
31
- - name: Run tests
32
- run: bundle exec rspec --tag ~skip_in_windows --tag ~dev
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "fontist"
6
- require "fontist/import/google_check"
7
-
8
- Fontist::Import::GoogleCheck.new.call
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "fontist"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- require "pry"
11
- Pry.start