fontist 1.7.1 → 1.7.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/README.md +46 -18
- data/lib/fontist.rb +1 -1
- data/lib/fontist/cli.rb +1 -1
- data/lib/fontist/font_formula.rb +23 -12
- data/lib/fontist/formula.rb +13 -53
- data/lib/fontist/system_font.rb +4 -33
- data/lib/fontist/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 035a1318895900d90f27d2b5db8f08b86c64e6eb5e172ef81038c55305258756
|
4
|
+
data.tar.gz: 5a748c9632995e504b448508d56d0e292a7429b1eaa86d08978bf6e54d67f9e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1558eb54750ed4efaabe694b79e23a00ce3a51d6c026641ab58796737ff609cce23b92dd141524e90c8d7e55f11cc0537fe405ca849b9d0309e65e47d1b672fe
|
7
|
+
data.tar.gz: 371d9283fa520c1dd036e22f600a5804a75af10b3a2d90bfe775432036ab51c12466696bb33a6614954c4de974889087255cdf2705b91731b6a0afa7ce9bef88
|
data/README.md
CHANGED
@@ -109,7 +109,7 @@ fonts in your system.
|
|
109
109
|
#### Find formula fonts
|
110
110
|
|
111
111
|
Normally, each font name can be associated with multiple styles or collection, for
|
112
|
-
example the `Calibri` font might contains a `regular`, `
|
112
|
+
example the `Calibri` font might contains a `regular`, `bold` or `italic` styles
|
113
113
|
fonts and if you want a interface that can return the complete list then this is
|
114
114
|
your friend. You can use it as following:
|
115
115
|
|
@@ -153,11 +153,14 @@ Fontist::Manifest::Locations.call(manifest_path)
|
|
153
153
|
```
|
154
154
|
|
155
155
|
```ruby
|
156
|
-
{"Segoe UI"=>
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
156
|
+
{"Segoe UI"=> {
|
157
|
+
"Regular"=>{"full_name"=>"Segoe UI",
|
158
|
+
"paths"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"]},
|
159
|
+
"Bold"=>{"full_name"=>"Segoe UI Bold",
|
160
|
+
"paths"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]}},
|
161
|
+
"Roboto Mono"=> {
|
162
|
+
"Regular"=>{"full_name"=>nil,
|
163
|
+
"paths"=>[]}}}
|
161
164
|
```
|
162
165
|
|
163
166
|
#### Install
|
@@ -172,11 +175,14 @@ Fontist::Manifest::Install.call(manifest, confirmation: "yes")
|
|
172
175
|
It will install fonts and return their locations:
|
173
176
|
|
174
177
|
```ruby
|
175
|
-
{"Segoe UI"=>
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
178
|
+
{"Segoe UI"=> {
|
179
|
+
"Regular"=>{"full_name"=>"Segoe UI",
|
180
|
+
"paths"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"]},
|
181
|
+
"Bold"=>{"full_name"=>"Segoe UI Bold",
|
182
|
+
"paths"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]}},
|
183
|
+
"Roboto Mono"=> {
|
184
|
+
"Regular"=>{"full_name"=>"Roboto Mono Regular",
|
185
|
+
"paths"=>["/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"]}}}
|
180
186
|
```
|
181
187
|
|
182
188
|
### CLI
|
@@ -191,7 +197,8 @@ All searches are case-insensitive for ease of use.
|
|
191
197
|
|
192
198
|
The `install` command is similar to the `Font.install` call. It first checks
|
193
199
|
whether this font is already installed, and if not, then installs the font and
|
194
|
-
returns its paths.
|
200
|
+
returns its paths. Only font name (not formula name, nor font filename) could
|
201
|
+
be used as a parameter.
|
195
202
|
|
196
203
|
```
|
197
204
|
$ fontist install "segoe ui"
|
@@ -274,11 +281,17 @@ $ fontist manifest-locations manifest.yml
|
|
274
281
|
---
|
275
282
|
Segoe UI:
|
276
283
|
Regular:
|
277
|
-
|
284
|
+
full_name: Segoe UI
|
285
|
+
paths:
|
286
|
+
- "/Users/user/.fontist/fonts/SEGOEUI.TTF"
|
278
287
|
Bold:
|
279
|
-
|
288
|
+
full_name: Segoe UI Bold
|
289
|
+
paths:
|
290
|
+
- "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
|
280
291
|
Roboto Mono:
|
281
|
-
Regular:
|
292
|
+
Regular:
|
293
|
+
full_name:
|
294
|
+
paths: []
|
282
295
|
```
|
283
296
|
|
284
297
|
Since Segoe UI is installed, but Roboto Mono is not.
|
@@ -292,12 +305,18 @@ $ fontist manifest-install --confirm-license manifest.yml
|
|
292
305
|
---
|
293
306
|
Segoe UI:
|
294
307
|
Regular:
|
295
|
-
|
308
|
+
full_name: Segoe UI
|
309
|
+
paths:
|
310
|
+
- "/Users/user/.fontist/fonts/SEGOEUI.TTF"
|
296
311
|
Bold:
|
297
|
-
|
312
|
+
full_name: Segoe UI Bold
|
313
|
+
paths:
|
314
|
+
- "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
|
298
315
|
Roboto Mono:
|
299
316
|
Regular:
|
300
|
-
|
317
|
+
full_name: Roboto Mono Regular
|
318
|
+
paths:
|
319
|
+
- "/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"
|
301
320
|
```
|
302
321
|
|
303
322
|
#### Help
|
@@ -308,6 +327,15 @@ List of all commands could be seen by:
|
|
308
327
|
fontist help
|
309
328
|
```
|
310
329
|
|
330
|
+
### Configuration
|
331
|
+
|
332
|
+
By default Fontist uses the `~/.fontist` directory to store fonts and its
|
333
|
+
files. It could be changed with the `FONTIST_PATH` environment variable.
|
334
|
+
|
335
|
+
```sh
|
336
|
+
FONTIST_PATH=~/.fontist_new fontist update
|
337
|
+
```
|
338
|
+
|
311
339
|
## Development
|
312
340
|
|
313
341
|
We are following Sandi Metz's Rules for this gem, you can read the
|
data/lib/fontist.rb
CHANGED
data/lib/fontist/cli.rb
CHANGED
@@ -9,7 +9,7 @@ module Fontist
|
|
9
9
|
false
|
10
10
|
end
|
11
11
|
|
12
|
-
desc "install FONT", "Install font
|
12
|
+
desc "install FONT", "Install font"
|
13
13
|
option :force, type: :boolean, aliases: :f,
|
14
14
|
desc: "Install even if it's already installed in system"
|
15
15
|
option :confirm_license, type: :boolean, desc: "Confirm license agreement"
|
data/lib/fontist/font_formula.rb
CHANGED
@@ -83,12 +83,30 @@ module Fontist
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def match_fonts(
|
87
|
-
|
88
|
-
|
89
|
-
@matched_fonts.push(
|
86
|
+
def match_fonts(fonts_paths, font_name)
|
87
|
+
filenames = filenames_by_font_name(font_name)
|
88
|
+
paths = search_for_filenames(fonts_paths, filenames)
|
89
|
+
@matched_fonts.push(*paths)
|
90
90
|
|
91
|
-
|
91
|
+
paths
|
92
|
+
end
|
93
|
+
|
94
|
+
def filenames_by_font_name(font_name)
|
95
|
+
fonts.map do |f|
|
96
|
+
if f[:name].casecmp?(font_name)
|
97
|
+
f[:styles].map do |s|
|
98
|
+
s[:font]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end.flatten.compact
|
102
|
+
end
|
103
|
+
|
104
|
+
def search_for_filenames(paths, filenames)
|
105
|
+
paths.select do |path|
|
106
|
+
filenames.any? do |filename|
|
107
|
+
File.basename(path) == filename
|
108
|
+
end
|
109
|
+
end
|
92
110
|
end
|
93
111
|
|
94
112
|
def extract_from_collection(options)
|
@@ -103,13 +121,6 @@ module Fontist
|
|
103
121
|
end
|
104
122
|
end
|
105
123
|
|
106
|
-
def map_names_to_fonts(font_name)
|
107
|
-
fonts = Fontist::Formula.find_fonts(font_name)
|
108
|
-
fonts = fonts.map { |font| font.styles.map(&:font) }.flatten if fonts
|
109
|
-
|
110
|
-
fonts || []
|
111
|
-
end
|
112
|
-
|
113
124
|
def download_file(source)
|
114
125
|
url = source[:urls].first
|
115
126
|
Fontist.ui.say(%(Downloading font "#{key}" from #{url}))
|
data/lib/fontist/formula.rb
CHANGED
@@ -28,79 +28,39 @@ module Fontist
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def find
|
31
|
-
|
31
|
+
formulas.values.detect do |formula|
|
32
|
+
formula.fonts.any? do |f|
|
33
|
+
f.name.casecmp?(font_name)
|
34
|
+
end
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
def find_fonts
|
35
|
-
formulas
|
36
|
-
|
37
|
-
|
39
|
+
formulas.values.map do |formula|
|
40
|
+
formula.fonts.select do |f|
|
41
|
+
f.name.casecmp?(font_name)
|
42
|
+
end
|
43
|
+
end.flatten
|
38
44
|
end
|
39
45
|
|
40
46
|
def find_styles
|
41
|
-
formulas.values.
|
42
|
-
formula.fonts.
|
47
|
+
formulas.values.map do |formula|
|
48
|
+
formula.fonts.map do |f|
|
43
49
|
f.styles.select do |s|
|
44
50
|
f.name.casecmp?(font_name) && s.type.casecmp?(style_name)
|
45
51
|
end
|
46
52
|
end
|
47
|
-
end
|
53
|
+
end.flatten
|
48
54
|
end
|
49
55
|
|
50
56
|
private
|
51
57
|
|
52
58
|
attr_reader :font_name, :style_name
|
53
59
|
|
54
|
-
def find_formula
|
55
|
-
find_by_key || find_by_font_name || find_by_font || []
|
56
|
-
end
|
57
|
-
|
58
60
|
def formulas
|
59
61
|
@formulas ||= all.to_h
|
60
62
|
end
|
61
63
|
|
62
|
-
def take_fonts(formulas)
|
63
|
-
formulas.map(&:fonts).flatten
|
64
|
-
end
|
65
|
-
|
66
|
-
def find_by_key
|
67
|
-
matched_formulas = formulas.select do |key, _value|
|
68
|
-
key.to_s.casecmp?(font_name)
|
69
|
-
end
|
70
|
-
|
71
|
-
matched_formulas.empty? ? nil : matched_formulas.values
|
72
|
-
end
|
73
|
-
|
74
|
-
def find_by_font_name
|
75
|
-
matched_formulas = formulas.select do |key, value|
|
76
|
-
!value.fonts.map(&:name).grep(/#{font_name}/i).empty?
|
77
|
-
end
|
78
|
-
|
79
|
-
matched_formulas.empty? ? nil : matched_formulas.values
|
80
|
-
end
|
81
|
-
|
82
|
-
# Note
|
83
|
-
#
|
84
|
-
# These interface recursively look into every single font styles,
|
85
|
-
# so ideally try to avoid using it when possible, and that's why
|
86
|
-
# we've added it as last option in formula finder.
|
87
|
-
#
|
88
|
-
def find_by_font
|
89
|
-
matched_formulas = formulas.select do |key, value|
|
90
|
-
match_in_font_styles?(value[:fonts])
|
91
|
-
end
|
92
|
-
|
93
|
-
matched_formulas.empty? ? nil : matched_formulas.values
|
94
|
-
end
|
95
|
-
|
96
|
-
def match_in_font_styles?(fonts)
|
97
|
-
styles = fonts.select do |font|
|
98
|
-
!font.styles.map(&:font).grep(/#{font_name}/i).empty?
|
99
|
-
end
|
100
|
-
|
101
|
-
styles.empty? ? false : true
|
102
|
-
end
|
103
|
-
|
104
64
|
def check_and_register_font_formulas
|
105
65
|
$check_and_register_font_formulas ||= Fontist::Formulas.register_formulas
|
106
66
|
end
|
data/lib/fontist/system_font.rb
CHANGED
@@ -17,10 +17,10 @@ module Fontist
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def find
|
20
|
-
|
21
|
-
|
20
|
+
styles = find_styles
|
21
|
+
return unless styles
|
22
22
|
|
23
|
-
|
23
|
+
styles.map { |x| x[:path] }
|
24
24
|
end
|
25
25
|
|
26
26
|
def find_with_name
|
@@ -45,25 +45,6 @@ module Fontist
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def grep_font_paths(font, style = nil)
|
49
|
-
pattern = prepare_pattern(font, style)
|
50
|
-
|
51
|
-
paths = font_paths.map { |path| [File.basename(path), path] }.to_h
|
52
|
-
files = paths.keys
|
53
|
-
matched = files.grep(pattern)
|
54
|
-
paths.values_at(*matched).compact
|
55
|
-
end
|
56
|
-
|
57
|
-
def prepare_pattern(font, style = nil)
|
58
|
-
style = nil if style&.casecmp?("regular")
|
59
|
-
|
60
|
-
s = [font, style].compact.map { |x| Regexp.quote(x) }
|
61
|
-
.join(".*")
|
62
|
-
.gsub("\\ ", "\s?") # space independent
|
63
|
-
|
64
|
-
Regexp.new(s, Regexp::IGNORECASE)
|
65
|
-
end
|
66
|
-
|
67
48
|
def font_paths
|
68
49
|
@font_paths ||= Dir.glob((
|
69
50
|
user_sources +
|
@@ -72,11 +53,6 @@ module Fontist
|
|
72
53
|
).flatten.uniq)
|
73
54
|
end
|
74
55
|
|
75
|
-
def lookup_using_font_name
|
76
|
-
font_names = map_name_to_valid_font_names || []
|
77
|
-
font_paths.grep(/#{font_names.join("|")}/i) unless font_names.empty?
|
78
|
-
end
|
79
|
-
|
80
56
|
def fontist_fonts_path
|
81
57
|
@fontist_fonts_path ||= Fontist.fonts_path
|
82
58
|
end
|
@@ -85,17 +61,12 @@ module Fontist
|
|
85
61
|
Fontist::Utils::System.user_os
|
86
62
|
end
|
87
63
|
|
88
|
-
def map_name_to_valid_font_names
|
89
|
-
fonts = Formula.find_fonts(font)
|
90
|
-
fonts.map { |font| font.styles.map(&:font) }.flatten if fonts
|
91
|
-
end
|
92
|
-
|
93
64
|
def system_path_file
|
94
65
|
File.open(Fontist.system_file_path)
|
95
66
|
end
|
96
67
|
|
97
68
|
def default_sources
|
98
|
-
@default_sources ||= YAML.
|
69
|
+
@default_sources ||= YAML.safe_load(system_path_file)["system"][user_os.to_s]
|
99
70
|
end
|
100
71
|
|
101
72
|
def find_styles
|
data/lib/fontist/version.rb
CHANGED
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.7.
|
4
|
+
version: 1.7.2
|
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-12-
|
12
|
+
date: 2020-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: down
|