fontist 1.10.0 → 1.11.3

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.
@@ -4,7 +4,7 @@ module Fontist
4
4
  module SystemHelper
5
5
  class << self
6
6
  def run(command)
7
- Fontist.ui.say("Run `#{command}`")
7
+ Fontist.ui.say("Run `#{command}`") if Fontist.debug?
8
8
 
9
9
  result = `#{command}`
10
10
  unless $CHILD_STATUS.to_i.zero?
@@ -106,7 +106,11 @@ module Fontist
106
106
  end
107
107
 
108
108
  def detect_extension
109
- Files::FontDetector.standard_extension(@path)
109
+ detected = Files::FontDetector.standard_extension(@path)
110
+ file_extension = File.extname(File.basename(@path)).sub(/^\./, "")
111
+ return file_extension if file_extension.casecmp?(detected)
112
+
113
+ detected
110
114
  end
111
115
  end
112
116
  end
@@ -13,6 +13,8 @@ module Fontist
13
13
  end
14
14
 
15
15
  def call
16
+ raise ArgumentError, "Empty path" unless @path
17
+
16
18
  text = REQUIREMENTS[:otfinfo].call(@path)
17
19
  text.split("\n")
18
20
  .select { |x| x.include?(":") }
@@ -3,7 +3,8 @@ require_relative "files/font_detector"
3
3
  module Fontist
4
4
  module Import
5
5
  class RecursiveExtraction
6
- LICENSE_PATTERN = /(ofl\.txt|ufl\.txt|licenses?\.txt|copying)$/i.freeze
6
+ LICENSE_PATTERN =
7
+ /(ofl\.txt|ufl\.txt|licenses?\.txt|license(\.md)?|copying)$/i.freeze
7
8
 
8
9
  def initialize(archive, subarchive: nil, subdir: nil)
9
10
  @archive = archive
@@ -69,6 +70,8 @@ module Fontist
69
70
 
70
71
  def extract_data(archive)
71
72
  Excavate::Archive.new(path(archive)).files(recursive_packages: true) do |path|
73
+ next unless File.file?(path)
74
+
72
75
  match_license(path)
73
76
  match_font(path) if font_directory?(path)
74
77
  end
data/lib/fontist/index.rb CHANGED
@@ -3,33 +3,6 @@ require_relative "indexes/filename_index"
3
3
 
4
4
  module Fontist
5
5
  class Index
6
- def self.rebuild_for_main_repo
7
- unless Dir.exist?(Fontist.private_formulas_path)
8
- return do_rebuild_for_main_repo_with
9
- end
10
-
11
- Dir.mktmpdir do |dir|
12
- tmp_private_path = File.join(dir, "private")
13
- FileUtils.mv(Fontist.private_formulas_path, tmp_private_path)
14
-
15
- do_rebuild_for_main_repo_with
16
-
17
- FileUtils.mv(tmp_private_path, Fontist.private_formulas_path)
18
- end
19
- end
20
-
21
- def self.do_rebuild_for_main_repo_with
22
- Fontist.formula_preferred_family_index_path =
23
- Fontist.formulas_repo_path.join("index.yml")
24
- Fontist.formula_filename_index_path =
25
- Fontist.formulas_repo_path.join("filename_index.yml")
26
-
27
- rebuild
28
-
29
- Fontist.formula_preferred_family_index_path = nil
30
- Fontist.formula_filename_index_path = nil
31
- end
32
-
33
6
  def self.rebuild
34
7
  Fontist::Indexes::DefaultFamilyFontIndex.rebuild
35
8
  Fontist::Indexes::PreferredFamilyFontIndex.rebuild
@@ -1,5 +1,4 @@
1
1
  require_relative "system_index"
2
- require_relative "formula_paths"
3
2
 
4
3
  module Fontist
5
4
  class SystemFont
@@ -13,6 +12,10 @@ module Fontist
13
12
  end
14
13
 
15
14
  def self.system_font_paths
15
+ @system_font_paths ||= load_system_font_paths
16
+ end
17
+
18
+ def self.load_system_font_paths
16
19
  config_path = Fontist.system_file_path
17
20
  os = Fontist::Utils::System.user_os.to_s
18
21
  templates = YAML.load_file(config_path)["system"][os]["paths"]
@@ -21,6 +24,10 @@ module Fontist
21
24
  Dir.glob(patterns)
22
25
  end
23
26
 
27
+ def self.reset_system_font_paths_cache
28
+ @system_font_paths = nil
29
+ end
30
+
24
31
  def self.expand_paths(paths)
25
32
  paths.map do |path|
