fontist 1.11.1 → 1.11.2
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.
- checksums.yaml +4 -4
- data/.github/workflows/metanorma.yml +2 -5
- data/README.adoc +54 -8
- data/fontist.gemspec +1 -2
- data/lib/fontist/cli.rb +5 -10
- data/lib/fontist/formula.rb +4 -0
- data/lib/fontist/google_cli.rb +29 -0
- data/lib/fontist/import/formula_builder.rb +17 -1
- data/lib/fontist/import/google/new_fonts_fetcher.rb +44 -33
- data/lib/fontist/import/google.rb +18 -0
- data/lib/fontist/import/google_check.rb +0 -7
- data/lib/fontist/import/google_import.rb +26 -142
- data/lib/fontist/import/helpers/system_helper.rb +1 -1
- data/lib/fontist/import/otf_parser.rb +2 -0
- data/lib/fontist/import/recursive_extraction.rb +2 -1
- data/lib/fontist/index.rb +0 -27
- data/lib/fontist/system_font.rb +1 -6
- data/lib/fontist/update.rb +2 -2
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +21 -15
- metadata +17 -36
- data/.github/workflows/check_google.yml +0 -28
- data/README.md +0 -582
- data/lib/fontist/formula_paths.rb +0 -44
- data/lib/fontist/import/google/fonts_public.md +0 -10
- data/lib/fontist/import/google/fonts_public.pb.rb +0 -71
- data/lib/fontist/import/google/fonts_public.proto +0 -46
@@ -1,11 +1,7 @@
|
|
1
1
|
require "erb"
|
2
2
|
require_relative "google"
|
3
3
|
require_relative "google/new_fonts_fetcher"
|
4
|
-
require_relative "
|
5
|
-
require_relative "template_helper"
|
6
|
-
require_relative "text_helper"
|
7
|
-
require_relative "otf_parser"
|
8
|
-
require_relative "otf_style"
|
4
|
+
require_relative "create_formula"
|
9
5
|
|
10
6
|
module Fontist
|
11
7
|
module Import
|
@@ -13,6 +9,7 @@ module Fontist
|
|
13
9
|
def call
|
14
10
|
fonts = new_fonts
|
15
11
|
create_formulas(fonts)
|
12
|
+
rebuild_index
|
16
13
|
end
|
17
14
|
|
18
15
|
private
|
@@ -22,161 +19,48 @@ module Fontist
|
|
22
19
|
end
|
23
20
|
|
24
21
|
def create_formulas(fonts)
|
22
|
+
return puts("Nothing to update") if fonts.empty?
|
23
|
+
|
25
24
|
puts "Creating formulas..."
|
26
25
|
fonts.each do |path|
|
27
26
|
create_formula(path)
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
|
-
def create_formula(
|
32
|
-
puts
|
33
|
-
metadata = fetch_metadata(path)
|
34
|
-
font = build_font(metadata, path)
|
35
|
-
save_formula(font)
|
36
|
-
end
|
30
|
+
def create_formula(font_path)
|
31
|
+
puts font_path
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
path = Fontist::Import::CreateFormula.new(
|
34
|
+
url(font_path),
|
35
|
+
name: Google.metadata_name(font_path),
|
36
|
+
formula_dir: formula_dir,
|
37
|
+
skip_sha: variable_style?(font_path),
|
38
|
+
digest: Google.digest(font_path),
|
39
|
+
).call
|
42
40
|
|
43
|
-
|
44
|
-
h = from_metadata(metadata)
|
45
|
-
.merge(from_otfinfo(path))
|
46
|
-
.merge(styles: styles_from_otfinfo(path, metadata.fonts))
|
47
|
-
.merge(from_license(path))
|
48
|
-
|
49
|
-
OpenStruct.new(h)
|
41
|
+
Fontist.ui.success("Formula has been successfully created: #{path}")
|
50
42
|
end
|
51
43
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
Hash.new.tap do |h|
|
56
|
-
h[:fullname] = metadata.name
|
57
|
-
h[:cleanname] = metadata.name.gsub(/ /, "")
|
58
|
-
h[:sha256] = sha256(metadata.name) unless variable_style?(metadata)
|
59
|
-
h[:copyright] = Fontist::Import::TextHelper.cleanup(copyright)
|
60
|
-
end
|
44
|
+
def url(path)
|
45
|
+
name = Google.metadata_name(path)
|
46
|
+
"https://fonts.google.com/download?family=#{ERB::Util.url_encode(name)}"
|
61
47
|
end
|
62
48
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
49
|
+
def formula_dir
|
50
|
+
@formula_dir ||= Fontist.formulas_path.join("google").tap do |path|
|
51
|
+
FileUtils.mkdir_p(path) unless File.exist?(path)
|
66
52
|
end
|
67
53
|
end
|
68
54
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
Digest::SHA256.file(file).to_s
|
75
|
-
end
|
76
|
-
|
77
|
-
def from_license(path)
|
78
|
-
file = Dir.glob(File.join(path, "{OFL.txt,UFL.txt,LICENSE.txt}")).first
|
79
|
-
print "warn, no license, " unless file
|
80
|
-
return { license: "" } unless file
|
81
|
-
|
82
|
-
{ license: cleanup_text(File.read(file)) }
|
83
|
-
end
|
84
|
-
|
85
|
-
def cleanup_text(text)
|
86
|
-
text.rstrip
|
87
|
-
.gsub("\r\n", "\n")
|
88
|
-
.lines
|
89
|
-
.map(&:rstrip)
|
90
|
-
.drop_while(&:empty?)
|
91
|
-
.join("\n")
|
92
|
-
end
|
93
|
-
|
94
|
-
def from_otfinfo(path)
|
95
|
-
font_file = Dir.glob(File.join(path, "*.ttf")).first
|
96
|
-
otf = OtfParser.new(font_file).call
|
97
|
-
|
98
|
-
{ homepage: otf["Vendor URL"],
|
99
|
-
license_url: otf["License URL"] }
|
100
|
-
end
|
101
|
-
|
102
|
-
def styles_from_otfinfo(path, fonts)
|
103
|
-
fonts.map do |f|
|
104
|
-
file_path = File.join(path, f.filename)
|
105
|
-
info = OtfParser.new(file_path).call
|
106
|
-
OtfStyle.new(info, file_path).call
|
55
|
+
def variable_style?(path)
|
56
|
+
fonts = Dir.glob(File.join(path, "*.{ttf,otf}"))
|
57
|
+
fonts.any? do |font|
|
58
|
+
File.basename(font).match?(/\[(.+,)?(wght|opsz)\]/)
|
107
59
|
end
|
108
60
|
end
|
109
61
|
|
110
|
-
def
|
111
|
-
|
112
|
-
path = formula_path(font.fullname)
|
113
|
-
save_to_path(hash, path)
|
114
|
-
end
|
115
|
-
|
116
|
-
def formula_hash(font)
|
117
|
-
stringify_keys(name: font.cleanname.sub(/\S/, &:upcase),
|
118
|
-
description: font.fullname,
|
119
|
-
homepage: font.homepage,
|
120
|
-
resources: formula_resource(font),
|
121
|
-
fonts: [yaml_font(font)],
|
122
|
-
extract: { format: :zip },
|
123
|
-
copyright: font.copyright,
|
124
|
-
license_url: font.license_url,
|
125
|
-
open_license: font.license)
|
126
|
-
end
|
127
|
-
|
128
|
-
def stringify_keys(hash)
|
129
|
-
JSON.parse(hash.to_json)
|
130
|
-
end
|
131
|
-
|
132
|
-
def formula_resource(font)
|
133
|
-
encoded_name = ERB::Util.url_encode(font.fullname)
|
134
|
-
url = "https://fonts.google.com/download?family=#{encoded_name}"
|
135
|
-
|
136
|
-
options = {}
|
137
|
-
options[:urls] = [url]
|
138
|
-
options[:sha256] = font.sha256 if font.sha256
|
139
|
-
|
140
|
-
{ "#{font.cleanname}.zip" => options }
|
141
|
-
end
|
142
|
-
|
143
|
-
def yaml_font(font)
|
144
|
-
{ name: font.fullname,
|
145
|
-
styles: yaml_styles(font.styles) }
|
146
|
-
end
|
147
|
-
|
148
|
-
def yaml_styles(styles)
|
149
|
-
styles.map do |s|
|
150
|
-
yaml_style(s)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def yaml_style(style)
|
155
|
-
Hash.new.tap do |h|
|
156
|
-
h.merge!(family_name: style.family_name,
|
157
|
-
type: style.style,
|
158
|
-
full_name: style.full_name)
|
159
|
-
if style.preferred_family_name
|
160
|
-
h[:preferred_family_name] = style.preferred_family_name
|
161
|
-
end
|
162
|
-
h[:preferred_type] = style.preferred_style if style.preferred_style
|
163
|
-
h.merge!(style.to_h.select do |k, _|
|
164
|
-
%i(post_script_name version description copyright).include?(k)
|
165
|
-
end.compact)
|
166
|
-
h.merge!(font: fix_variable_filename(style.filename))
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def fix_variable_filename(filename)
|
171
|
-
filename.sub("[wght]", "-VariableFont_wght")
|
172
|
-
end
|
173
|
-
|
174
|
-
def formula_path(name)
|
175
|
-
Fontist::Import::Google.formula_path(name)
|
176
|
-
end
|
177
|
-
|
178
|
-
def save_to_path(hash, path)
|
179
|
-
File.write(path, YAML.dump(hash))
|
62
|
+
def rebuild_index
|
63
|
+
Fontist::Index.rebuild
|
180
64
|
end
|
181
65
|
end
|
182
66
|
end
|
@@ -3,7 +3,8 @@ require_relative "files/font_detector"
|
|
3
3
|
module Fontist
|
4
4
|
module Import
|
5
5
|
class RecursiveExtraction
|
6
|
-
LICENSE_PATTERN =
|
6
|
+
LICENSE_PATTERN =
|
7
|
+
/(ofl\.txt|ufl\.txt|licenses?\.txt|license|copying)$/i.freeze
|
7
8
|
|
8
9
|
def initialize(archive, subarchive: nil, subdir: nil)
|
9
10
|
@archive = archive
|
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
|
data/lib/fontist/system_font.rb
CHANGED
@@ -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
|
@@ -51,7 +50,7 @@ module Fontist
|
|
51
50
|
end
|
52
51
|
|
53
52
|
def find_styles
|
54
|
-
find_by_index
|
53
|
+
find_by_index
|
55
54
|
end
|
56
55
|
|
57
56
|
private
|
@@ -61,9 +60,5 @@ module Fontist
|
|
61
60
|
def find_by_index
|
62
61
|
SystemIndex.system_index.find(font, style)
|
63
62
|
end
|
64
|
-
|
65
|
-
def find_by_formulas
|
66
|
-
FormulaPaths.new(self.class.font_paths).find(font, style)
|
67
|
-
end
|
68
63
|
end
|
69
64
|
end
|
data/lib/fontist/update.rb
CHANGED
data/lib/fontist/version.rb
CHANGED
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.
|
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
|
-
|
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
|
-
|
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.
|
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.11.
|
4
|
+
version: 1.11.2
|
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-
|
11
|
+
date: 2021-09-11 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:
|
28
|
+
name: extract_ttc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
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:
|
40
|
+
version: '0.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
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:
|
54
|
+
version: 1.0.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: git
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
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.
|
68
|
+
version: '1.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: ttfunk
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
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: '
|
82
|
+
version: '1.6'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
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: :
|
90
|
+
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
@@ -220,20 +220,6 @@ dependencies:
|
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: ruby-protocol-buffers
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - "~>"
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '1.0'
|
230
|
-
type: :development
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - "~>"
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '1.0'
|
237
223
|
- !ruby/object:Gem::Dependency
|
238
224
|
name: socksify
|
239
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -256,7 +242,6 @@ executables:
|
|
256
242
|
extensions: []
|
257
243
|
extra_rdoc_files: []
|
258
244
|
files:
|
259
|
-
- ".github/workflows/check_google.yml"
|
260
245
|
- ".github/workflows/metanorma.yml"
|
261
246
|
- ".github/workflows/release.yml"
|
262
247
|
- ".github/workflows/rspec.yml"
|
@@ -267,7 +252,6 @@ files:
|
|
267
252
|
- Gemfile
|
268
253
|
- LICENSE.txt
|
269
254
|
- README.adoc
|
270
|
-
- README.md
|
271
255
|
- Rakefile
|
272
256
|
- exe/fontist
|
273
257
|
- fontist.gemspec
|
@@ -278,7 +262,7 @@ files:
|
|
278
262
|
- lib/fontist/font_installer.rb
|
279
263
|
- lib/fontist/font_path.rb
|
280
264
|
- lib/fontist/formula.rb
|
281
|
-
- lib/fontist/
|
265
|
+
- lib/fontist/google_cli.rb
|
282
266
|
- lib/fontist/helpers.rb
|
283
267
|
- lib/fontist/import.rb
|
284
268
|
- lib/fontist/import/convert_formulas.rb
|
@@ -289,9 +273,6 @@ files:
|
|
289
273
|
- lib/fontist/import/formula_builder.rb
|
290
274
|
- lib/fontist/import/formula_serializer.rb
|
291
275
|
- lib/fontist/import/google.rb
|
292
|
-
- lib/fontist/import/google/fonts_public.md
|
293
|
-
- lib/fontist/import/google/fonts_public.pb.rb
|
294
|
-
- lib/fontist/import/google/fonts_public.proto
|
295
276
|
- lib/fontist/import/google/new_fonts_fetcher.rb
|
296
277
|
- lib/fontist/import/google/skiplist.yml
|
297
278
|
- lib/fontist/import/google_check.rb
|