fontist 1.9.3 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/metanorma.yml +1 -1
- data/.github/workflows/rspec.yml +1 -1
- data/lib/fontist/cli.rb +19 -0
- data/lib/fontist/font.rb +8 -3
- data/lib/fontist/import/formula_builder.rb +5 -1
- data/lib/fontist/import/google_import.rb +4 -0
- data/lib/fontist/import/otf/font_file.rb +12 -3
- data/lib/fontist/import/otf_style.rb +10 -2
- data/lib/fontist/import/otfinfo/template.erb +6 -0
- data/lib/fontist/index.rb +7 -4
- data/lib/fontist/indexes/default_family_font_index.rb +21 -0
- data/lib/fontist/indexes/font_index.rb +8 -13
- data/lib/fontist/indexes/preferred_family_font_index.rb +24 -0
- data/lib/fontist/system_font.rb +6 -11
- data/lib/fontist/system_index.rb +106 -26
- data/lib/fontist/update.rb +7 -21
- data/lib/fontist/utils/downloader.rb +0 -1
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +29 -5
- metadata +4 -3
- data/lib/fontist/fontist_font.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2ed5346597364ad2d6cf6d2ecdc575baee6590f164cd79888a85c7ae0a67ed5
|
4
|
+
data.tar.gz: f7378c2d93061211db416dfa4ce7e49450dfd50ec01618f79dedb483d1a258ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30e8c3f17d17c275e1942a07c113feda490e426afa762e4a6c93a283a99f97010da04b4bd954c13e8cc2504211ad273b9aeb84b6af12232d46cd1d19b7c8b244
|
7
|
+
data.tar.gz: 6d8e216241908538339ecb0a06a92f0b31a590eef0ffe2e81bee78a97b18204f4fc4f2b70113a79ea1d87f6c815b125bfb58e6db500942c5d1019098bb3812a0
|
data/.github/workflows/rspec.yml
CHANGED
data/lib/fontist/cli.rb
CHANGED
@@ -32,6 +32,10 @@ module Fontist
|
|
32
32
|
false
|
33
33
|
end
|
34
34
|
|
35
|
+
class_option :preferred_family,
|
36
|
+
type: :boolean,
|
37
|
+
desc: "Use Preferred Family when available"
|
38
|
+
|
35
39
|
desc "install FONT", "Install font"
|
36
40
|
option :force, type: :boolean, aliases: :f,
|
37
41
|
desc: "Install even if it's already installed in system"
|
@@ -39,6 +43,7 @@ module Fontist
|
|
39
43
|
option :hide_licenses, type: :boolean, desc: "Hide license texts"
|
40
44
|
option :no_progress, type: :boolean, desc: "Hide download progress"
|
41
45
|
def install(font)
|
46
|
+
handle_class_options(options)
|
42
47
|
Fontist::Font.install(
|
43
48
|
font,
|
44
49
|
force: options[:force],
|
@@ -53,6 +58,7 @@ module Fontist
|
|
53
58
|
|
54
59
|
desc "uninstall/remove FONT", "Uninstall font by font or formula"
|
55
60
|
def uninstall(font)
|
61
|
+
handle_class_options(options)
|
56
62
|
fonts_paths = Fontist::Font.uninstall(font)
|
57
63
|
Fontist.ui.success("These fonts are removed:")
|
58
64
|
Fontist.ui.success(fonts_paths.join("\n"))
|
@@ -64,6 +70,7 @@ module Fontist
|
|
64
70
|
|
65
71
|
desc "status [FONT]", "Show paths of FONT or all fonts"
|
66
72
|
def status(font = nil)
|
73
|
+
handle_class_options(options)
|
67
74
|
paths = Fontist::Font.status(font)
|
68
75
|
return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if paths.empty?
|
69
76
|
|
@@ -74,6 +81,7 @@ module Fontist
|
|
74
81
|
|
75
82
|
desc "list [FONT]", "List installation status of FONT or fonts in fontist"
|
76
83
|
def list(font = nil)
|
84
|
+
handle_class_options(options)
|
77
85
|
formulas = Fontist::Font.list(font)
|
78
86
|
print_list(formulas)
|
79
87
|
success
|
@@ -83,6 +91,7 @@ module Fontist
|
|
83
91
|
|
84
92
|
desc "update", "Update formulas"
|
85
93
|
def update
|
94
|
+
handle_class_options(options)
|
86
95
|
Formula.update_formulas_repo
|
87
96
|
Fontist.ui.success("Formulas have been successfully updated.")
|
88
97
|
success
|
@@ -94,6 +103,7 @@ module Fontist
|
|
94
103
|
desc "manifest-locations MANIFEST",
|
95
104
|
"Get locations of fonts from MANIFEST (yaml)"
|
96
105
|
def manifest_locations(manifest)
|
106
|
+
handle_class_options(options)
|
97
107
|
paths = Fontist::Manifest::Locations.from_file(manifest)
|
98
108
|
print_yaml(paths)
|
99
109
|
success
|
@@ -105,6 +115,7 @@ module Fontist
|
|
105
115
|
option :accept_all_licenses, type: :boolean, aliases: "--confirm-license", desc: "Accept all license agreements"
|
106
116
|
option :hide_licenses, type: :boolean, desc: "Hide license texts"
|
107
117
|
def manifest_install(manifest)
|
118
|
+
handle_class_options(options)
|
108
119
|
paths = Fontist::Manifest::Install.from_file(
|
109
120
|
manifest,
|
110
121
|
confirmation: options[:accept_all_licenses] ? "yes" : "no",
|
@@ -124,6 +135,7 @@ module Fontist
|
|
124
135
|
option :subdir, desc: "Subdirectory to take fonts from, starting with the " \
|
125
136
|
"root dir, e.g.: stixfonts-2.10/fonts/static_otf. May include `fnmatch` patterns."
|
126
137
|
def create_formula(url)
|
138
|
+
handle_class_options(options)
|
127
139
|
require "fontist/import/create_formula"
|
128
140
|
name = Fontist::Import::CreateFormula.new(url, options).call
|
129
141
|
Fontist.ui.say("#{name} formula has been successfully created")
|
@@ -141,6 +153,8 @@ module Fontist
|
|
141
153
|
desc: "Updates indexes in the main repo (for backward " \
|
142
154
|
"compatibility with versions prior to 1.9)"
|
143
155
|
def rebuild_index
|
156
|
+
handle_class_options(options)
|
157
|
+
|
144
158
|
if options[:main_repo]
|
145
159
|
Fontist::Index.rebuild_for_main_repo
|
146
160
|
else
|
@@ -153,6 +167,7 @@ module Fontist
|
|
153
167
|
|
154
168
|
desc "import-sil", "Import formulas from SIL"
|
155
169
|
def import_sil
|
170
|
+
handle_class_options(options)
|
156
171
|
require "fontist/import/sil_import"
|
157
172
|
Fontist::Import::SilImport.new.call
|
158
173
|
end
|
@@ -162,6 +177,10 @@ module Fontist
|
|
162
177
|
|
163
178
|
private
|
164
179
|
|
180
|
+
def handle_class_options(options)
|
181
|
+
Fontist.preferred_family = options[:preferred_family]
|
182
|
+
end
|
183
|
+
|
165
184
|
def success
|
166
185
|
STATUS_SUCCESS
|
167
186
|
end
|
data/lib/fontist/font.rb
CHANGED
@@ -166,7 +166,7 @@ module Fontist
|
|
166
166
|
end
|
167
167
|
|
168
168
|
def uninstall_font
|
169
|
-
paths =
|
169
|
+
paths = find_fontist_paths
|
170
170
|
return unless paths
|
171
171
|
|
172
172
|
paths.each do |path|
|
@@ -176,8 +176,13 @@ module Fontist
|
|
176
176
|
paths
|
177
177
|
end
|
178
178
|
|
179
|
-
def
|
180
|
-
Fontist::
|
179
|
+
def find_fontist_paths
|
180
|
+
fonts = Fontist::SystemIndex.fontist_index.find(name, nil)
|
181
|
+
return unless fonts
|
182
|
+
|
183
|
+
fonts.map do |font|
|
184
|
+
font[:path]
|
185
|
+
end
|
181
186
|
end
|
182
187
|
|
183
188
|
def installed_paths
|
@@ -129,7 +129,7 @@ module Fontist
|
|
129
129
|
|
130
130
|
fonts = groups.map do |name, group|
|
131
131
|
{ name: name,
|
132
|
-
styles: group
|
132
|
+
styles: styles_from_files(group, style_type) }
|
133
133
|
end
|
134
134
|
|
135
135
|
fonts.sort_by do |x|
|
@@ -137,6 +137,10 @@ module Fontist
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
def styles_from_files(files, style_type)
|
141
|
+
files.map(&style_type).sort_by { |x| x[:type] }
|
142
|
+
end
|
143
|
+
|
140
144
|
def extract
|
141
145
|
@extractor.operations
|
142
146
|
end
|
@@ -156,6 +156,10 @@ module Fontist
|
|
156
156
|
h.merge!(family_name: style.family_name,
|
157
157
|
type: style.style,
|
158
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
|
159
163
|
h.merge!(style.to_h.select do |k, _|
|
160
164
|
%i(post_script_name version description copyright).include?(k)
|
161
165
|
end.compact)
|
@@ -10,7 +10,8 @@ module Fontist
|
|
10
10
|
otfinfo: Otfinfo::OtfinfoRequirement.new,
|
11
11
|
}.freeze
|
12
12
|
|
13
|
-
STYLE_ATTRIBUTES = %i[family_name type
|
13
|
+
STYLE_ATTRIBUTES = %i[family_name type preferred_family_name
|
14
|
+
preferred_type full_name post_script_name
|
14
15
|
version description copyright font
|
15
16
|
source_font].freeze
|
16
17
|
|
@@ -35,11 +36,19 @@ module Fontist
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def family_name
|
38
|
-
info["
|
39
|
+
info["Family"]
|
39
40
|
end
|
40
41
|
|
41
42
|
def type
|
42
|
-
info["
|
43
|
+
info["Subfamily"]
|
44
|
+
end
|
45
|
+
|
46
|
+
def preferred_family_name
|
47
|
+
info["Preferred family"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def preferred_type
|
51
|
+
info["Preferred subfamily"]
|
43
52
|
end
|
44
53
|
|
45
54
|
def full_name
|
@@ -7,8 +7,8 @@ module Fontist
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
style = { family_name: @info["
|
11
|
-
style: @info["
|
10
|
+
style = { family_name: @info["Family"],
|
11
|
+
style: @info["Subfamily"],
|
12
12
|
full_name: @info["Full name"],
|
13
13
|
post_script_name: @info["PostScript name"],
|
14
14
|
version: version(@info["Version"]),
|
@@ -16,6 +16,14 @@ module Fontist
|
|
16
16
|
filename: File.basename(@path),
|
17
17
|
copyright: @info["Copyright"] }
|
18
18
|
|
19
|
+
if @info["Preferred family"]
|
20
|
+
style[:preferred_family_name] = @info["Preferred family"]
|
21
|
+
end
|
22
|
+
|
23
|
+
if @info["Preferred subfamily"]
|
24
|
+
style[:preferred_style] = @info["Preferred subfamily"]
|
25
|
+
end
|
26
|
+
|
19
27
|
OpenStruct.new(style)
|
20
28
|
end
|
21
29
|
|
@@ -2,6 +2,12 @@
|
|
2
2
|
{
|
3
3
|
family_name: "<%= s.family_name %>",
|
4
4
|
style: "<%= s.style %>",
|
5
|
+
<%- if s.preferred_family_name -%>
|
6
|
+
preferred_family_name: "<%= s.preferred_family_name %>",
|
7
|
+
<%- end -%>
|
8
|
+
<%- if s.preferred_style -%>
|
9
|
+
preferred_type: "<%= s.preferred_style %>",
|
10
|
+
<%- end -%>
|
5
11
|
full_name: "<%= s.full_name %>",
|
6
12
|
<%- if s.post_script_name -%>
|
7
13
|
post_script_name: "<%= s.post_script_name %>",
|
data/lib/fontist/index.rb
CHANGED
@@ -19,25 +19,28 @@ module Fontist
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.do_rebuild_for_main_repo_with
|
22
|
-
Fontist.
|
22
|
+
Fontist.formula_preferred_family_index_path =
|
23
|
+
Fontist.formulas_repo_path.join("index.yml")
|
23
24
|
Fontist.formula_filename_index_path =
|
24
25
|
Fontist.formulas_repo_path.join("filename_index.yml")
|
25
26
|
|
26
27
|
rebuild
|
27
28
|
|
28
|
-
Fontist.
|
29
|
+
Fontist.formula_preferred_family_index_path = nil
|
29
30
|
Fontist.formula_filename_index_path = nil
|
30
31
|
end
|
31
32
|
|
32
33
|
def self.rebuild
|
33
|
-
Fontist::Indexes::
|
34
|
+
Fontist::Indexes::DefaultFamilyFontIndex.rebuild
|
35
|
+
Fontist::Indexes::PreferredFamilyFontIndex.rebuild
|
34
36
|
Fontist::Indexes::FilenameIndex.rebuild
|
35
37
|
|
36
38
|
reset_cache
|
37
39
|
end
|
38
40
|
|
39
41
|
def self.reset_cache
|
40
|
-
Fontist::Indexes::
|
42
|
+
Fontist::Indexes::DefaultFamilyFontIndex.reset_cache
|
43
|
+
Fontist::Indexes::PreferredFamilyFontIndex.reset_cache
|
41
44
|
Fontist::Indexes::FilenameIndex.reset_cache
|
42
45
|
end
|
43
46
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "base_index"
|
2
|
+
|
3
|
+
module Fontist
|
4
|
+
module Indexes
|
5
|
+
class DefaultFamilyFontIndex < BaseIndex
|
6
|
+
def self.path
|
7
|
+
Fontist.formula_index_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_formula(formula)
|
11
|
+
formula.fonts.each do |font|
|
12
|
+
add_index_formula(font.name, formula.to_index_formula)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def normalize_key(key)
|
17
|
+
key.downcase
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,21 +1,16 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "default_family_font_index"
|
2
|
+
require_relative "preferred_family_font_index"
|
2
3
|
|
3
4
|
module Fontist
|
4
5
|
module Indexes
|
5
|
-
class FontIndex
|
6
|
-
def self.
|
7
|
-
Fontist.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
formula.fonts.each do |font|
|
12
|
-
add_index_formula(font.name, formula.to_index_formula)
|
6
|
+
class FontIndex
|
7
|
+
def self.from_yaml
|
8
|
+
if Fontist.preferred_family?
|
9
|
+
PreferredFamilyFontIndex.from_yaml
|
10
|
+
else
|
11
|
+
DefaultFamilyFontIndex.from_yaml
|
13
12
|
end
|
14
13
|
end
|
15
|
-
|
16
|
-
def normalize_key(key)
|
17
|
-
key.downcase
|
18
|
-
end
|
19
14
|
end
|
20
15
|
end
|
21
16
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "base_index"
|
2
|
+
|
3
|
+
module Fontist
|
4
|
+
module Indexes
|
5
|
+
class PreferredFamilyFontIndex < BaseIndex
|
6
|
+
def self.path
|
7
|
+
Fontist.formula_preferred_family_index_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_formula(formula)
|
11
|
+
formula.fonts.each do |font|
|
12
|
+
font.styles.each do |style|
|
13
|
+
font_name = style.preferred_family_name || font.name
|
14
|
+
add_index_formula(font_name, formula.to_index_formula)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def normalize_key(key)
|
20
|
+
key.downcase
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/fontist/system_font.rb
CHANGED
@@ -3,10 +3,9 @@ require_relative "formula_paths"
|
|
3
3
|
|
4
4
|
module Fontist
|
5
5
|
class SystemFont
|
6
|
-
def initialize(font:, style: nil
|
6
|
+
def initialize(font:, style: nil)
|
7
7
|
@font = font
|
8
8
|
@style = style
|
9
|
-
@user_sources = sources || []
|
10
9
|
end
|
11
10
|
|
12
11
|
def self.font_paths
|
@@ -36,8 +35,8 @@ module Fontist
|
|
36
35
|
Dir.glob(Fontist.fonts_path.join("**"))
|
37
36
|
end
|
38
37
|
|
39
|
-
def self.find(font
|
40
|
-
new(font: font
|
38
|
+
def self.find(font)
|
39
|
+
new(font: font).find
|
41
40
|
end
|
42
41
|
|
43
42
|
def self.find_styles(font, style)
|
@@ -57,18 +56,14 @@ module Fontist
|
|
57
56
|
|
58
57
|
private
|
59
58
|
|
60
|
-
attr_reader :font, :style
|
59
|
+
attr_reader :font, :style
|
61
60
|
|
62
61
|
def find_by_index
|
63
|
-
SystemIndex.
|
62
|
+
SystemIndex.system_index.find(font, style)
|
64
63
|
end
|
65
64
|
|
66
65
|
def find_by_formulas
|
67
|
-
FormulaPaths.new(
|
68
|
-
end
|
69
|
-
|
70
|
-
def all_paths
|
71
|
-
@all_paths ||= Dir.glob(user_sources) + self.class.font_paths
|
66
|
+
FormulaPaths.new(self.class.font_paths).find(font, style)
|
72
67
|
end
|
73
68
|
end
|
74
69
|
end
|
data/lib/fontist/system_index.rb
CHANGED
@@ -4,22 +4,73 @@ module Fontist
|
|
4
4
|
class SystemIndex
|
5
5
|
include Utils::Locking
|
6
6
|
|
7
|
+
class DefaultFamily
|
8
|
+
def family_name(name)
|
9
|
+
name.font_family
|
10
|
+
end
|
11
|
+
|
12
|
+
def type(name)
|
13
|
+
name.font_subfamily
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class PreferredFamily
|
18
|
+
def family_name(name)
|
19
|
+
return name.font_family if name.preferred_family.empty?
|
20
|
+
|
21
|
+
name.preferred_family
|
22
|
+
end
|
23
|
+
|
24
|
+
def type(name)
|
25
|
+
return name.font_subfamily if name.preferred_subfamily.empty?
|
26
|
+
|
27
|
+
name.preferred_subfamily
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
PLATFORM_MACINTOSH = 1
|
32
|
+
PLATFORM_MICROSOFT = 3
|
33
|
+
|
34
|
+
ENCODING_MAC_ROMAN = 0
|
35
|
+
ENCODING_MS_UNICODE_BMP = 1
|
36
|
+
|
37
|
+
LANGUAGE_MAC_ENGLISH = 0
|
38
|
+
LANGUAGE_MS_ENGLISH_AMERICAN = 0x409
|
39
|
+
|
7
40
|
attr_reader :font_paths
|
8
41
|
|
9
|
-
def self.
|
10
|
-
|
42
|
+
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
|
11
52
|
end
|
12
53
|
|
13
|
-
def self.
|
14
|
-
|
54
|
+
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
|
15
64
|
end
|
16
65
|
|
17
|
-
def initialize(font_paths)
|
66
|
+
def initialize(index_path, font_paths, family)
|
67
|
+
@index_path = index_path
|
18
68
|
@font_paths = font_paths
|
69
|
+
@family = family
|
19
70
|
end
|
20
71
|
|
21
72
|
def find(font, style)
|
22
|
-
fonts =
|
73
|
+
fonts = index.select do |file|
|
23
74
|
file[:family_name].casecmp?(font) &&
|
24
75
|
(style.nil? || file[:type].casecmp?(style))
|
25
76
|
end
|
@@ -28,27 +79,27 @@ module Fontist
|
|
28
79
|
end
|
29
80
|
|
30
81
|
def rebuild
|
31
|
-
|
82
|
+
build_index
|
32
83
|
end
|
33
84
|
|
34
85
|
private
|
35
86
|
|
36
|
-
def
|
37
|
-
@
|
87
|
+
def index
|
88
|
+
@index ||= build_index
|
38
89
|
end
|
39
90
|
|
40
|
-
def
|
91
|
+
def build_index
|
41
92
|
lock(lock_path) do
|
42
|
-
|
93
|
+
do_build_index
|
43
94
|
end
|
44
95
|
end
|
45
96
|
|
46
97
|
def lock_path
|
47
|
-
|
98
|
+
"#{@index_path}.lock"
|
48
99
|
end
|
49
100
|
|
50
|
-
def
|
51
|
-
previous_index =
|
101
|
+
def do_build_index
|
102
|
+
previous_index = load_index
|
52
103
|
updated_index = detect_paths(font_paths, previous_index)
|
53
104
|
updated_index.tap do |index|
|
54
105
|
save_index(index) if changed?(updated_index, previous_index)
|
@@ -59,21 +110,23 @@ module Fontist
|
|
59
110
|
this.map { |x| x[:path] }.uniq.sort != other.map { |x| x[:path] }.uniq.sort
|
60
111
|
end
|
61
112
|
|
62
|
-
def
|
63
|
-
index = File.exist?(
|
113
|
+
def load_index
|
114
|
+
index = File.exist?(@index_path) ? YAML.load_file(@index_path) : []
|
115
|
+
check_index(index)
|
116
|
+
index
|
117
|
+
end
|
64
118
|
|
119
|
+
def check_index(index)
|
65
120
|
index.each do |item|
|
66
121
|
missing_keys = %i[path full_name family_name type] - item.keys
|
67
122
|
unless missing_keys.empty?
|
68
123
|
raise(Errors::FontIndexCorrupted, <<~MSG.chomp)
|
69
124
|
Font index is corrupted.
|
70
125
|
Item #{item.inspect} misses required attributes: #{missing_keys.join(', ')}.
|
71
|
-
You can remove the index file (#{
|
126
|
+
You can remove the index file (#{@index_path}) and try again.
|
72
127
|
MSG
|
73
128
|
end
|
74
129
|
end
|
75
|
-
|
76
|
-
index
|
77
130
|
end
|
78
131
|
|
79
132
|
def detect_paths(paths, index)
|
@@ -98,7 +151,9 @@ module Fontist
|
|
98
151
|
end
|
99
152
|
|
100
153
|
def detect_file_font(path)
|
101
|
-
|
154
|
+
content = File.read(path, mode: "rb")
|
155
|
+
file = TTFunk::File.new(content)
|
156
|
+
|
102
157
|
parse_font(file, path)
|
103
158
|
rescue StandardError
|
104
159
|
warn $!.message
|
@@ -111,6 +166,9 @@ module Fontist
|
|
111
166
|
parse_font(file, path)
|
112
167
|
end
|
113
168
|
end
|
169
|
+
rescue StandardError
|
170
|
+
warn $!.message
|
171
|
+
warn "Warning: File at #{path} not recognized as a font file."
|
114
172
|
end
|
115
173
|
|
116
174
|
def parse_font(file, path)
|
@@ -118,20 +176,42 @@ module Fontist
|
|
118
176
|
|
119
177
|
{
|
120
178
|
path: path,
|
121
|
-
full_name:
|
122
|
-
family_name:
|
123
|
-
type:
|
179
|
+
full_name: english_name(x.font_name),
|
180
|
+
family_name: english_name(@family.family_name(x)),
|
181
|
+
type: english_name(@family.type(x)),
|
124
182
|
}
|
125
183
|
end
|
126
184
|
|
127
|
-
def
|
185
|
+
def english_name(name)
|
186
|
+
visible_characters(find_english(name))
|
187
|
+
end
|
188
|
+
|
189
|
+
def find_english(name)
|
190
|
+
name.find { |x| microsoft_english?(x) } ||
|
191
|
+
name.find { |x| mac_english?(x) } ||
|
192
|
+
name.last
|
193
|
+
end
|
194
|
+
|
195
|
+
def microsoft_english?(string)
|
196
|
+
string.platform_id == PLATFORM_MICROSOFT &&
|
197
|
+
string.encoding_id == ENCODING_MS_UNICODE_BMP &&
|
198
|
+
string.language_id == LANGUAGE_MS_ENGLISH_AMERICAN
|
199
|
+
end
|
200
|
+
|
201
|
+
def mac_english?(string)
|
202
|
+
string.platform_id == PLATFORM_MACINTOSH &&
|
203
|
+
string.encoding_id == ENCODING_MAC_ROMAN &&
|
204
|
+
string.language_id == LANGUAGE_MAC_ENGLISH
|
205
|
+
end
|
206
|
+
|
207
|
+
def visible_characters(text)
|
128
208
|
text.gsub(/[^[:print:]]/, "").to_s
|
129
209
|
end
|
130
210
|
|
131
211
|
def save_index(index)
|
132
|
-
dir = File.dirname(
|
212
|
+
dir = File.dirname(@index_path)
|
133
213
|
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
134
|
-
File.write(
|
214
|
+
File.write(@index_path, YAML.dump(index))
|
135
215
|
end
|
136
216
|
end
|
137
217
|
end
|
data/lib/fontist/update.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
module Fontist
|
2
2
|
class Update
|
3
|
-
BRANCH = "master".freeze
|
4
|
-
|
5
3
|
def self.call
|
6
|
-
new
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(branch = "main")
|
10
|
-
@branch = branch
|
4
|
+
new.call
|
11
5
|
end
|
12
6
|
|
13
7
|
def call
|
@@ -23,21 +17,13 @@ module Fontist
|
|
23
17
|
dir = File.dirname(Fontist.formulas_repo_path)
|
24
18
|
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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)
|
31
26
|
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)
|
41
27
|
end
|
42
28
|
|
43
29
|
def update_private_repos
|
data/lib/fontist/version.rb
CHANGED
data/lib/fontist.rb
CHANGED
@@ -11,7 +11,6 @@ require "fontist/repo"
|
|
11
11
|
require "fontist/font"
|
12
12
|
require "fontist/formula"
|
13
13
|
require "fontist/system_font"
|
14
|
-
require "fontist/fontist_font"
|
15
14
|
require "fontist/manifest"
|
16
15
|
require "fontist/helpers"
|
17
16
|
|
@@ -65,15 +64,32 @@ module Fontist
|
|
65
64
|
end
|
66
65
|
|
67
66
|
def self.system_index_path
|
68
|
-
Fontist.fontist_path.join("system_index.yml")
|
67
|
+
Fontist.fontist_path.join("system_index.default_family.yml")
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.system_preferred_family_index_path
|
71
|
+
Fontist.fontist_path.join("system_index.preferred_family.yml")
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.fontist_index_path
|
75
|
+
Fontist.fontist_path.join("fontist_index.default_family.yml")
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.fontist_preferred_family_index_path
|
79
|
+
Fontist.fontist_path.join("fontist_index.preferred_family.yml")
|
69
80
|
end
|
70
81
|
|
71
82
|
def self.formula_index_path
|
72
|
-
|
83
|
+
Fontist.formula_index_dir.join("formula_index.default_family.yml")
|
73
84
|
end
|
74
85
|
|
75
|
-
def self.
|
76
|
-
@
|
86
|
+
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
|
77
93
|
end
|
78
94
|
|
79
95
|
def self.formula_filename_index_path
|
@@ -88,4 +104,12 @@ module Fontist
|
|
88
104
|
def self.formula_index_dir
|
89
105
|
Fontist.fontist_path
|
90
106
|
end
|
107
|
+
|
108
|
+
def self.preferred_family?
|
109
|
+
!!@preferred_family
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.preferred_family=(bool)
|
113
|
+
@preferred_family = bool
|
114
|
+
end
|
91
115
|
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.
|
4
|
+
version: 1.10.0
|
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-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|
@@ -262,7 +262,6 @@ files:
|
|
262
262
|
- lib/fontist/font.rb
|
263
263
|
- lib/fontist/font_installer.rb
|
264
264
|
- lib/fontist/font_path.rb
|
265
|
-
- lib/fontist/fontist_font.rb
|
266
265
|
- lib/fontist/formula.rb
|
267
266
|
- lib/fontist/formula_paths.rb
|
268
267
|
- lib/fontist/helpers.rb
|
@@ -296,9 +295,11 @@ files:
|
|
296
295
|
- lib/fontist/import/text_helper.rb
|
297
296
|
- lib/fontist/index.rb
|
298
297
|
- lib/fontist/indexes/base_index.rb
|
298
|
+
- lib/fontist/indexes/default_family_font_index.rb
|
299
299
|
- lib/fontist/indexes/filename_index.rb
|
300
300
|
- lib/fontist/indexes/font_index.rb
|
301
301
|
- lib/fontist/indexes/index_formula.rb
|
302
|
+
- lib/fontist/indexes/preferred_family_font_index.rb
|
302
303
|
- lib/fontist/manifest.rb
|
303
304
|
- lib/fontist/manifest/install.rb
|
304
305
|
- lib/fontist/manifest/locations.rb
|
data/lib/fontist/fontist_font.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
class FontistFont
|
3
|
-
def initialize(font_name:)
|
4
|
-
@font_name = font_name
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.find(name)
|
8
|
-
new(font_name: name).find
|
9
|
-
end
|
10
|
-
|
11
|
-
def find
|
12
|
-
styles = FormulaPaths.new(font_paths).find(@font_name)
|
13
|
-
return unless styles
|
14
|
-
|
15
|
-
styles.map { |x| x[:path] }
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def font_paths
|
21
|
-
Dir.glob(Fontist.fonts_path.join("**"))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|