26
33
  require "etc"
@@ -51,7 +58,7 @@ module Fontist
51
58
  end
52
59
 
53
60
  def find_styles
54
- find_by_index || find_by_formulas
61
+ find_by_index
55
62
  end
56
63
 
57
64
  private
@@ -61,9 +68,5 @@ module Fontist
61
68
  def find_by_index
62
69
  SystemIndex.system_index.find(font, style)
63
70
  end
64
-
65
- def find_by_formulas
66
- FormulaPaths.new(self.class.font_paths).find(font, style)
67
- end
68
71
  end
69
72
  end
@@ -37,35 +37,39 @@ module Fontist
37
37
  LANGUAGE_MAC_ENGLISH = 0
38
38
  LANGUAGE_MS_ENGLISH_AMERICAN = 0x409
39
39
 
40
- attr_reader :font_paths
41
-
42
40
  def self.system_index
43
- if Fontist.preferred_family?
44
- new(Fontist.system_preferred_family_index_path,
45
- SystemFont.font_paths,
46
- PreferredFamily.new)
47
- else
48
- new(Fontist.system_index_path,
49
- SystemFont.font_paths,
50
- DefaultFamily.new)
51
- end
41
+ path = if Fontist.preferred_family?
42
+ Fontist.system_preferred_family_index_path
43
+ else
44
+ Fontist.system_index_path
45
+ end
46
+
47
+ @system_index ||= {}
48
+ @system_index[Fontist.preferred_family?] ||= {}
49
+ @system_index[Fontist.preferred_family?][path] ||=
50
+ new(path, -> { SystemFont.font_paths }, family)
52
51
  end
53
52
 
54
53
  def self.fontist_index
55
- if Fontist.preferred_family?
56
- new(Fontist.fontist_preferred_family_index_path,
57
- SystemFont.fontist_font_paths,
58
- PreferredFamily.new)
59
- else
60
- new(Fontist.fontist_index_path,
61
- SystemFont.fontist_font_paths,
62
- DefaultFamily.new)
63
- end
54
+ path = if Fontist.preferred_family?
55
+ Fontist.fontist_preferred_family_index_path
56
+ else
57
+ Fontist.fontist_index_path
58
+ end
59
+
60
+ @fontist_index ||= {}
61
+ @fontist_index[Fontist.preferred_family?] ||= {}
62
+ @fontist_index[Fontist.preferred_family?][path] ||=
63
+ new(path, -> { SystemFont.fontist_font_paths }, family)
64
+ end
65
+
66
+ def self.family
67
+ Fontist.preferred_family? ? PreferredFamily.new : DefaultFamily.new
64
68
  end
65
69
 
66
- def initialize(index_path, font_paths, family)
70
+ def initialize(index_path, font_paths_fetcher, family)
67
71
  @index_path = index_path
68
- @font_paths = font_paths
72
+ @font_paths_fetcher = font_paths_fetcher
69
73
  @family = family
70
74
  end
71
75
 
@@ -85,7 +89,18 @@ module Fontist
85
89
  private
86
90
 
87
91
  def index
88
- @index ||= build_index
92
+ return @index unless index_changed?
93
+
94
+ @index = build_index
95
+ end
96
+
97
+ def index_changed?
98
+ @index.nil? ||
99
+ @index.map { |x| x[:path] }.uniq.sort != font_paths.sort
100
+ end
101
+
102
+ def font_paths
103
+ @font_paths_fetcher.call
89
104
  end
90
105
 
91
106
  def build_index
@@ -148,6 +163,11 @@ module Fontist
148
163
  else
149
164
  raise Errors::UnknownFontTypeError.new(path)
150
165
  end
166
+ rescue StandardError
167
+ Fontist.ui.error($!.message)
168
+ Fontist.ui.error(
169
+ "Warning: File at #{path} not recognized as a font file.",
170
+ )
151
171
  end
152
172
 
153
173
  def detect_file_font(path)
@@ -155,9 +175,6 @@ module Fontist
155
175
  file = TTFunk::File.new(content)
156
176
 
157
177
  parse_font(file, path)
158
- rescue StandardError
159
- warn $!.message
160
- warn "Warning: File at #{path} not recognized as a font file."
161
178
  end
162
179
 
163
180
  def detect_collection_fonts(path)
@@ -166,9 +183,6 @@ module Fontist
166
183
  parse_font(file, path)
167
184
  end
168
185
  end
169
- rescue StandardError
170
- warn $!.message
171
- warn "Warning: File at #{path} not recognized as a font file."
172
186
  end
173
187
 
