fontist 1.2.1 → 1.6.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/check_google.yml +28 -0
- data/.github/workflows/macosx.yml +3 -0
- data/.github/workflows/ubuntu.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/.gitignore +6 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +22 -0
- data/README.md +224 -0
- data/bin/check_google +8 -0
- data/bin/convert_formulas +8 -0
- data/bin/fontist +7 -0
- data/bin/generate_otfinfo +8 -0
- data/bin/import_google +8 -0
- data/fontist.gemspec +16 -1
- data/lib/fontist.rb +23 -13
- data/lib/fontist/cli.rb +162 -0
- data/lib/fontist/errors.rb +5 -0
- data/lib/fontist/font.rb +181 -8
- data/lib/fontist/font_formula.rb +12 -5
- data/lib/fontist/fontist_font.rb +70 -0
- data/lib/fontist/formula.rb +27 -9
- data/lib/fontist/formula_template.rb +108 -0
- data/lib/fontist/formulas.rb +41 -0
- data/lib/fontist/import.rb +9 -0
- data/lib/fontist/import/convert_formulas.rb +65 -0
- data/lib/fontist/import/create_formula.rb +74 -0
- data/lib/fontist/import/extractors.rb +5 -0
- data/lib/fontist/import/extractors/cab_extractor.rb +37 -0
- data/lib/fontist/import/extractors/extractor.rb +19 -0
- data/lib/fontist/import/extractors/ole_extractor.rb +41 -0
- data/lib/fontist/import/extractors/seven_zip_extractor.rb +44 -0
- data/lib/fontist/import/extractors/zip_extractor.rb +31 -0
- data/lib/fontist/import/files/collection_file.rb +47 -0
- data/lib/fontist/import/formula_builder.rb +162 -0
- data/lib/fontist/import/formula_serializer.rb +133 -0
- data/lib/fontist/import/google.rb +16 -0
- data/lib/fontist/import/google/fonts_public.md +10 -0
- data/lib/fontist/import/google/fonts_public.pb.rb +71 -0
- data/lib/fontist/import/google/fonts_public.proto +46 -0
- data/lib/fontist/import/google/new_fonts_fetcher.rb +121 -0
- data/lib/fontist/import/google/skiplist.yml +8 -0
- data/lib/fontist/import/google_check.rb +34 -0
- data/lib/fontist/import/google_import.rb +180 -0
- data/lib/fontist/import/helpers/hash_helper.rb +13 -0
- data/lib/fontist/import/helpers/system_helper.rb +23 -0
- data/lib/fontist/import/otf/font_file.rb +91 -0
- data/lib/fontist/import/otf_parser.rb +25 -0
- data/lib/fontist/import/otf_style.rb +29 -0
- data/lib/fontist/import/otfinfo/otfinfo_requirement.rb +22 -0
- data/lib/fontist/import/otfinfo/template.erb +20 -0
- data/lib/fontist/import/otfinfo_generate.rb +45 -0
- data/lib/fontist/import/recursive_extraction.rb +128 -0
- data/lib/fontist/import/template_helper.rb +19 -0
- data/lib/fontist/import/text_helper.rb +30 -0
- data/lib/fontist/manifest.rb +2 -0
- data/lib/fontist/manifest/common.rb +60 -0
- data/lib/fontist/manifest/install.rb +36 -0
- data/lib/fontist/manifest/locations.rb +13 -0
- data/lib/fontist/registry.rb +1 -0
- data/lib/fontist/system_font.rb +53 -22
- data/lib/fontist/utils.rb +5 -0
- data/lib/fontist/utils/cache.rb +88 -0
- data/lib/fontist/utils/downloader.rb +69 -8
- data/lib/fontist/utils/dsl.rb +4 -0
- data/lib/fontist/utils/dsl/font.rb +37 -0
- data/lib/fontist/utils/exe_extractor.rb +20 -18
- data/lib/fontist/utils/msi_extractor.rb +31 -0
- data/lib/fontist/utils/seven_zip_extractor.rb +41 -0
- data/lib/fontist/utils/system.rb +23 -0
- data/lib/fontist/utils/ui.rb +27 -0
- data/lib/fontist/utils/zip_extractor.rb +10 -4
- data/lib/fontist/version.rb +1 -1
- metadata +185 -48
- data/lib/fontist/formulas/andale_font.rb +0 -80
- data/lib/fontist/formulas/arial_black_font.rb +0 -79
- data/lib/fontist/formulas/cleartype_fonts.rb +0 -227
- data/lib/fontist/formulas/comic_font.rb +0 -78
- data/lib/fontist/formulas/courier_font.rb +0 -81
- data/lib/fontist/formulas/euphemia_font.rb +0 -85
- data/lib/fontist/formulas/georgia_font.rb +0 -80
- data/lib/fontist/formulas/impact_font.rb +0 -78
- data/lib/fontist/formulas/montserrat_font.rb +0 -132
- data/lib/fontist/formulas/ms_truetype_fonts.rb +0 -125
- data/lib/fontist/formulas/open_sans_fonts.rb +0 -263
- data/lib/fontist/formulas/overpass_font.rb +0 -73
- data/lib/fontist/formulas/source_fonts.rb +0 -109
- data/lib/fontist/formulas/stix_fonts.rb +0 -108
- data/lib/fontist/formulas/tahoma_font.rb +0 -147
- data/lib/fontist/formulas/webding_font.rb +0 -78
- data/spec/fontist/font_formula_spec.rb +0 -67
- data/spec/fontist/font_spec.rb +0 -87
- data/spec/fontist/formula_spec.rb +0 -67
- data/spec/fontist/formulas/andale_font_spec.rb +0 -29
- data/spec/fontist/formulas/arial_black_font_spec.rb +0 -29
- data/spec/fontist/formulas/cleartype_fonts_spec.rb +0 -38
- data/spec/fontist/formulas/comic_font_spec.rb +0 -29
- data/spec/fontist/formulas/courier_font_spec.rb +0 -29
- data/spec/fontist/formulas/euphemia_font_spec.rb +0 -29
- data/spec/fontist/formulas/georgia_font_spec.rb +0 -29
- data/spec/fontist/formulas/impact_font_spec.rb +0 -29
- data/spec/fontist/formulas/montserrat_font_spec.rb +0 -29
- data/spec/fontist/formulas/ms_truetype_fonts_spec.rb +0 -29
- data/spec/fontist/formulas/open_sans_fonts_spec.rb +0 -29
- data/spec/fontist/formulas/overpass_font_spec.rb +0 -29
- data/spec/fontist/formulas/source_fonts_spec.rb +0 -31
- data/spec/fontist/formulas/stix_fonts_spec.rb +0 -29
- data/spec/fontist/formulas/tahoma_font_spec.rb +0 -29
- data/spec/fontist/formulas/webding_font_spec.rb +0 -29
- data/spec/fontist/registry_spec.rb +0 -47
- data/spec/fontist/system_font_spec.rb +0 -44
- data/spec/fontist/utils/downloader_spec.rb +0 -35
- data/spec/fontist_spec.rb +0 -5
- data/spec/spec_helper.rb +0 -22
- data/spec/support/fontist_helper.rb +0 -10
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Import
|
3
|
+
module Helpers
|
4
|
+
module SystemHelper
|
5
|
+
class << self
|
6
|
+
def run(command)
|
7
|
+
unless ENV.fetch("TEST_ENV", "") === "CI"
|
8
|
+
Fontist.ui.say("Run `#{command}`")
|
9
|
+
end
|
10
|
+
|
11
|
+
result = `#{command}`
|
12
|
+
unless $CHILD_STATUS.to_i.zero?
|
13
|
+
raise Errors::BinaryCallError,
|
14
|
+
"Failed to run #{command}, status: #{$CHILD_STATUS}"
|
15
|
+
end
|
16
|
+
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative "../otfinfo/otfinfo_requirement"
|
2
|
+
require_relative "../text_helper"
|
3
|
+
|
4
|
+
module Fontist
|
5
|
+
module Import
|
6
|
+
module Otf
|
7
|
+
class FontFile
|
8
|
+
REQUIREMENTS = {
|
9
|
+
otfinfo: Otfinfo::OtfinfoRequirement.new,
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
STYLE_ATTRIBUTES = %i[family_name type full_name post_script_name
|
13
|
+
version description copyright font].freeze
|
14
|
+
COLLECTION_ATTRIBUTES = STYLE_ATTRIBUTES.reject { |a| a == :font }
|
15
|
+
|
16
|
+
attr_reader :path
|
17
|
+
|
18
|
+
def initialize(path)
|
19
|
+
@path = path
|
20
|
+
@info = read
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_style
|
24
|
+
STYLE_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_collection_style
|
28
|
+
COLLECTION_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
|
29
|
+
end
|
30
|
+
|
31
|
+
def family_name
|
32
|
+
info["Preferred family"] || info["Family"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def type
|
36
|
+
info["Preferred subfamily"] || info["Subfamily"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def full_name
|
40
|
+
info["Full name"]
|
41
|
+
end
|
42
|
+
|
43
|
+
def post_script_name
|
44
|
+
info["PostScript name"]
|
45
|
+
end
|
46
|
+
|
47
|
+
def version
|
48
|
+
return unless info["Version"]
|
49
|
+
|
50
|
+
info["Version"].gsub("Version ", "")
|
51
|
+
end
|
52
|
+
|
53
|
+
def description
|
54
|
+
info["Description"]
|
55
|
+
end
|
56
|
+
|
57
|
+
def font
|
58
|
+
File.basename(@path)
|
59
|
+
end
|
60
|
+
|
61
|
+
def copyright
|
62
|
+
info["Copyright"]
|
63
|
+
end
|
64
|
+
|
65
|
+
def homepage
|
66
|
+
info["Vendor URL"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def license_url
|
70
|
+
info["License URL"]
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
attr_reader :info
|
76
|
+
|
77
|
+
def read
|
78
|
+
text = REQUIREMENTS[:otfinfo].call(@path)
|
79
|
+
|
80
|
+
text
|
81
|
+
.encode("UTF-8", invalid: :replace, replace: "")
|
82
|
+
.split("\n")
|
83
|
+
.select { |x| x.include?(":") }
|
84
|
+
.map { |x| x.split(":", 2) }
|
85
|
+
.map { |x| x.map { |y| Fontist::Import::TextHelper.cleanup(y) } }
|
86
|
+
.to_h
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "otfinfo/otfinfo_requirement"
|
2
|
+
require_relative "text_helper"
|
3
|
+
|
4
|
+
module Fontist
|
5
|
+
module Import
|
6
|
+
class OtfParser
|
7
|
+
REQUIREMENTS = {
|
8
|
+
otfinfo: Fontist::Import::Otfinfo::OtfinfoRequirement.new,
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@path = path
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
text = REQUIREMENTS[:otfinfo].call(@path)
|
17
|
+
text.split("\n")
|
18
|
+
.select { |x| x.include?(":") }
|
19
|
+
.map { |x| x.split(":", 2) }
|
20
|
+
.map { |x| x.map { |y| Fontist::Import::TextHelper.cleanup(y) } }
|
21
|
+
.to_h
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Import
|
3
|
+
class OtfStyle
|
4
|
+
def initialize(info, path)
|
5
|
+
@info = info
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
style = { family_name: @info["Preferred family"] || @info["Family"],
|
11
|
+
style: @info["Preferred subfamily"] || @info["Subfamily"],
|
12
|
+
full_name: @info["Full name"],
|
13
|
+
post_script_name: @info["PostScript name"],
|
14
|
+
version: version(@info["Version"]),
|
15
|
+
description: @info["Description"],
|
16
|
+
filename: File.basename(@path),
|
17
|
+
copyright: @info["Copyright"] }
|
18
|
+
|
19
|
+
OpenStruct.new(style)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def version(text)
|
25
|
+
Fontist::Import::Google.style_version(text)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "fontist/import/helpers/system_helper"
|
2
|
+
|
3
|
+
module Fontist
|
4
|
+
module Import
|
5
|
+
module Otfinfo
|
6
|
+
class OtfinfoRequirement
|
7
|
+
def initialize
|
8
|
+
otfinfo_path = `which otfinfo`
|
9
|
+
if otfinfo_path.empty?
|
10
|
+
abort "otfinfo is not available. (Or is PATH not setup properly?)"\
|
11
|
+
" You must install otfinfo."\
|
12
|
+
" On macOS it can be installed via `brew install lcdf-typetools`."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(path)
|
17
|
+
Helpers::SystemHelper.run("otfinfo --info '#{path}'")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%- resource.each do |s| -%>
|
2
|
+
{
|
3
|
+
family_name: "<%= s.family_name %>",
|
4
|
+
style: "<%= s.style %>",
|
5
|
+
full_name: "<%= s.full_name %>",
|
6
|
+
<%- if s.post_script_name -%>
|
7
|
+
post_script_name: "<%= s.post_script_name %>",
|
8
|
+
<%- end -%>
|
9
|
+
<%- if s.version -%>
|
10
|
+
version: "<%= esc(s.version) %>",
|
11
|
+
<%- end -%>
|
12
|
+
<%- if s.description -%>
|
13
|
+
description: "<%= esc(s.description) %>",
|
14
|
+
<%- end -%>
|
15
|
+
filename: "<%= s.filename %>",
|
16
|
+
<%- if s.copyright -%>
|
17
|
+
copyright: "<%= esc(s.copyright) %>",
|
18
|
+
<%- end -%>
|
19
|
+
},
|
20
|
+
<%- end -%>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "erb"
|
2
|
+
require_relative "template_helper"
|
3
|
+
require_relative "text_helper"
|
4
|
+
require_relative "otf_parser"
|
5
|
+
require_relative "otf_style"
|
6
|
+
|
7
|
+
module Fontist
|
8
|
+
module Import
|
9
|
+
class OtfinfoGenerate
|
10
|
+
TEMPLATE_PATH = File.expand_path("otfinfo/template.erb", __dir__)
|
11
|
+
|
12
|
+
def initialize(font)
|
13
|
+
@font = font
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
paths = font_paths(@font)
|
18
|
+
puts paths
|
19
|
+
styles = generate_styles(paths)
|
20
|
+
puts render(styles)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def font_paths(font)
|
26
|
+
formula = Fontist::Formula.find(font)
|
27
|
+
font_formula = Object.const_get(formula.installer)
|
28
|
+
font_formula.fetch_font(nil, confirmation: "yes")
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_styles(paths)
|
32
|
+
paths.map do |path|
|
33
|
+
info = OtfParser.new(path).call
|
34
|
+
OtfStyle.new(info, path).call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def render(styles)
|
39
|
+
template = File.read(TEMPLATE_PATH)
|
40
|
+
renderer = ERB.new(template, trim_mode: "-")
|
41
|
+
renderer.result(Fontist::Import::TemplateHelper.bind(styles))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require "find"
|
2
|
+
require_relative "extractors"
|
3
|
+
|
4
|
+
module Fontist
|
5
|
+
module Import
|
6
|
+
class RecursiveExtraction
|
7
|
+
BOTH_FONTS_PATTERN = "**/*.{ttf,otf,ttc}*".freeze
|
8
|
+
ARCHIVE_EXTENSIONS = %w[zip msi exe cab].freeze
|
9
|
+
|
10
|
+
def initialize(archive, subarchive: nil)
|
11
|
+
@archive = archive
|
12
|
+
@subarchive = subarchive
|
13
|
+
@operations = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def extension
|
17
|
+
File.extname(filename(@archive)).sub(/^\./, "")
|
18
|
+
end
|
19
|
+
|
20
|
+
def extract(pattern)
|
21
|
+
Array.new.tap do |results|
|
22
|
+
Find.find(extracted_path) do |path| # rubocop:disable Style/CollectionMethods, Metrics/LineLength
|
23
|
+
results << yield(path) if path.match(pattern)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def operations
|
29
|
+
ensure_extracted
|
30
|
+
@operations.size == 1 ? @operations.first : @operations
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def filename(file)
|
36
|
+
if file.respond_to?(:original_filename)
|
37
|
+
file.original_filename
|
38
|
+
else
|
39
|
+
File.basename(file)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def ensure_extracted
|
44
|
+
extracted_path
|
45
|
+
end
|
46
|
+
|
47
|
+
def extracted_path
|
48
|
+
@extracted_path ||= extract_recursively(@archive)
|
49
|
+
end
|
50
|
+
|
51
|
+
def extract_recursively(archive)
|
52
|
+
path = operate_on_archive(archive)
|
53
|
+
return path if fonts_exist?(path)
|
54
|
+
|
55
|
+
next_archive = find_archive(path)
|
56
|
+
extract_recursively(next_archive)
|
57
|
+
end
|
58
|
+
|
59
|
+
def operate_on_archive(archive)
|
60
|
+
extractor = choose_extractor(archive)
|
61
|
+
Fontist.ui.say("Extracting #{archive} with #{extractor.class.name}")
|
62
|
+
|
63
|
+
save_operation(extractor)
|
64
|
+
extractor.extract
|
65
|
+
end
|
66
|
+
|
67
|
+
# rubocop:disable Metrics/MethodLength
|
68
|
+
def choose_extractor(archive)
|
69
|
+
case filename(archive)
|
70
|
+
when /\.msi$/i
|
71
|
+
Extractors::OleExtractor.new(archive)
|
72
|
+
when /\.cab$/i
|
73
|
+
Extractors::CabExtractor.new(archive)
|
74
|
+
when /\.exe$/i
|
75
|
+
extractor = Extractors::SevenZipExtractor.new(archive)
|
76
|
+
extractor.try ? extractor : Extractors::CabExtractor.new(archive)
|
77
|
+
else
|
78
|
+
Extractors::ZipExtractor.new(archive)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
# rubocop:enable Metrics/MethodLength
|
82
|
+
|
83
|
+
def save_operation(extractor)
|
84
|
+
@operations << { format: extractor.format }
|
85
|
+
end
|
86
|
+
|
87
|
+
def fonts_exist?(path)
|
88
|
+
fonts = Dir.glob(File.join(path, BOTH_FONTS_PATTERN))
|
89
|
+
!fonts.empty?
|
90
|
+
end
|
91
|
+
|
92
|
+
def find_archive(path)
|
93
|
+
paths = Dir.children(path).map { |file| File.join(path, file) }
|
94
|
+
by_subarchive(paths) || by_size(paths)
|
95
|
+
end
|
96
|
+
|
97
|
+
def by_subarchive(paths)
|
98
|
+
return unless @subarchive
|
99
|
+
|
100
|
+
path_found = paths.detect do |path|
|
101
|
+
@subarchive == File.basename(path)
|
102
|
+
end
|
103
|
+
|
104
|
+
return unless path_found
|
105
|
+
|
106
|
+
save_operation_subarchive(path_found)
|
107
|
+
|
108
|
+
path_found
|
109
|
+
end
|
110
|
+
|
111
|
+
def save_operation_subarchive(path)
|
112
|
+
@operations.last[:options] ||= {}
|
113
|
+
@operations.last[:options][:subarchive] = File.basename(path)
|
114
|
+
end
|
115
|
+
|
116
|
+
def by_size(paths)
|
117
|
+
paths.max_by do |path|
|
118
|
+
[file_type(path), File.size(path)]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def file_type(file_path)
|
123
|
+
extension = File.extname(file_path).delete(".")
|
124
|
+
ARCHIVE_EXTENSIONS.include?(extension) ? 1 : 0
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Import
|
3
|
+
module TemplateHelper
|
4
|
+
class << self
|
5
|
+
def bind(resource, name = nil)
|
6
|
+
b = binding
|
7
|
+
b.local_variable_set(name, resource) if name
|
8
|
+
b
|
9
|
+
end
|
10
|
+
|
11
|
+
def escape_double_quotes(text)
|
12
|
+
text.gsub('"', '\"')
|
13
|
+
end
|
14
|
+
|
15
|
+
alias esc escape_double_quotes
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Import
|
3
|
+
module TextHelper
|
4
|
+
class << self
|
5
|
+
def cleanup(text)
|
6
|
+
return unless text
|
7
|
+
|
8
|
+
text.gsub("\r\n", "\n")
|
9
|
+
.gsub("\r", "\n")
|
10
|
+
.strip
|
11
|
+
.lines
|
12
|
+
.map(&:rstrip)
|
13
|
+
.drop_while(&:empty?)
|
14
|
+
.join("\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
def longest_common_prefix(strs)
|
18
|
+
return if strs.empty?
|
19
|
+
|
20
|
+
min, max = strs.minmax
|
21
|
+
idx = min.size.times { |i| break i if min[i] != max[i] }
|
22
|
+
prefix = min[0...idx].strip
|
23
|
+
return if prefix.empty?
|
24
|
+
|
25
|
+
prefix
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|