fontist 1.5.0 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,6 +47,10 @@ module Fontist
47
47
  instance.temp_resource.merge!(filename: name)
48
48
  end
49
49
 
50
+ def source_filename(name)
51
+ instance.temp_resource.merge!(source_filename: name)
52
+ end
53
+
50
54
  def provides_font(font, options = {})
51
55
  font_styles = instance.extract_font_styles(options)
52
56
  instance.font_list.push(name: font, styles: font_styles)
@@ -0,0 +1,36 @@
1
+ module Fontist
2
+ module Utils
3
+ module Dsl
4
+ class CollectionFont
5
+ REQUIRED_ATTRIBUTES = %i[style].freeze
6
+
7
+ attr_reader :attributes
8
+
9
+ def initialize(attributes)
10
+ REQUIRED_ATTRIBUTES.each do |required_attribute|
11
+ unless attributes[required_attribute]
12
+ raise(Fontist::Errors::MissingAttributeError.new(
13
+ "Missing attribute: #{required_attribute}"
14
+ ))
15
+ end
16
+ end
17
+
18
+ self.attributes = attributes
19
+ end
20
+
21
+ def attributes=(attrs)
22
+ @attributes = { family_name: attrs[:family_name],
23
+ type: attrs[:style],
24
+ collection: attrs[:full_name],
25
+ full_name: attrs[:full_name],
26
+ post_script_name: attrs[:post_script_name],
27
+ version: attrs[:version],
28
+ description: attrs[:description],
29
+ copyright: attrs[:copyright],
30
+ font: attrs[:filename],
31
+ source_font: attrs[:source_filename] }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -29,7 +29,8 @@ module Fontist
29
29
  version: attrs[:version],
30
30
  description: attrs[:description],
31
31
  copyright: attrs[:copyright],
32
- font: attrs[:filename] }
32
+ font: attrs[:filename],
33
+ source_font: attrs[:source_filename] }
33
34
  end
34
35
  end
35
36
  end
@@ -5,17 +5,19 @@ module Fontist
5
5
  download = @downloaded === true ? false : download
6
6
 
7
7
  exe_file = download_file(exe_file).path if download
8
+
9
+ Fontist.ui.say(%(Installing font "#{key}".))
8
10
  cab_file = decompressor.search(exe_file)
9
- cabbed_fonts = grep_fonts(cab_file.files, font_ext) || []
11
+ cabbed_fonts = grep_fonts(cab_file.files) || []
10
12
  fonts_paths = extract_cabbed_fonts_to_assets(cabbed_fonts)
11
13
 
12
14
  block_given? ? yield(fonts_paths) : fonts_paths
13
15
  end
14
16
 
15
- def exe_extract(source)
17
+ def exe_extract(source, subarchive: nil)
16
18
  cab_file = decompressor.search(download_file(source).path)
17
- fonts_paths = build_cab_file_hash(cab_file.files)
18
- block_given? ? yield(fonts_paths) : fonts_paths
19
+ subarchive_path = extract_subarchive(cab_file.files, subarchive)
20
+ block_given? ? yield(subarchive_path) : subarchive_path
19
21
  end
20
22
 
21
23
  private
@@ -27,10 +29,10 @@ module Fontist
27
29
  )
28
30
  end
29
31
 
30
- def grep_fonts(file, font_ext)
32
+ def grep_fonts(file)
31
33
  Array.new.tap do |fonts|
32
34
  while file
33
- fonts.push(file) if file.filename.match(font_ext)
35
+ fonts.push(file) if font_file?(file.filename)
34
36
  file = file.next
35
37
  end
36
38
  end
@@ -39,7 +41,8 @@ module Fontist
39
41
  def extract_cabbed_fonts_to_assets(cabbed_fonts)
40
42
  Array.new.tap do |fonts|
41
43
  cabbed_fonts.each do |font|
42
- font_path = fonts_path.join(font.filename).to_s
44
+ target_filename = target_filename(font.filename)
45
+ font_path = fonts_path.join(target_filename).to_s
43
46
  decompressor.extract(font, font_path)
44
47
 
45
48
  fonts.push(font_path)
@@ -47,10 +50,11 @@ module Fontist
47
50
  end
48
51
  end
49
52
 
50
- def build_cab_file_hash(file)
53
+ def extract_subarchive(file, subarchive = nil)
51
54
  while file
52
55
  filename = file.filename
53
- if filename.include?("cab") || filename.include?("msi")
56
+
57
+ if subarchive_found?(filename, subarchive)
54
58
  file_path = File.join(Dir.mktmpdir, filename)
55
59
  decompressor.extract(file, file_path)
56
60
 
@@ -60,6 +64,12 @@ module Fontist
60
64
  file = file.next
61
65
  end
62
66
  end
67
+
68
+ def subarchive_found?(filename, subarchive)
69
+ return subarchive == filename if subarchive
70
+
71
+ filename.include?("cab") || filename.include?("msi")
72
+ end
63
73
  end
64
74
  end
65
75
  end
@@ -18,6 +18,10 @@ module Fontist
18
18
  def self.ask(message, options = {})
19
19
  new.ask(message, options)
20
20
  end
21
+
22
+ def self.print(message)
23
+ super
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -4,40 +4,49 @@ require "pathname"
4
4
  module Fontist
5
5
  module Utils
6
6
  module ZipExtractor