174
188
  def parse_font(file, path)
@@ -1,7 +1,13 @@
1
1
  module Fontist
2
2
  class Update
3
+ VERSION = "v2".freeze
4
+
3
5
  def self.call
4
- new.call
6
+ new(VERSION).call
7
+ end
8
+
9
+ def initialize(branch = "main")
10
+ @branch = branch
5
11
  end
6
12
 
7
13
  def call
@@ -17,13 +23,21 @@ module Fontist
17
23
  dir = File.dirname(Fontist.formulas_repo_path)
18
24
  FileUtils.mkdir_p(dir) unless File.exist?(dir)
19
25
 
20
- if Dir.exist?(Fontist.formulas_repo_path)
21
- Git.open(Fontist.formulas_repo_path).pull
22
- else
23
- Git.clone(Fontist.formulas_repo_url,
24
- Fontist.formulas_repo_path,
25
- depth: 1)
26
+ unless Dir.exist?(Fontist.formulas_repo_path)
27
+ return Git.clone(Fontist.formulas_repo_url,
28
+ Fontist.formulas_repo_path,
29
+ branch: @branch,
30
+ depth: 1)
26
31
  end
32
+
33
+ git = Git.open(Fontist.formulas_repo_path)
34
+ return git.pull("origin", @branch) if git.current_branch == @branch
35
+
36
+ git.config("remote.origin.fetch",
37
+ "+refs/heads/#{@branch}:refs/remotes/origin/#{@branch}")
38
+ git.fetch
39
+ git.checkout(@branch)
40
+ git.pull("origin", @branch)
27
41
  end
28
42
 
29
43
  def update_private_repos
@@ -24,12 +24,7 @@ module Fontist
24
24
  download_file
25
25
  end
26
26
 
27
- if !sha.empty? && !sha.include?(Digest::SHA256.file(file).to_s)
28
- raise(Fontist::Errors::TamperedFileError.new(
29
- "The downloaded file from #{@file} doesn't " \
30
- "match with the expected sha256 checksum!"
31
- ))
32
- end
27
+ raise_if_tampered(file)
33
28
 
34
29
  file
35
30
  end
@@ -38,6 +33,19 @@ module Fontist
38
33
 
39
34
  attr_reader :file, :sha, :file_size
40
35
 
36
+ def raise_if_tampered(file)
37
+ file_checksum = Digest::SHA256.file(file).to_s
38
+ if !sha.empty? && !sha.include?(file_checksum)
39
+ raise(
40
+ Fontist::Errors::TamperedFileError.new(
41
+ "The downloaded file from #{@file} doesn't " \
42
+ "match with the expected sha256 checksum (#{file_checksum})!\n" \
43
+ "Beginning of content: #{File.read(file, 3000)}",
44
+ ),
45
+ )
46
+ end
47
+ end
48
+
41
49
  def byte_to_megabyte
42
50
  @byte_to_megabyte ||= 1024 * 1024
43
51
  end
@@ -59,6 +67,7 @@ module Fontist
59
67
  url,
60
68
  open_timeout: 10,
61
69
  read_timeout: 10,
70
+ max_redirects: 10,
62
71
  headers: headers,
