fontist 1.6.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/release.yml +38 -0
- data/.github/workflows/rspec.yml +58 -0
- data/README.md +109 -32
- data/{bin → exe}/fontist +0 -0
- data/fontist.gemspec +4 -2
- data/lib/fontist.rb +10 -3
- data/lib/fontist/cli.rb +63 -42
- data/lib/fontist/errors.rb +14 -11
- data/lib/fontist/font.rb +25 -27
- data/lib/fontist/font_installer.rb +114 -0
- data/lib/fontist/fontist_font.rb +3 -49
- data/lib/fontist/formula.rb +89 -63
- data/lib/fontist/formula_paths.rb +43 -0
- data/lib/fontist/helpers.rb +7 -0
- data/lib/fontist/import/create_formula.rb +15 -30
- data/lib/fontist/import/files/collection_file.rb +6 -1
- data/lib/fontist/import/files/file_requirement.rb +17 -0
- data/lib/fontist/import/files/font_detector.rb +48 -0
- data/lib/fontist/import/formula_builder.rb +7 -3
- data/lib/fontist/import/google_check.rb +1 -1
- data/lib/fontist/import/google_import.rb +3 -4
- data/lib/fontist/import/otf/font_file.rb +17 -3
- data/lib/fontist/import/otfinfo_generate.rb +1 -1
- data/lib/fontist/import/recursive_extraction.rb +74 -13
- data/lib/fontist/index.rb +72 -0
- data/lib/fontist/index_formula.rb +30 -0
- data/lib/fontist/manifest/install.rb +6 -15
- data/lib/fontist/manifest/locations.rb +59 -4
- data/lib/fontist/system_font.rb +22 -49
- data/lib/fontist/system_index.rb +92 -0
- data/lib/fontist/utils.rb +1 -0
- data/lib/fontist/utils/dsl.rb +4 -0
- data/lib/fontist/utils/dsl/collection_font.rb +36 -0
- data/lib/fontist/utils/dsl/font.rb +2 -1
- data/lib/fontist/utils/exe_extractor.rb +6 -5
- data/lib/fontist/utils/zip_extractor.rb +20 -12
- data/lib/fontist/version.rb +1 -1
- metadata +45 -20
- data/.github/workflows/macosx.yml +0 -33
- data/.github/workflows/ubuntu.yml +0 -30
- data/.github/workflows/windows.yml +0 -32
- data/bin/check_google +0 -8
- data/bin/console +0 -11
- data/bin/convert_formulas +0 -8
- data/bin/generate_otfinfo +0 -8
- data/bin/import_google +0 -8
- data/bin/rspec +0 -29
- data/bin/setup +0 -7
- data/lib/fontist/font_formula.rb +0 -130
- data/lib/fontist/formula_template.rb +0 -108
- data/lib/fontist/formulas.rb +0 -56
- data/lib/fontist/manifest/common.rb +0 -60
- data/lib/fontist/registry.rb +0 -43
@@ -4,41 +4,49 @@ require "pathname"
|
|
4
4
|
module Fontist
|
5
5
|
module Utils
|
6
6
|
module ZipExtractor
|
7
|
-
|
8
|
-
# rubocop:disable Lint/UnusedMethodArgument
|
9
|
-
def zip_extract(resource, download: true, fonts_sub_dir: "")
|
7
|
+
def zip_extract(resource, download: true, fonts_sub_dir: nil)
|
10
8
|
zip_file = download_file(resource) if download
|
11
9
|
zip_file ||= resource.urls.first
|
12
10
|
|
13
|
-
Fontist.ui.say(%(Installing font "#{key}".))
|
14
|
-
fonts_paths = unzip_fonts(zip_file)
|
11
|
+
Fontist.ui.say(%(Installing font "#{formula.key}".))
|
12
|
+
fonts_paths = unzip_fonts(zip_file, fonts_sub_dir)
|
15
13
|
block_given? ? yield(fonts_paths) : fonts_paths
|
16
14
|
end
|
17
|
-
# rubocop:enable Lint/UnusedMethodArgument
|
18
15
|
|
19
16
|
alias_method :unzip, :zip_extract
|
20
17
|
|
21
18
|
private
|
22
19
|
|
23
20
|
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
24
|
-
def unzip_fonts(file)
|
21
|
+
def unzip_fonts(file, subdir)
|
25
22
|
Zip.on_exists_proc = true
|
26
23
|
|
27
24
|
Array.new.tap do |fonts|
|
28
25
|
Zip::File.open(file) do |zip_file|
|
29
|
-
zip_file.
|
26
|
+
zip_file.each do |entry|
|
30
27
|
if entry.name
|
31
|
-
filename = Pathname.new(entry.name).basename
|
32
|
-
|
33
|
-
|
28
|
+
filename = Pathname.new(entry.name).basename.to_s
|
29
|
+
if font_directory?(entry.name, subdir) && font_file?(filename)
|
30
|
+
target_filename = target_filename(filename)
|
31
|
+
font_path = fonts_path.join(target_filename)
|
32
|
+
fonts.push(font_path.to_s)
|
34
33
|
|
35
|
-
|
34
|
+
entry.extract(font_path)
|
35
|
+
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
42
|
+
|
43
|
+
def font_directory?(path, subdir)
|
44
|
+
return true unless subdir
|
45
|
+
|
46
|
+
dirname = File.dirname(path)
|
47
|
+
normalized_pattern = subdir.chomp("/")
|
48
|
+
File.fnmatch?(normalized_pattern, dirname)
|
49
|
+
end
|
42
50
|
end
|
43
51
|
end
|
44
52
|
end
|
data/lib/fontist/version.rb
CHANGED
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.
|
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:
|
10
|
+
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-12-20 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: ttfunk
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '1.0'
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1.0'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
127
|
name: extract_ttc
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,6 +165,20 @@ dependencies:
|
|
151
165
|
- - "~>"
|
152
166
|
- !ruby/object:Gem::Version
|
153
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'
|
154
182
|
- !ruby/object:Gem::Dependency
|
155
183
|
name: rake
|
156
184
|
requirement: !ruby/object:Gem::Requirement
|
@@ -245,9 +273,8 @@ extensions: []
|
|
245
273
|
extra_rdoc_files: []
|
246
274
|
files:
|
247
275
|
- ".github/workflows/check_google.yml"
|
248
|
-
- ".github/workflows/
|
249
|
-
- ".github/workflows/
|
250
|
-
- ".github/workflows/windows.yml"
|
276
|
+
- ".github/workflows/release.yml"
|
277
|
+
- ".github/workflows/rspec.yml"
|
251
278
|
- ".gitignore"
|
252
279
|
- ".hound.yml"
|
253
280
|
- ".rspec"
|
@@ -256,24 +283,17 @@ files:
|
|
256
283
|
- LICENSE.txt
|
257
284
|
- README.md
|
258
285
|
- Rakefile
|
259
|
-
-
|
260
|
-
- bin/console
|
261
|
-
- bin/convert_formulas
|
262
|
-
- bin/fontist
|
263
|
-
- bin/generate_otfinfo
|
264
|
-
- bin/import_google
|
265
|
-
- bin/rspec
|
266
|
-
- bin/setup
|
286
|
+
- exe/fontist
|
267
287
|
- fontist.gemspec
|
268
288
|
- lib/fontist.rb
|
269
289
|
- lib/fontist/cli.rb
|
270
290
|
- lib/fontist/errors.rb
|
271
291
|
- lib/fontist/font.rb
|
272
|
-
- lib/fontist/
|
292
|
+
- lib/fontist/font_installer.rb
|
273
293
|
- lib/fontist/fontist_font.rb
|
274
294
|
- lib/fontist/formula.rb
|
275
|
-
- lib/fontist/
|
276
|
-
- lib/fontist/
|
295
|
+
- lib/fontist/formula_paths.rb
|
296
|
+
- lib/fontist/helpers.rb
|
277
297
|
- lib/fontist/import.rb
|
278
298
|
- lib/fontist/import/convert_formulas.rb
|
279
299
|
- lib/fontist/import/create_formula.rb
|
@@ -284,6 +304,8 @@ files:
|
|
284
304
|
- lib/fontist/import/extractors/seven_zip_extractor.rb
|
285
305
|
- lib/fontist/import/extractors/zip_extractor.rb
|
286
306
|
- lib/fontist/import/files/collection_file.rb
|
307
|
+
- lib/fontist/import/files/file_requirement.rb
|
308
|
+
- lib/fontist/import/files/font_detector.rb
|
287
309
|
- lib/fontist/import/formula_builder.rb
|
288
310
|
- lib/fontist/import/formula_serializer.rb
|
289
311
|
- lib/fontist/import/google.rb
|
@@ -305,17 +327,19 @@ files:
|
|
305
327
|
- lib/fontist/import/recursive_extraction.rb
|
306
328
|
- lib/fontist/import/template_helper.rb
|
307
329
|
- lib/fontist/import/text_helper.rb
|
330
|
+
- lib/fontist/index.rb
|
331
|
+
- lib/fontist/index_formula.rb
|
308
332
|
- lib/fontist/manifest.rb
|
309
|
-
- lib/fontist/manifest/common.rb
|
310
333
|
- lib/fontist/manifest/install.rb
|
311
334
|
- lib/fontist/manifest/locations.rb
|
312
|
-
- lib/fontist/registry.rb
|
313
335
|
- lib/fontist/system.yml
|
314
336
|
- lib/fontist/system_font.rb
|
337
|
+
- lib/fontist/system_index.rb
|
315
338
|
- lib/fontist/utils.rb
|
316
339
|
- lib/fontist/utils/cache.rb
|
317
340
|
- lib/fontist/utils/downloader.rb
|
318
341
|
- lib/fontist/utils/dsl.rb
|
342
|
+
- lib/fontist/utils/dsl/collection_font.rb
|
319
343
|
- lib/fontist/utils/dsl/font.rb
|
320
344
|
- lib/fontist/utils/exe_extractor.rb
|
321
345
|
- lib/fontist/utils/msi_extractor.rb
|
@@ -346,7 +370,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
346
370
|
- !ruby/object:Gem::Version
|
347
371
|
version: '0'
|
348
372
|
requirements: []
|
349
|
-
|
373
|
+
rubyforge_project:
|
374
|
+
rubygems_version: 2.6.14.4
|
350
375
|
signing_key:
|
351
376
|
specification_version: 4
|
352
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
|
data/bin/check_google
DELETED
data/bin/console
DELETED
@@ -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
|
data/bin/convert_formulas
DELETED
data/bin/generate_otfinfo
DELETED
data/bin/import_google
DELETED
data/bin/rspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rspec' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
DELETED
data/lib/fontist/font_formula.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
class FontFormula
|
3
|
-
include Singleton
|
4
|
-
extend Fontist::Utils::Dsl
|
5
|
-
include Fontist::Utils::ZipExtractor
|
6
|
-
include Fontist::Utils::ExeExtractor
|
7
|
-
include Fontist::Utils::MsiExtractor
|
8
|
-
include Fontist::Utils::SevenZipExtractor
|
9
|
-
|
10
|
-
attr_accessor :license, :license_url, :license_required, :copyright
|
11
|
-
attr_accessor :key, :homepage, :description, :options, :temp_resource
|
12
|
-
|
13
|
-
def font_list
|
14
|
-
@font_list ||= []
|
15
|
-
end
|
16
|
-
|
17
|
-
def resources
|
18
|
-
@resources ||= {}
|
19
|
-
end
|
20
|
-
|
21
|
-
def fonts
|
22
|
-
@fonts ||= font_list.uniq
|
23
|
-
end
|
24
|
-
|
25
|
-
def extract_font_styles(options)
|
26
|
-
extract_from_file(options) ||
|
27
|
-
extract_from_collection(options) || default_font
|
28
|
-
end
|
29
|
-
|
30
|
-
def reinitialize
|
31
|
-
@downloaded = false
|
32
|
-
@matched_fonts = []
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.fetch_font(name, confirmation:)
|
36
|
-
if instance.license_required && confirmation.downcase != "yes"
|
37
|
-
raise(Fontist::Errors::LicensingError)
|
38
|
-
end
|
39
|
-
|
40
|
-
instance.reinitialize
|
41
|
-
instance.install_font(name, confirmation)
|
42
|
-
end
|
43
|
-
|
44
|
-
def install_font(name, confirmation)
|
45
|
-
run_in_temp_dir { extract }
|
46
|
-
matched_fonts_uniq = matched_fonts.flatten.uniq
|
47
|
-
matched_fonts_uniq.empty? ? nil : matched_fonts_uniq
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
attr_reader :downloaded, :matched_fonts
|
53
|
-
|
54
|
-
def resource(name, &block)
|
55
|
-
source = resources[name]
|
56
|
-
block_given? ? yield(source) : source
|
57
|
-
end
|
58
|
-
|
59
|
-
def fonts_path
|
60
|
-
@fonts_path = Fontist.fonts_path
|
61
|
-
end
|
62
|
-
|
63
|
-
def default_font
|
64
|
-
[{ type: "Regular", font: temp_resource[:filename] }]
|
65
|
-
end
|
66
|
-
|
67
|
-
def run_in_temp_dir(&block)
|
68
|
-
Dir.mktmpdir(nil, Dir.tmpdir) do |dir|
|
69
|
-
@temp_dir = Pathname.new(dir)
|
70
|
-
|
71
|
-
yield
|
72
|
-
@temp_dir = nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def extract_from_file(options)
|
77
|
-
styles = options.fetch(:match_styles_from_file, [])
|
78
|
-
|
79
|
-
unless styles.empty?
|
80
|
-
styles.map do |attributes|
|
81
|
-
Fontist::Utils::Dsl::Font.new(attributes).attributes
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def match_fonts(fonts_dir, font_name)
|
87
|
-
fonts = map_names_to_fonts(font_name).join("|")
|
88
|
-
font = fonts_dir.grep(/#{fonts}/i)
|
89
|
-
@matched_fonts.push(font) if font
|
90
|
-
|
91
|
-
font
|
92
|
-
end
|
93
|
-
|
94
|
-
def extract_from_collection(options)
|
95
|
-
styles = options.fetch(:extract_styles_from_collection, [])
|
96
|
-
|
97
|
-
unless styles.empty?
|
98
|
-
styles.map do |type, file|
|
99
|
-
{ type: type, collection: file, font: temp_resource[:filename] }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def map_names_to_fonts(font_name)
|
105
|
-
fonts = Fontist::Formula.find_fonts(font_name)
|
106
|
-
fonts = fonts.map { |font| font.styles.map(&:font) }.flatten if fonts
|
107
|
-
|
108
|
-
fonts || []
|
109
|
-
end
|
110
|
-
|
111
|
-
def download_file(source)
|
112
|
-
url = source[:urls].first
|
113
|
-
Fontist.ui.say(%(Downloading font "#{key}" from #{url}))
|
114
|
-
|
115
|
-
downloaded_file = Fontist::Utils::Downloader.download(
|
116
|
-
url,
|
117
|
-
sha: source[:sha256],
|
118
|
-
file_size: source[:file_size],
|
119
|
-
progress_bar: is_progress_bar_enabled
|
120
|
-
)
|
121
|
-
|
122
|
-
@downloaded = true
|
123
|
-
downloaded_file
|
124
|
-
end
|
125
|
-
|
126
|
-
def is_progress_bar_enabled
|
127
|
-
options.nil? ? true : options.fetch(:progress_bar, true)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|