fontist 1.17.1 → 1.19.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/test-and-release.yml +1 -0
- data/README.adoc +51 -4
- data/fontist.gemspec +1 -0
- data/lib/fontist/cli/class_options.rb +28 -0
- data/lib/fontist/cli.rb +5 -16
- data/lib/fontist/config.rb +78 -0
- data/lib/fontist/config_cli.rb +58 -0
- data/lib/fontist/errors.rb +2 -0
- data/lib/fontist/exclude.yml +1 -0
- data/lib/fontist/import/google/new_fonts_fetcher.rb +13 -3
- data/lib/fontist/import/google.rb +2 -0
- data/lib/fontist/import/google_import.rb +7 -2
- data/lib/fontist/import/macos.rb +5 -1
- data/lib/fontist/import_cli.rb +8 -1
- data/lib/fontist/system_font.rb +5 -2
- data/lib/fontist/system_index.rb +17 -3
- data/lib/fontist/utils/cache.rb +1 -1
- data/lib/fontist/utils/downloader.rb +2 -2
- data/lib/fontist/utils/file_magic.rb +35 -0
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +30 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f726f1ac899163c9c7346d540f5bcaf831d522dd59f3e3afd5bed661560ea40
|
4
|
+
data.tar.gz: a94c77482bd16d9f751b2d3d713e13bf1aefd78703d7bba973c8d2649469035d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d0fbfe9abf98ee2b28b2cf7f1aa73d0d3003519345d2f68f684043fb462f5df26a19a662e005ff07eb882923e3becbd52c616254ab6a704423a08f7c4588797
|
7
|
+
data.tar.gz: 74dd96f8a564fbcfab6d6372e0729b4aab1c3e80d14fd358626e8beaec505acdeb21b3e4de1eb589a13c9a490c8f595dc1e3ca40fc9650ae24dc29e68234a214
|
data/README.adoc
CHANGED
@@ -78,6 +78,9 @@ NOTE: See <<preferred-family-change>> for the differences between
|
|
78
78
|
`-v, --verbose`:: Set the log level to debug. It prints formulas excluded
|
79
79
|
during installation and information for developers of fontist.
|
80
80
|
|
81
|
+
`-c, --no-cache`:: Prefer direct download even when a file is already cached in
|
82
|
+
a system.
|
83
|
+
|
81
84
|
=== Install fonts: `fontist install`
|
82
85
|
|
83
86
|
Fontist checks whether this font is already installed, and if not, then installs
|
@@ -299,6 +302,41 @@ Roboto Mono:
|
|
299
302
|
- "/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"
|
300
303
|
----
|
301
304
|
|
305
|
+
=== Work with fontist config: `fontist config`
|
306
|
+
|
307
|
+
Fontist supports system-wide settings for the following parameters:
|
308
|
+
|
309
|
+
`fonts_path`:: Sets path where to install fonts (default: `~/.fontist/fonts`)
|
310
|
+
|
311
|
+
`open_timeout`:: Sets timeout for opening a connection during download
|
312
|
+
(default: `10`)
|
313
|
+
|
314
|
+
`read_timeout`:: Sets timeout for reading the opened connection during download
|
315
|
+
(default: `10`)
|
316
|
+
|
317
|
+
Show current attributes in the config:
|
318
|
+
|
319
|
+
[source,sh]
|
320
|
+
----
|
321
|
+
$ fontist config show
|
322
|
+
Current config:
|
323
|
+
read_timeout: 5
|
324
|
+
----
|
325
|
+
|
326
|
+
Assign a value to an attribute:
|
327
|
+
|
328
|
+
[source,sh]
|
329
|
+
----
|
330
|
+
$ fontist config set read_timeout 60
|
331
|
+
----
|
332
|
+
|
333
|
+
Restore a default value of an attribute:
|
334
|
+
|
335
|
+
[source,sh]
|
336
|
+
----
|
337
|
+
$ fontist config delete read_timeout
|
338
|
+
----
|
339
|
+
|
302
340
|
=== Work with Fontconfig: `fontist fontconfig`
|
303
341
|
|
304
342
|
Fontconfig is a software designed to provide fonts to other programs. It is
|
@@ -341,7 +379,7 @@ List of all commands could be seen by:
|
|
341
379
|
fontist help
|
342
380
|
----
|
343
381
|
|
344
|
-
=== Configuration
|
382
|
+
=== Configuration with environment variables
|
345
383
|
|
346
384
|
By default Fontist uses the `~/.fontist` directory to store fonts and its
|
347
385
|
files. It could be changed with the `FONTIST_PATH` environment variable.
|
@@ -621,6 +659,15 @@ Apple Support site:
|
|
621
659
|
WARNING: Fontist does not allow installing macOS-specific fonts on non-macOS
|
622
660
|
platforms due to font license restrictions of those fonts.
|
623
661
|
|
662
|
+
=== Known problematic fonts
|
663
|
+
|
664
|
+
* NISC18030.ttf (GB18030 Bitmap) - macOS, more info in
|
665
|
+
https://github.com/fontist/fontist/issues/344[the NISC18030 issue]
|
666
|
+
|
667
|
+
The full list of known problematic fonts:
|
668
|
+
|
669
|
+
* https://github.com/fontist/fontist/blob/main/lib/fontist/exclude.yml[List of fonts excluded from usage]
|
670
|
+
|
624
671
|
|
625
672
|
== Advanced usage
|
626
673
|
|
@@ -826,7 +873,7 @@ For file paths, specify the file path as argument:
|
|
826
873
|
|
827
874
|
[source,sh]
|
828
875
|
----
|
829
|
-
wget https://www.latofonts.com/
|
876
|
+
wget https://www.latofonts.com/files/Lato2OFL.zip
|
830
877
|
fontist create-formula lato.zip
|
831
878
|
----
|
832
879
|
|
@@ -834,7 +881,7 @@ For URLs, simply specify the URL as the argument:
|
|
834
881
|
|
835
882
|
[source,sh]
|
836
883
|
----
|
837
|
-
fontist create-formula https://www.latofonts.com/
|
884
|
+
fontist create-formula https://www.latofonts.com/files/Lato2OFL.zip
|
838
885
|
# > file created at lato.yml because the file downloaded is lato.zip
|
839
886
|
----
|
840
887
|
|
@@ -843,7 +890,7 @@ private formula repository location.
|
|
843
890
|
|
844
891
|
[source,sh]
|
845
892
|
----
|
846
|
-
fontist create-formula https://www.latofonts.com/
|
893
|
+
fontist create-formula https://www.latofonts.com/files/Lato2OFL.zip
|
847
894
|
cp lato.yml ~/.fontist/formulas/Formulas/
|
848
895
|
----
|
849
896
|
|
data/fontist.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.add_runtime_dependency "down", "~> 5.0"
|
33
33
|
spec.add_runtime_dependency "extract_ttc", "~> 0.1"
|
34
|
+
spec.add_runtime_dependency "json", "~> 2.0"
|
34
35
|
spec.add_runtime_dependency "nokogiri", "~> 1.0"
|
35
36
|
spec.add_runtime_dependency "mime-types", "~> 3.0"
|
36
37
|
spec.add_runtime_dependency "sys-uname", "~> 1.2"
|
@@ -1,9 +1,37 @@
|
|
1
1
|
module Fontist
|
2
2
|
class CLI < Thor
|
3
3
|
module ClassOptions
|
4
|
+
# rubocop:disable Metrics/MethodLength
|
5
|
+
def self.included(base)
|
6
|
+
base.class_option :preferred_family,
|
7
|
+
type: :boolean,
|
8
|
+
desc: "Use Preferred Family when available"
|
9
|
+
|
10
|
+
base.class_option :quiet,
|
11
|
+
aliases: :q,
|
12
|
+
type: :boolean,
|
13
|
+
desc: "Hide all messages"
|
14
|
+
|
15
|
+
base.class_option :verbose,
|
16
|
+
aliases: :v,
|
17
|
+
type: :boolean,
|
18
|
+
desc: "Print debug messages"
|
19
|
+
|
20
|
+
base.class_option :no_cache,
|
21
|
+
aliases: :c,
|
22
|
+
type: :boolean,
|
23
|
+
desc: "Avoid using cache during download"
|
24
|
+
|
25
|
+
base.class_option :formulas_path,
|
26
|
+
type: :string,
|
27
|
+
desc: "Path to formulas"
|
28
|
+
end
|
29
|
+
# rubocop:enable Metrics/MethodLength
|
30
|
+
|
4
31
|
def handle_class_options(options)
|
5
32
|
Fontist.preferred_family = options[:preferred_family]
|
6
33
|
Fontist.log_level = log_level(options)
|
34
|
+
Fontist.use_cache = !options[:no_cache]
|
7
35
|
|
8
36
|
if options[:formulas_path]
|
9
37
|
Fontist.formulas_path = Pathname.new(options[:formulas_path])
|
data/lib/fontist/cli.rb
CHANGED
@@ -4,6 +4,7 @@ require "fontist/repo_cli"
|
|
4
4
|
require "fontist/cache_cli"
|
5
5
|
require "fontist/import_cli"
|
6
6
|
require "fontist/fontconfig_cli"
|
7
|
+
require "fontist/config_cli"
|
7
8
|
|
8
9
|
module Fontist
|
9
10
|
class CLI < Thor
|
@@ -26,6 +27,7 @@ module Fontist
|
|
26
27
|
STATUS_FONTCONFIG_NOT_FOUND = 14
|
27
28
|
STATUS_FONTCONFIG_FILE_NOT_FOUND = 15
|
28
29
|
STATUS_FONTIST_VERSION_ERROR = 15
|
30
|
+
STATUS_INVALID_CONFIG_ATTRIBUTE = 16
|
29
31
|
|
30
32
|
ERROR_TO_STATUS = {
|
31
33
|
Fontist::Errors::UnsupportedFontError => [STATUS_NON_SUPPORTED_FONT_ERROR],
|
@@ -58,22 +60,6 @@ module Fontist
|
|
58
60
|
false
|
59
61
|
end
|
60
62
|
|
61
|
-
class_option :preferred_family,
|
62
|
-
type: :boolean,
|
63
|
-
desc: "Use Preferred Family when available"
|
64
|
-
|
65
|
-
class_option :quiet,
|
66
|
-
aliases: :q,
|
67
|
-
type: :boolean,
|
68
|
-
desc: "Hide all messages"
|
69
|
-
|
70
|
-
class_option :verbose,
|
71
|
-
aliases: :v,
|
72
|
-
type: :boolean,
|
73
|
-
desc: "Print debug messages"
|
74
|
-
|
75
|
-
class_option :formulas_path, type: :string, desc: "Path to formulas"
|
76
|
-
|
77
63
|
desc "install FONT", "Install font"
|
78
64
|
option :force, type: :boolean, aliases: :f,
|
79
65
|
desc: "Install even if already installed in system"
|
@@ -221,6 +207,9 @@ module Fontist
|
|
221
207
|
desc "fontconfig SUBCOMMAND ...ARGS", "Manage fontconfig"
|
222
208
|
subcommand "fontconfig", Fontist::FontconfigCLI
|
223
209
|
|
210
|
+
desc "config SUBCOMMAND ...ARGS", "Manage fontist config"
|
211
|
+
subcommand "config", Fontist::ConfigCLI
|
212
|
+
|
224
213
|
desc "cache SUBCOMMAND ...ARGS", "Manage fontist cache"
|
225
214
|
subcommand "cache", Fontist::CacheCLI
|
226
215
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Fontist
|
2
|
+
class Config
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@custom_values = load_config_file
|
7
|
+
end
|
8
|
+
|
9
|
+
def values
|
10
|
+
default_values.merge(@custom_values)
|
11
|
+
end
|
12
|
+
|
13
|
+
def custom_values
|
14
|
+
@custom_values
|
15
|
+
end
|
16
|
+
|
17
|
+
def set(key, value)
|
18
|
+
attr = key.to_sym
|
19
|
+
unless default_values.key?(attr)
|
20
|
+
raise Errors::InvalidConfigAttributeError,
|
21
|
+
"No such attribute '#{attr}' exists."
|
22
|
+
end
|
23
|
+
|
24
|
+
v = normalize_value(value)
|
25
|
+
if respond_to?("#{attr}=")
|
26
|
+
public_send("#{attr}=", v)
|
27
|
+
else
|
28
|
+
@custom_values[attr] = v
|
29
|
+
end
|
30
|
+
|
31
|
+
persist
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete(key)
|
35
|
+
@custom_values.delete(key.to_sym)
|
36
|
+
|
37
|
+
persist
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_value(key)
|
41
|
+
default_values[key.to_sym]
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_values
|
45
|
+
{ fonts_path: Fontist.fontist_path.join("fonts"),
|
46
|
+
open_timeout: 10,
|
47
|
+
read_timeout: 10 }
|
48
|
+
end
|
49
|
+
|
50
|
+
def persist
|
51
|
+
values = @custom_values.transform_keys(&:to_s)
|
52
|
+
FileUtils.mkdir_p(File.dirname(Fontist.config_path))
|
53
|
+
File.write(Fontist.config_path, YAML.dump(values))
|
54
|
+
end
|
55
|
+
|
56
|
+
def load
|
57
|
+
@custom_values = load_config_file
|
58
|
+
end
|
59
|
+
|
60
|
+
def fonts_path=(value)
|
61
|
+
@custom_values[:fonts_path] = File.expand_path(value)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def load_config_file
|
67
|
+
return {} unless File.exist?(Fontist.config_path)
|
68
|
+
|
69
|
+
YAML.load_file(Fontist.config_path).transform_keys(&:to_sym)
|
70
|
+
end
|
71
|
+
|
72
|
+
def normalize_value(value)
|
73
|
+
return value.to_i if value.to_i.to_s == value # detect integer
|
74
|
+
|
75
|
+
value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Fontist
|
2
|
+
class ConfigCLI < Thor
|
3
|
+
include CLI::ClassOptions
|
4
|
+
|
5
|
+
desc "show", "Show values of the current config"
|
6
|
+
def show
|
7
|
+
handle_class_options(options)
|
8
|
+
values = Config.instance.custom_values
|
9
|
+
|
10
|
+
if values.empty?
|
11
|
+
Fontist.ui.success("Config is empty.")
|
12
|
+
else
|
13
|
+
Fontist.ui.success("Current config:")
|
14
|
+
Fontist.ui.success(format_hash(values))
|
15
|
+
end
|
16
|
+
|
17
|
+
CLI::STATUS_SUCCESS
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "set KEY VALUE", "Set the KEY attribute to VALUE in the current config"
|
21
|
+
def set(key, value)
|
22
|
+
handle_class_options(options)
|
23
|
+
Config.instance.set(key, value)
|
24
|
+
Fontist.ui.success("'#{key}' set to '#{value}'.")
|
25
|
+
CLI::STATUS_SUCCESS
|
26
|
+
rescue Errors::InvalidConfigAttributeError => e
|
27
|
+
Fontist.ui.error(e.message)
|
28
|
+
CLI::STATUS_INVALID_CONFIG_ATTRIBUTE
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "delete KEY", "Delete the KEY attribute from the current config"
|
32
|
+
def delete(key)
|
33
|
+
handle_class_options(options)
|
34
|
+
Config.instance.delete(key)
|
35
|
+
Fontist.ui.success(
|
36
|
+
"'#{key}' reset to default ('#{Config.instance.default_value(key)}').",
|
37
|
+
)
|
38
|
+
CLI::STATUS_SUCCESS
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "keys", "Print all available config attributes"
|
42
|
+
def keys
|
43
|
+
handle_class_options(options)
|
44
|
+
Fontist.ui.say("Available keys:")
|
45
|
+
Config.instance.default_values.each do |key, value|
|
46
|
+
Fontist.ui.say("#{key} (default: #{value})")
|
47
|
+
end
|
48
|
+
CLI::STATUS_SUCCESS
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def format_hash(hash)
|
54
|
+
h = hash.transform_keys(&:to_s)
|
55
|
+
YAML.dump(h).gsub(/^---.*$/, "").strip
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/fontist/errors.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
- NISC18030.ttf
|
@@ -9,8 +9,9 @@ module Fontist
|
|
9
9
|
REPO_URL = "https://github.com/google/fonts.git".freeze
|
10
10
|
SKIPLIST_PATH = File.expand_path("skiplist.yml", __dir__)
|
11
11
|
|
12
|
-
def initialize(logging: false)
|
12
|
+
def initialize(logging: false, limit: nil)
|
13
13
|
@logging = logging
|
14
|
+
@limit = limit
|
14
15
|
end
|
15
16
|
|
16
17
|
def call
|
@@ -30,11 +31,20 @@ module Fontist
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def fetch_new_paths
|
33
|
-
|
34
|
-
|
34
|
+
new_paths = []
|
35
|
+
|
36
|
+
fetch_fonts_paths.each do |path|
|
37
|
+
new = log_font(path) do
|
35
38
|
new?(path)
|
36
39
|
end
|
40
|
+
|
41
|
+
next unless new
|
42
|
+
|
43
|
+
new_paths << path
|
44
|
+
return new_paths if @limit && new_paths.size >= @limit
|
37
45
|
end
|
46
|
+
|
47
|
+
new_paths
|
38
48
|
end
|
39
49
|
|
40
50
|
def fetch_fonts_paths
|
@@ -6,16 +6,21 @@ require_relative "create_formula"
|
|
6
6
|
module Fontist
|
7
7
|
module Import
|
8
8
|
class GoogleImport
|
9
|
+
def initialize(options)
|
10
|
+
@max_count = options[:max_count] || Google::DEFAULT_MAX_COUNT
|
11
|
+
end
|
12
|
+
|
9
13
|
def call
|
10
14
|
fonts = new_fonts
|
11
15
|
create_formulas(fonts)
|
12
|
-
rebuild_index
|
16
|
+
rebuild_index unless fonts.empty?
|
13
17
|
end
|
14
18
|
|
15
19
|
private
|
16
20
|
|
17
21
|
def new_fonts
|
18
|
-
Fontist::Import::Google::NewFontsFetcher.new(logging: true
|
22
|
+
Fontist::Import::Google::NewFontsFetcher.new(logging: true,
|
23
|
+
limit: @max_count).call
|
19
24
|
end
|
20
25
|
|
21
26
|
def create_formulas(fonts)
|
data/lib/fontist/import/macos.rb
CHANGED
@@ -8,6 +8,10 @@ module Fontist
|
|
8
8
|
FONT_XML = "/System/Library/AssetsV2/com_apple_MobileAsset_Font6/com_apple_MobileAsset_Font6.xml".freeze # rubocop:disable Layout/LineLength
|
9
9
|
HOMEPAGE = "https://support.apple.com/en-om/HT211240#document".freeze
|
10
10
|
|
11
|
+
def initialize(font_xml = FONT_XML)
|
12
|
+
@font_xml = font_xml
|
13
|
+
end
|
14
|
+
|
11
15
|
def call
|
12
16
|
links.each do |link|
|
13
17
|
create_formula(link)
|
@@ -21,7 +25,7 @@ module Fontist
|
|
21
25
|
private
|
22
26
|
|
23
27
|
def links
|
24
|
-
data = Plist.parse_xml(
|
28
|
+
data = Plist.parse_xml(@font_xml)
|
25
29
|
data["Assets"].map do |x|
|
26
30
|
x.values_at("__BaseURL", "__RelativePath").join
|
27
31
|
end
|
data/lib/fontist/import_cli.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
|
+
require_relative "import/google"
|
2
|
+
|
1
3
|
module Fontist
|
2
4
|
class ImportCLI < Thor
|
3
5
|
include CLI::ClassOptions
|
4
6
|
|
5
7
|
desc "google", "Import Google fonts"
|
8
|
+
option :max_count,
|
9
|
+
type: :numeric, aliases: :n,
|
10
|
+
desc: "Limit the number of formulas to import " \
|
11
|
+
"(default is #{Fontist::Import::Google::DEFAULT_MAX_COUNT})."
|
12
|
+
|
6
13
|
def google
|
7
14
|
handle_class_options(options)
|
8
15
|
require "fontist/import/google_import"
|
9
|
-
Fontist::Import::GoogleImport.new.call
|
16
|
+
Fontist::Import::GoogleImport.new(options).call
|
10
17
|
CLI::STATUS_SUCCESS
|
11
18
|
end
|
12
19
|
|
data/lib/fontist/system_font.rb
CHANGED
@@ -16,9 +16,8 @@ module Fontist
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.load_system_font_paths
|
19
|
-
config_path = Fontist.system_file_path
|
20
19
|
os = Fontist::Utils::System.user_os.to_s
|
21
|
-
templates =
|
20
|
+
templates = system_config["system"][os]["paths"]
|
22
21
|
patterns = expand_paths(templates)
|
23
22
|
|
24
23
|
Dir.glob(patterns)
|
@@ -26,6 +25,10 @@ module Fontist
|
|
26
25
|
# "Case sensitivity depends on your system"
|
27
26
|
end
|
28
27
|
|
28
|
+
def self.system_config
|
29
|
+
YAML.load_file(Fontist.system_file_path)
|
30
|
+
end
|
31
|
+
|
29
32
|
def self.reset_system_font_paths_cache
|
30
33
|
@system_font_paths = nil
|
31
34
|
end
|
data/lib/fontist/system_index.rb
CHANGED
@@ -66,6 +66,10 @@ module Fontist
|
|
66
66
|
Fontist.preferred_family? ? PreferredFamily.new : DefaultFamily.new
|
67
67
|
end
|
68
68
|
|
69
|
+
def excluded_fonts
|
70
|
+
@excluded_fonts ||= YAML.load_file(Fontist.excluded_fonts_path)
|
71
|
+
end
|
72
|
+
|
69
73
|
def initialize(index_path, font_paths_fetcher, family)
|
70
74
|
@index_path = index_path
|
71
75
|
@font_paths_fetcher = font_paths_fetcher
|
@@ -154,16 +158,26 @@ module Fontist
|
|
154
158
|
end
|
155
159
|
|
156
160
|
def detect_fonts(path)
|
161
|
+
return if excluded?(path)
|
162
|
+
|
163
|
+
gather_fonts(path)
|
164
|
+
rescue Errors::FontFileError => e
|
165
|
+
print_recognition_error(e, path)
|
166
|
+
end
|
167
|
+
|
168
|
+
def excluded?(path)
|
169
|
+
excluded_fonts.include?(File.basename(path))
|
170
|
+
end
|
171
|
+
|
172
|
+
def gather_fonts(path)
|
157
173
|
case File.extname(path).gsub(/^\./, "").downcase
|
158
174
|
when "ttf", "otf"
|
159
175
|
detect_file_font(path)
|
160
176
|
when "ttc"
|
161
177
|
detect_collection_fonts(path)
|
162
178
|
else
|
163
|
-
|
179
|
+
print_recognition_error(Errors::UnknownFontTypeError.new(path), path)
|
164
180
|
end
|
165
|
-
rescue Errors::FontFileError => e
|
166
|
-
print_recognition_error(e, path)
|
167
181
|
end
|
168
182
|
|
169
183
|
def print_recognition_error(exception, path)
|
data/lib/fontist/utils/cache.rb
CHANGED
@@ -80,8 +80,8 @@ module Fontist
|
|
80
80
|
def do_download_file_with_progress_bar(progress_bar)
|
81
81
|
Down.download(
|
82
82
|
url,
|
83
|
-
open_timeout:
|
84
|
-
read_timeout:
|
83
|
+
open_timeout: Fontist.open_timeout,
|
84
|
+
read_timeout: Fontist.read_timeout,
|
85
85
|
max_redirects: 10,
|
86
86
|
headers: headers,
|
87
87
|
content_length_proc: ->(content_length) {
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Utils
|
3
|
+
class FileMagic
|
4
|
+
MAP_MAGIC_TO_TYPE = {
|
5
|
+
"\x00\x01\x00\x00\x00" => :ttf,
|
6
|
+
"\x4f\x54\x54\x4f" => :otf,
|
7
|
+
"\x74\x74\x63\x66" => :ttc,
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def self.detect(path)
|
11
|
+
new(path).detect
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.max_magic
|
15
|
+
@max_magic ||= MAP_MAGIC_TO_TYPE.keys.map(&:bytesize).max
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(path)
|
19
|
+
@path = path
|
20
|
+
end
|
21
|
+
|
22
|
+
def detect
|
23
|
+
beginning = File.binread(@path, self.class.max_magic)
|
24
|
+
|
25
|
+
MAP_MAGIC_TO_TYPE.each do |magic, type|
|
26
|
+
slice = beginning.byteslice(0, magic.bytesize)
|
27
|
+
|
28
|
+
return type if slice == magic
|
29
|
+
end
|
30
|
+
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/fontist/version.rb
CHANGED
data/lib/fontist.rb
CHANGED
@@ -13,6 +13,7 @@ require "fontist/formula"
|
|
13
13
|
require "fontist/system_font"
|
14
14
|
require "fontist/manifest"
|
15
15
|
require "fontist/helpers"
|
16
|
+
require "fontist/config"
|
16
17
|
|
17
18
|
module Fontist
|
18
19
|
def self.ui
|
@@ -36,7 +37,7 @@ module Fontist
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def self.fonts_path
|
39
|
-
|
40
|
+
Pathname.new(config[:fonts_path])
|
40
41
|
end
|
41
42
|
|
42
43
|
def self.formulas_repo_path
|
@@ -75,6 +76,10 @@ module Fontist
|
|
75
76
|
Fontist.lib_path.join("fontist", "system.yml")
|
76
77
|
end
|
77
78
|
|
79
|
+
def self.excluded_fonts_path
|
80
|
+
Fontist.lib_path.join("fontist", "exclude.yml")
|
81
|
+
end
|
82
|
+
|
78
83
|
def self.system_index_path
|
79
84
|
Fontist.fontist_path.join("system_index.default_family.yml")
|
80
85
|
end
|
@@ -119,6 +124,30 @@ module Fontist
|
|
119
124
|
@preferred_family = bool
|
120
125
|
end
|
121
126
|
|
127
|
+
def self.open_timeout
|
128
|
+
config[:open_timeout]
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.read_timeout
|
132
|
+
config[:read_timeout]
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.config
|
136
|
+
Fontist::Config.instance.values
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.config_path
|
140
|
+
Fontist.fontist_path.join("config.yml")
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.use_cache?
|
144
|
+
instance_variable_defined?("@use_cache") ? @use_cache : true
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.use_cache=(bool)
|
148
|
+
@use_cache = bool
|
149
|
+
end
|
150
|
+
|
122
151
|
def self.log_level=(level)
|
123
152
|
Fontist.ui.level = level
|
124
153
|
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.19.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:
|
11
|
+
date: 2024-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: nokogiri
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -306,7 +320,10 @@ files:
|
|
306
320
|
- lib/fontist/cli.rb
|
307
321
|
- lib/fontist/cli/class_options.rb
|
308
322
|
- lib/fontist/collection_file.rb
|
323
|
+
- lib/fontist/config.rb
|
324
|
+
- lib/fontist/config_cli.rb
|
309
325
|
- lib/fontist/errors.rb
|
326
|
+
- lib/fontist/exclude.yml
|
310
327
|
- lib/fontist/font.rb
|
311
328
|
- lib/fontist/font_file.rb
|
312
329
|
- lib/fontist/font_installer.rb
|
@@ -365,6 +382,7 @@ files:
|
|
365
382
|
- lib/fontist/utils.rb
|
366
383
|
- lib/fontist/utils/cache.rb
|
367
384
|
- lib/fontist/utils/downloader.rb
|
385
|
+
- lib/fontist/utils/file_magic.rb
|
368
386
|
- lib/fontist/utils/locking.rb
|
369
387
|
- lib/fontist/utils/system.rb
|
370
388
|
- lib/fontist/utils/ui.rb
|