63
72
  content_length_proc: ->(content_length) {
64
73
  @progress_bar.total = content_length if content_length
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.10.0".freeze
2
+ VERSION = "1.11.3".freeze
3
3
  end
data/lib/fontist.rb CHANGED
@@ -40,7 +40,11 @@ module Fontist
40
40
  end
41
41
 
42
42
  def self.formulas_repo_path
43
- Fontist.fontist_path.join("formulas")
43
+ Fontist.fontist_version_path.join("formulas")
44
+ end
45
+
46
+ def self.fontist_version_path
47
+ Fontist.fontist_path.join("versions", Update::VERSION)
44
48
  end
45
49
 
46
50
  def self.formulas_repo_url
@@ -48,7 +52,11 @@ module Fontist
48
52
  end
49
53
 
50
54
  def self.formulas_path
51
- Fontist.formulas_repo_path.join("Formulas")
55
+ @formulas_path || Fontist.formulas_repo_path.join("Formulas")
56
+ end
57
+
58
+ def self.formulas_path=(path)
59
+ @formulas_path = path
52
60
  end
53
61
 
54
62
  def self.private_formulas_path
@@ -84,25 +92,15 @@ module Fontist
84
92
  end
85
93
 
86
94
  def self.formula_preferred_family_index_path
87
- @formula_preferred_family_index_path ||
88
- Fontist.formula_index_dir.join("formula_index.preferred_family.yml")
89
- end
90
-
91
- def self.formula_preferred_family_index_path=(path)
92
- @formula_preferred_family_index_path = path
95
+ Fontist.formula_index_dir.join("formula_index.preferred_family.yml")
93
96
  end
94
97
 
95
98
  def self.formula_filename_index_path
96
- @formula_filename_index_path ||
97
- Fontist.formula_index_dir.join("filename_index.yml")
98
- end
99
-
100
- def self.formula_filename_index_path=(path)
101
- @formula_filename_index_path = path
99
+ Fontist.formula_index_dir.join("filename_index.yml")
102
100
  end
103
101
 
104
102
  def self.formula_index_dir
105
- Fontist.fontist_path
103
+ Fontist.fontist_version_path
106
104
  end
107
105
 
108
106
  def self.preferred_family?
@@ -112,4 +110,12 @@ module Fontist
112
110
  def self.preferred_family=(bool)
113
111
  @preferred_family = bool
114
112
  end
113
+
114
+ def self.debug?
115
+ @debug || false
116
+ end
117
+
118
+ def self.debug=(bool)
119
+ @debug = bool
120
+ end
115
121
  end
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: 1.10.0
4
+ version: 1.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-17 00:00:00.000000000 Z
11
+ date: 2021-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -25,69 +25,69 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: thor
28
+ name: extract_ttc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.1
33
+ version: '0.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.1
40
+ version: '0.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: git
42
+ name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: 1.0.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: 1.0.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: ttfunk
56
+ name: git
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.6'
61
+ version: '1.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.6'
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: excavate
70
+ name: ttfunk
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.1'
75
+ version: '1.6'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.1'
82
+ version: '1.6'
83
83
  - !ruby/object:Gem::Dependency
84
- name: extract_ttc
84
+ name: excavate
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0.1'
90
- type: :development
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: '3.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rspec-benchmark
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.6'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.6'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: rubocop
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -221,19 +235,19 @@ dependencies:
221
235
  - !ruby/object:Gem::Version
222
236
  version: '0'
223
237
  - !ruby/object:Gem::Dependency
224
- name: ruby-protocol-buffers
238
+ name: socksify
225
239
  requirement: !ruby/object:Gem::Requirement
226
240
  requirements:
227
- - - "~>"
241
+ - - ">="
228
242
  - !ruby/object:Gem::Version
229
- version: '1.0'
230
- type: :development
243
+ version: '0'
244
+ type: :runtime
231
245
  prerelease: false
232
246
  version_requirements: !ruby/object:Gem::Requirement
233
247
  requirements:
234
- - - "~>"
248
+ - - ">="
235
249
  - !ruby/object:Gem::Version
236
- version: '1.0'
250
+ version: '0'
237
251
  description: Install openly-licensed fonts on Windows, Linux and Mac!
238
252
  email:
239
253
  - open.source@ribose.com
@@ -242,7 +256,6 @@ executables:
242
256
  extensions: []
243
257
  extra_rdoc_files: []
244
258
  files:
245
- - ".github/workflows/check_google.yml"
246
259
  - ".github/workflows/metanorma.yml"
247
260
  - ".github/workflows/release.yml"
248
261
  - ".github/workflows/rspec.yml"
@@ -252,7 +265,7 @@ files:
252
265
  - ".rubocop.yml"
253
266
  - Gemfile
254
267
  - LICENSE.txt
255
- - README.md
268
+ - README.adoc
256
269
  - Rakefile
257
270
  - exe/fontist
258
271
  - fontist.gemspec
@@ -263,7 +276,7 @@ files:
263
276
  - lib/fontist/font_installer.rb
264
277
  - lib/fontist/font_path.rb
265
278
  - lib/fontist/formula.rb
266
- - lib/fontist/formula_paths.rb
279
+ - lib/fontist/google_cli.rb
267
280
  - lib/fontist/helpers.rb
268
281
  - lib/fontist/import.rb
269
282
  - lib/fontist/import/convert_formulas.rb
@@ -274,9 +287,6 @@ files:
274
287
  - lib/fontist/import/formula_builder.rb
275
288
  - lib/fontist/import/formula_serializer.rb
276
289
  - lib/fontist/import/google.rb
277
- - lib/fontist/import/google/fonts_public.md
278
- - lib/fontist/import/google/fonts_public.pb.rb
279
- - lib/fontist/import/google/fonts_public.proto
280
290
  - lib/fontist/import/google/new_fonts_fetcher.rb
281
291
  - lib/fontist/import/google/skiplist.yml
282
292
  - lib/fontist/import/google_check.rb