fontist 1.8.8 → 1.8.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cd7962408633c39bb2cfff2ef8c3c0500842033f80ed7211474eefe98845327
4
- data.tar.gz: 4630d28fbe5afad9865aeaebfa46e50215eb99cc8e2580466ae1fcb616117cfa
3
+ metadata.gz: a094865cc9cb315ad328f795c59934f06663e8c43ff2931a0644da7aef7d8c7d
4
+ data.tar.gz: 170ee4d526e74992ee56593fb5fb715c400fe07c2ade9307faebcdcd8e32e47c
5
5
  SHA512:
6
- metadata.gz: 57ac2451e5911694725ddd4f7f29bb8693e0be8e4397101f1f90c6a83ba353ea51fc7e2c9c0875e1bc0f4f17a466b9191d2c4017a47e971c9bb620bef0ea4a4c
7
- data.tar.gz: 6aee6a31dd412af421191cb8cb5ca7793d5071bfcb0101666ef7d591abffcb98a7e9a3990978e7268d4e55fb1f0fa339711bffe801f272e08c133cd3c6783a9b
6
+ metadata.gz: 52ec33b7a2000ec5af4ae65165c0b0cdd22f1b0389b6c3ec89ed3a135ca3e55ac810a71cf9ce4621ae2398dcb77ed1dd2c8a45b077a2bfb8a1afc4a5d4d5efab
7
+ data.tar.gz: 30635f72fb0d39f2ecb0657b36ee89f6a48647e8f23ec896f8837323e76eb7964d3feeda3cf899f6d698e06681e815000e132c6c4a556695f340d59a351db214
@@ -0,0 +1,35 @@
1
+ name: metanorma
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
11
+ runs-on: ${{ matrix.os }}
12
+ continue-on-error: ${{ matrix.experimental }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
17
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
18
+ experimental: [ true ]
19
+ steps:
20
+ - uses: actions/checkout@master
21
+ with:
22
+ repository: metanorma/metanorma
23
+
24
+ - uses: actions/checkout@master
25
+ with:
26
+ path: "fontist"
27
+
28
+ - run: 'echo ''gem "fontist", path: "./fontist"'' > Gemfile.devel'
29
+
30
+ - uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby }}
33
+ bundler-cache: true
34
+
35
+ - run: bundle exec rake
@@ -13,19 +13,9 @@ jobs:
13
13
  strategy:
14
14
  fail-fast: false
15
15
  matrix:
16
- ruby: [ '2.4', '2.5', '2.6', '2.7' ]
16
+ ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
17
17
  os: [ ubuntu-latest, windows-latest, macos-latest ]
18
18
  experimental: [ false ]
19
- include:
20
- - ruby: '3.0'
21
- os: 'ubuntu-latest'
22
- experimental: true
23
- - ruby: '3.0'
24
- os: 'windows-latest'
25
- experimental: true
26
- - ruby: '3.0'
27
- os: 'macos-latest'
28
- experimental: true
29
19
 
30
20
  steps:
31
21
  - uses: actions/checkout@master
@@ -33,20 +23,11 @@ jobs:
33
23
  - uses: ruby/setup-ruby@v1
34
24
  with:
35
25
  ruby-version: ${{ matrix.ruby }}
36
-
37
- - uses: actions/cache@v1
38
- with:
39
- path: vendor/bundle
40
- key: bundle-v2-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
41
- restore-keys: bundle-v2-${{ matrix.os }}-${{ matrix.ruby }}
26
+ bundler-cache: true
42
27
 
43
28
  - if: matrix.os == 'macos-latest'
44
29
  run: brew install lcdf-typetools
45
30
 
46
- - run: bundle config set path 'vendor/bundle'
47
-
48
- - run: bundle install --jobs 4 --retry 3
49
-
50
31
  - if: matrix.os == 'macos-latest'
51
32
  run: bundle exec rspec
52
33
  env:
data/.rubocop.yml CHANGED
@@ -9,14 +9,14 @@ AllCops:
9
9
  Rails:
10
10
  Enabled: false
11
11
 
12
- Metrics/LineLength:
12
+ Layout/LineLength:
13
13
  Exclude:
14
14
  - 'lib/fontist/formulas/**/*.rb'
15
15
 
16
- Layout/IndentFirstHashElement:
16
+ Layout/FirstHashElementIndentation:
17
17
  Exclude:
18
18
  - 'lib/fontist/formulas/**/*.rb'
19
19
 
20
- Layout/IndentHeredoc:
20
+ Layout/HeredocIndentation:
21
21
  Exclude:
22
22
  - 'lib/fontist/formulas/**/*.rb'
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Fontist
2
2
 
3
- ![windows](https://github.com/fontist/fontist/workflows/windows/badge.svg)
4
- ![macos](https://github.com/fontist/fontist/workflows/macos/badge.svg)
5
- ![ubuntu](https://github.com/fontist/fontist/workflows/ubuntu/badge.svg)
3
+ [![Build Status](https://github.com/fontist/fontist/actions/workflows/rspec.yml/badge.svg)](https://github.com/fontist/fontist/actions/workflows/rspec.yml)
4
+ [![Gem Version](https://img.shields.io/gem/v/fontist.svg)](https://rubygems.org/gems/fontist)
5
+ [![Pull Requests](https://img.shields.io/github/issues-pr-raw/fontist/fontist.svg)](https://github.com/fontist/fontist/pulls)
6
6
 
7
7
  A simple library to find and download fonts for Windows, Linux and Mac.
8
8
 
@@ -34,6 +34,18 @@ After installation please fetch formulas to your system:
34
34
  fontist update
35
35
  ```
36
36
 
37
+ ### Dependencies
38
+
39
+ Depends on
40
+ [ffi-libarchive-binary](https://github.com/fontist/ffi-libarchive-binary) which
41
+ has the following requirements:
42
+
43
+ * zlib
44
+ * Expat
45
+ * OpenSSL (for Linux only)
46
+
47
+ These dependencies are generally present on all systems.
48
+
37
49
  ## Usage
38
50
 
39
51
  ### Font
data/fontist.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency "down", "~> 5.0"
31
31
  spec.add_runtime_dependency "thor", "~> 1.0.1"
32
32
  spec.add_runtime_dependency "git", "~> 1.0"
33
- spec.add_runtime_dependency "ttfunk", "~> 1.0"
33
+ spec.add_runtime_dependency "ttfunk", "~> 1.6"
34
34
  spec.add_runtime_dependency "excavate", "~> 0.1"
35
35
 
36
36
  spec.add_development_dependency "extract_ttc", "~> 0.1"
data/lib/fontist/cli.rb CHANGED
@@ -31,12 +31,14 @@ module Fontist
31
31
  desc: "Install even if it's already installed in system"
32
32
  option :accept_all_licenses, type: :boolean, aliases: "--confirm-license", desc: "Accept all license agreements"
33
33
  option :hide_licenses, type: :boolean, desc: "Hide license texts"
34
+ option :no_progress, type: :boolean, desc: "Hide download progress"
34
35
  def install(font)
35
36
  Fontist::Font.install(
36
37
  font,
37
38
  force: options[:force],
38
39
  confirmation: options[:accept_all_licenses] ? "yes" : "no",
39
- hide_licenses: options[:hide_licenses]
40
+ hide_licenses: options[:hide_licenses],
41
+ no_progress: options[:no_progress]
40
42
  )
41
43
  success
42
44
  rescue Fontist::Errors::GeneralError => e
data/lib/fontist/font.rb CHANGED
@@ -7,6 +7,7 @@ module Fontist
7
7
  @name = options[:name]
8
8
  @confirmation = options[:confirmation] || "no"
9
9
  @hide_licenses = options[:hide_licenses]
10
+ @no_progress = options[:no_progress] || false
10
11
  @force = options[:force] || false
11
12
 
12
13
  check_or_create_fontist_path!
@@ -94,7 +95,7 @@ module Fontist
94
95
  end
95
96
 
96
97
  def font_installer(formula)
97
- FontInstaller.new(formula)
98
+ FontInstaller.new(formula, no_progress: @no_progress)
98
99
  end
99
100
 
100
101
  def formula
@@ -3,8 +3,9 @@ require "excavate"
3
3
 
4
4
  module Fontist
5
5
  class FontInstaller
6
- def initialize(formula)
6
+ def initialize(formula, no_progress: false)
7
7
  @formula = formula
8
+ @no_progress = no_progress
8
9
  end
9
10
 
10
11
  def install(confirmation:)
@@ -60,7 +61,7 @@ module Fontist
60
61
  url,
61
62
  sha: source.sha256,
62
63
  file_size: source.file_size,
63
- progress_bar: true
64
+ progress_bar: !@no_progress
64
65
  )
65
66
  end
66
67
 
@@ -14,6 +14,7 @@ module Fontist
14
14
  paths = search_font_paths(s["font"])
15
15
  paths.map do |path|
16
16
  { full_name: s["full_name"],
17
+ type: s["type"],
17
18
  path: path }
18
19
  end
19
20
  end
@@ -4,9 +4,7 @@ module Fontist
4
4
  module SystemHelper
5
5
  class << self
6
6
  def run(command)
7
- unless ENV.fetch("TEST_ENV", "") === "CI"
8
- Fontist.ui.say("Run `#{command}`")
9
- end
7
+ Fontist.ui.say("Run `#{command}`")
10
8
 
11
9
  result = `#{command}`
12
10
  unless $CHILD_STATUS.to_i.zero?
data/lib/fontist/index.rb CHANGED
@@ -7,5 +7,10 @@ module Fontist
7
7
  Fontist::Indexes::FontIndex.rebuild
8
8
  Fontist::Indexes::FilenameIndex.rebuild
9
9
  end
10
+
11
+ def self.reset_cache
12
+ Fontist::Indexes::FontIndex.reset_cache
13
+ Fontist::Indexes::FilenameIndex.reset_cache
14
+ end
10
15
  end
11
16
  end
@@ -18,6 +18,10 @@ module Fontist
18
18
  raise NotImplementedError, "Please define path of an index"
19
19
  end
20
20
 
21
+ def self.reset_cache
22
+ @from_yaml = nil
23
+ end
24
+
21
25
  def self.rebuild
22
26
  index = new
23
27
  index.build
@@ -3,17 +3,18 @@ require_relative "locations"
3
3
  module Fontist
4
4
  module Manifest
5
5
  class Install < Locations
6
- def initialize(manifest, confirmation: "no", hide_licenses: false)
7
- @manifest = manifest
6
+ def initialize(manifest, confirmation: "no", hide_licenses: false, no_progress: false)
7
+ super(manifest)
8
8
  @confirmation = confirmation
9
9
  @hide_licenses = hide_licenses
10
+ @no_progress = no_progress
10
11
  end
11
12
 
12
13
  private
13
14
 
14
15
  def file_paths(font, style)
15
16
  paths = find_font_with_name(font, style)
16
- return paths unless paths["paths"].empty?
17
+ return paths unless paths.nil?
17
18
 
18
19
  install_font(font)
19
20
 
@@ -21,7 +22,13 @@ module Fontist
21
22
  end
22
23
 
23
24
  def install_font(font)
24
- Fontist::Font.install(font, force: true, confirmation: @confirmation, hide_licenses: @hide_licenses)
25
+ Fontist::Font.install(
26
+ font,
27
+ force: true,
28
+ confirmation: @confirmation,
29
+ hide_licenses: @hide_licenses,
30
+ no_progress: @no_progress
31
+ )
25
32
  end
26
33
  end
27
34
  end
@@ -42,26 +42,40 @@ module Fontist
42
42
  end
43
43
 
44
44
  def style_paths_map(font, names)
45
- paths = style_paths(font, names)
46
- names.zip(paths).to_h
45
+ styles = style_paths(font, names)
46
+ group_paths(styles)
47
47
  end
48
48
 
49
49
  def style_paths(font, names)
50
- names.map do |style|
51
- file_paths(font, style)
50
+ names.flat_map do |style|
51
+ file_paths(font, style) || empty_paths(style)
52
52
  end
53
53
  end
54
54
 
55
+ def group_paths(styles)
56
+ styles.group_by { |s| s[:type] }
57
+ .transform_values { |group| style(group) }
58
+ end
59
+
60
+ def style(styles)
61
+ { "full_name" => styles.first[:full_name],
62
+ "paths" => styles.map { |x| x[:path] } }.compact
63
+ end
64
+
55
65
  def file_paths(font, style)
56
66
  find_font_with_name(font, style).tap do |x|
57
- if x["paths"].empty?
67
+ if x.nil?
58
68
  raise Errors::MissingFontError.new(font, style)
59
69
  end
60
70
  end
61
71
  end
62
72
 
63
73
  def find_font_with_name(font, style)
64
- Fontist::SystemFont.find_with_name(font, style).map { |k, v| [k.to_s, v] }.to_h
74
+ Fontist::SystemFont.find_styles(font, style)
75
+ end
76
+
77
+ def empty_paths(style)
78
+ [{ "full_name" => nil, "type" => style, "path" => nil }]
65
79
  end
66
80
  end
67
81
  end
@@ -40,8 +40,8 @@ module Fontist
40
40
  new(font: font, sources: sources).find
41
41
  end
42
42
 
43
- def self.find_with_name(font, style)
44
- new(font: font, style: style).find_with_name
43
+ def self.find_styles(font, style)
44
+ new(font: font, style: style).find_styles
45
45
  end
46
46
 
47
47
  def find
@@ -51,22 +51,14 @@ module Fontist
51
51
  styles.map { |x| x[:path] }
52
52
  end
53
53
 
54
- def find_with_name
55
- styles = find_styles
56
- return { full_name: nil, paths: [] } unless styles
57
-
58
- { full_name: styles.first[:full_name],
59
- paths: styles.map { |x| x[:path] } }
54
+ def find_styles
55
+ find_by_index || find_by_formulas
60
56
  end
61
57
 
62
58
  private
63
59
 
64
60
  attr_reader :font, :style, :user_sources
65
61
 
66
- def find_styles
67
- find_by_index || find_by_formulas
68
- end
69
-
70
62
  def find_by_index
71
63
  SystemIndex.new(all_paths).find(font, style)
72
64
  end
@@ -83,7 +83,7 @@ module Fontist
83
83
  next by_path[path] if by_path[path]
84
84
 
85
85
  detect_fonts(path)
86
- end
86
+ end.compact
87
87
  end
88
88
 
89
89
  def detect_fonts(path)
@@ -100,6 +100,9 @@ module Fontist
100
100
  def detect_file_font(path)
101
101
  file = TTFunk::File.open(path)
102
102
  parse_font(file, path)
103
+ rescue StandardError
104
+ warn $!.message
105
+ warn "Warning: File at #{path} not recognized as a font file."
103
106
  end
104
107
 
105
108
  def detect_collection_fonts(path)
@@ -3,10 +3,10 @@ module Fontist
3
3
  class Cache
4
4
  include Locking
5
5
 
6
- def fetch(key, bar: nil)
6
+ def fetch(key)
7
7
  map = load_cache
8
8
  if cache_exist?(map[key])
9
- print_bar(bar, map[key]) if bar
9
+ print(map[key])
10
10
 
11
11
  return downloaded_file(map[key])
12
12
  end
@@ -17,6 +17,25 @@ module Fontist
17
17
  downloaded_file(path)
18
18
  end
19
19
 
20
+ def delete(key)
21
+ lock(lock_path) do
22
+ map = load_cache
23
+ return unless map[key]
24
+
25
+ value = map.delete(key)
26
+ File.write(cache_map_path, YAML.dump(map))
27
+ value
28
+ end
29
+ end
30
+
31
+ def set(key, value)
32
+ lock(lock_path) do
33
+ map = load_cache
34
+ map[key] = value
35
+ File.write(cache_map_path, YAML.dump(map))
36
+ end
37
+ end
38
+
20
39
  private
21
40
 
22
41
  def cache_map_path
@@ -39,12 +58,12 @@ module Fontist
39
58
  Fontist.downloads_path.join(path)
40
59
  end
41
60
 
42
- def print_bar(bar, path)
43
- File.size(downloaded_path(path)).tap do |size|
44
- bar.total = size
45
- bar.increment(size)
46
- bar.finish("cache")
47
- end
61
+ def print(path)
62
+ Fontist.ui.say("Fetched from cache: #{size(path)} MiB.")
63
+ end
64
+
65
+ def size(path)
66
+ File.size(downloaded_path(path)) / (1024 * 1024)
48
67
  end
49
68
 
50
69
  def save_cache(generated_file, key)
@@ -14,13 +14,13 @@ module Fontist
14
14
  # TODO: If the first mirror fails, try the second one
15
15
  @file = file
16
16
  @sha = [sha].flatten.compact
17
- @file_size = (file_size || default_file_size).to_i
17
+ @file_size = file_size.to_i if file_size
18
18
  @progress_bar = set_progress_bar(progress_bar)
19
19
  @cache = Cache.new
20
20
  end
21
21
 
22
22
  def download
23
- file = @cache.fetch(@file, bar: @progress_bar) do
23
+ file = @cache.fetch(@file) do
24
24
  download_file
25
25
  end
26
26
 
@@ -38,10 +38,6 @@ module Fontist
38
38
 
39
39
  attr_reader :file, :sha, :file_size
40
40
 
41
- def default_file_size
42
- 5 * byte_to_megabyte
43
- end
44
-
45
41
  def byte_to_megabyte
46
42
  @byte_to_megabyte ||= 1024 * 1024
47
43
  end
@@ -51,10 +47,10 @@ module Fontist
51
47
  end
52
48
 
53
49
  def set_progress_bar(progress_bar)
54
- if ENV.fetch("TEST_ENV", "") === "CI" || progress_bar
50
+ if progress_bar
55
51
  ProgressBar.new(@file_size)
56
52
  else
57
- NullProgressBar.new
53
+ NullProgressBar.new(@file_size)
58
54
  end
59
55
  end
60
56
 
@@ -79,24 +75,13 @@ module Fontist
79
75
  end
80
76
  end
81
77
 
82
- class NullProgressBar
83
- def total=(_)
84
- # do nothing
85
- end
86
-
87
- def increment(_)
88
- # do nothing
89
- end
90
-
91
- def finish(_ = nil)
92
- # do nothing
93
- end
94
- end
95
-
96
78
  class ProgressBar
97
79
  def initialize(total)
98
- @counter = 1
80
+ @counter = 0
99
81
  @total = total
82
+ @printed_percent = -1
83
+ @printed_size = -1
84
+ @start = Time.now
100
85
  end
101
86
 
102
87
  def total=(total)
@@ -105,22 +90,57 @@ module Fontist
105
90
 
106
91
  def increment(progress)
107
92
  @counter = progress
108
- Fontist.ui.print "\r\e[0KDownloads: #{counter_mb}MB/#{total_mb}MB " \
109
- "(#{completeness})"
93
+
94
+ print_incrementally
95
+ end
96
+
97
+ def finish
98
+ print
99
+
100
+ Fontist.ui.print(format(", %<mb_per_second>.2f MiB/s, done.\n", mb_per_second: mb_per_second))
110
101
  end
111
102
 
112
- def finish(message = nil)
113
- if message
114
- Fontist.ui.print " (#{message})\n"
103
+ private
104
+
105
+ def print_incrementally
106
+ if total?
107
+ print_percent_incrementally
115
108
  else
116
- Fontist.ui.print "\n"
109
+ print_size_incrementally
117
110
  end
118
111
  end
119
112
 
120
- private
113
+ def print
114
+ if total?
115
+ print_percent
116
+ else
117
+ print_size
118
+ end
119
+ end
120
+
121
+ def total?
122
+ !!@total
123
+ end
121
124
 
122
- def completeness
123
- sprintf("%#.2f%%", (@counter.fdiv(@total) * 100)) # rubocop:disable Style/FormatStringToken, Metrics/LineLength
125
+ def print_percent_incrementally
126
+ return unless percent > @printed_percent
127
+
128
+ print_percent
129
+
130
+ @printed_percent = percent
131
+ end
132
+
133
+ def print_percent
134
+ # rubocop:disable Style/FormatStringToken
135
+ Fontist.ui.print(format("\r\e[0KDownloading: %<completeness>3d%% (%<counter_mb>d/%<total_mb>d MiB)",
136
+ completeness: percent,
137
+ counter_mb: counter_mb,
138
+ total_mb: total_mb))
139
+ # rubocop:enable Style/FormatStringToken
140
+ end
141
+
142
+ def percent
143
+ (@counter.fdiv(@total) * 100).to_i
124
144
  end
125
145
 
126
146
  def counter_mb
@@ -134,6 +154,28 @@ module Fontist
134
154
  def byte_to_megabyte
135
155
  @byte_to_megabyte ||= 1024 * 1024
136
156
  end
157
+
158
+ def print_size_incrementally
159
+ return unless counter_mb > @printed_size
160
+
161
+ print_size
162
+
163
+ @printed_size = counter_mb
164
+ end
165
+
166
+ def print_size
167
+ Fontist.ui.print(format("\r\e[0KDownloading: %<downloaded>4d MiB", downloaded: counter_mb))
168
+ end
169
+
170
+ def mb_per_second
171
+ @counter / (Time.now - @start) / byte_to_megabyte
172
+ end
173
+ end
174
+
175
+ class NullProgressBar < ProgressBar
176
+ def print_incrementally
177
+ # do nothing
178
+ end
137
179
  end
138
180
  end
139
181
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.8.8".freeze
2
+ VERSION = "1.8.13".freeze
3
3
  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.8.8
4
+ version: 1.8.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-26 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '1.6'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.0'
68
+ version: '1.6'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: excavate
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -243,6 +243,7 @@ extensions: []
243
243
  extra_rdoc_files: []
244
244
  files:
245
245
  - ".github/workflows/check_google.yml"
246
+ - ".github/workflows/metanorma.yml"
246
247
  - ".github/workflows/release.yml"
247
248
  - ".github/workflows/rspec.yml"
248
249
  - ".gitignore"
@@ -337,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
338
  version: '0'
338
339
  requirements: []
339
340
  rubygems_version: 3.0.3
340
- signing_key:
341
+ signing_key:
341
342
  specification_version: 4
342
343
  summary: Install openly-licensed fonts on Windows, Linux and Mac!
343
344
  test_files: []