7
- # fonts_sub_dir is unused now, but formulas have this option
8
- # rubocop:disable Lint/UnusedMethodArgument
9
- def zip_extract(resource, download: true, fonts_sub_dir: "")
7
+ def zip_extract(resource, download: true, fonts_sub_dir: nil)
10
8
  zip_file = download_file(resource) if download
11
9
  zip_file ||= resource.urls.first
12
10
 
13
- fonts_paths = unzip_fonts(zip_file)
11
+ Fontist.ui.say(%(Installing font "#{key}".))
12
+ fonts_paths = unzip_fonts(zip_file, fonts_sub_dir)
14
13
  block_given? ? yield(fonts_paths) : fonts_paths
15
14
  end
16
- # rubocop:enable Lint/UnusedMethodArgument
17
15
 
18
16
  alias_method :unzip, :zip_extract
19
17
 
20
18
  private
21
19
 
22
20
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
23
- def unzip_fonts(file)
21
+ def unzip_fonts(file, subdir)
24
22
  Zip.on_exists_proc = true
25
23
 
26
24
  Array.new.tap do |fonts|
27
25
  Zip::File.open(file) do |zip_file|
28
- zip_file.glob("**/*.{ttf,ttc,otf}").each do |entry|
26
+ zip_file.each do |entry|
29
27
  if entry.name
30
- filename = Pathname.new(entry.name).basename
31
- font_path = fonts_path.join(filename.to_s)
32
- fonts.push(font_path.to_s)
28
+ filename = Pathname.new(entry.name).basename.to_s
29
+ if font_directory?(entry.name, subdir) && font_file?(filename)
30
+ target_filename = target_filename(filename)
31
+ font_path = fonts_path.join(target_filename)
32
+ fonts.push(font_path.to_s)
33
33
 
34
- entry.extract(font_path)
34
+ entry.extract(font_path)
35
+ end
35
36
  end
36
37
  end
37
38
  end
38
39
  end
39
40
  end
40
41
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
42
+
43
+ def font_directory?(path, subdir)
44
+ return true unless subdir
45
+
46
+ dirname = File.dirname(path)
47
+ normalized_pattern = subdir.chomp("/")
48
+ File.fnmatch?(normalized_pattern, dirname)
49
+ end
41
50
  end
42
51
  end
43
52
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.5.0".freeze
2
+ VERSION = "1.7.2".freeze
3
3
  end
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.5.0
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-11-10 00:00:00.000000000 Z
12
+ date: 2020-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '1.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: ttfunk
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.0'
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: extract_ttc
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -284,6 +298,8 @@ files:
284
298
  - lib/fontist/import/extractors/seven_zip_extractor.rb
285
299
  - lib/fontist/import/extractors/zip_extractor.rb
286
300
  - lib/fontist/import/files/collection_file.rb
301
+ - lib/fontist/import/files/file_requirement.rb
302
+ - lib/fontist/import/files/font_detector.rb
287
303
  - lib/fontist/import/formula_builder.rb
288
304
  - lib/fontist/import/formula_serializer.rb
289
305
  - lib/fontist/import/google.rb
@@ -306,16 +322,17 @@ files:
306
322
  - lib/fontist/import/template_helper.rb
307
323
  - lib/fontist/import/text_helper.rb
308
324
  - lib/fontist/manifest.rb
309
- - lib/fontist/manifest/common.rb
310
325
  - lib/fontist/manifest/install.rb
311
326
  - lib/fontist/manifest/locations.rb
312
327
  - lib/fontist/registry.rb
313
328
  - lib/fontist/system.yml
314
329
  - lib/fontist/system_font.rb
330
+ - lib/fontist/system_index.rb
315
331
  - lib/fontist/utils.rb
316
332
  - lib/fontist/utils/cache.rb
317
333
  - lib/fontist/utils/downloader.rb
318
334
  - lib/fontist/utils/dsl.rb
335
+ - lib/fontist/utils/dsl/collection_font.rb
319
336
  - lib/fontist/utils/dsl/font.rb
320
337
  - lib/fontist/utils/exe_extractor.rb
321
338
  - lib/fontist/utils/msi_extractor.rb
@@ -1,60 +0,0 @@
1
- module Fontist
2
- module Manifest
3
- class Common
4
- def initialize(manifest)
5
- @manifest = manifest
6
- end
7
-
8
- def self.call(manifest)
9
- new(manifest).call
10
- end
11
-
12
- def call
13
- font_names.zip(font_paths).to_h
14
- end
15
-
16
- private
17
-
18
- def font_names
19
- fonts.keys
20
- end
21
-
22
- def fonts
23
- @fonts ||= begin
24
- unless File.exist?(@manifest)
25
- raise Fontist::Errors::ManifestCouldNotBeFoundError
26
- end
27
-
28
- fonts = YAML.load_file(@manifest)
29
- unless fonts.is_a?(Hash)
30
- raise Fontist::Errors::ManifestCouldNotBeReadError
31
- end
32
-
33
- fonts
34
- end
35
- end
36
-
37
- def font_paths
38
- fonts.map do |font, styles|
39
- styles_to_ary = [styles].flatten
40
- style_paths_map(font, styles_to_ary)
41
- end
42
- end
43
-
44
- def style_paths_map(font, names)
45
- paths = style_paths(font, names)
46
- names.zip(paths).to_h
47
- end
48
-
49
- def style_paths(font, names)
50
- names.map do |style|
51
- file_paths(font, style)
52
- end
53
- end
54
-
55
- def file_paths(_font, _style)
56
- raise NotImplementedError.new("Implement #file_paths in child class")
57
- end
58
- end
59
- end
60
- end