fontist 2.0.1 → 2.0.2

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: 722a298384ffed9d696e836b150d354e874211c9927ff3482e68a6e0a26367fc
4
- data.tar.gz: d8b57e7f9223bc56f0b83e0a4ef1b48db4a35e8a8fd41e9af2fe109e0ffda152
3
+ metadata.gz: 579975f05c71659ca72914f2e273dead08930e5943f230fbc4ad5029d19b5bad
4
+ data.tar.gz: c3529656ee99bbd27cd9b7c37025e79350c99ead6b5f222cb08773460b2e6feb
5
5
  SHA512:
6
- metadata.gz: 63aed7061e821c6cc0d30f73de923f1dcf2badcee91855bd99e3618ab6bb859bb6a33935e77ed586be49ae640c97457bdaa148482f02a04fd5694e7c93bc1dfc
7
- data.tar.gz: f682fc64dafb10898e5d6d676f35f7e2208f46c3fab1d58ddaf95b047fb9c94feacaffe293cdbb6cab951d47dfc28dc738e207d0eaa48b19ce1aac41be858c6a
6
+ metadata.gz: 7cffa6efd591fc625aff86d71774ef70aff09b6c0fe9d5cb53f4ff0fff81a80fb76950701267ecfd8bea637a26e046a1ce698111226c8972049d86cd0110dd7a
7
+ data.tar.gz: 8e0386ba63208db999567979f733521ff11b64b745bfd492436012761335a6a406b0fc0104176e05cecb283c4bd3924504e7668ab388a2937fd1596f6bfe8fa4
data/README.adoc CHANGED
@@ -4,7 +4,17 @@ image:https://github.com/fontist/fontist/actions/workflows/test-and-release.yml/
4
4
  image:https://img.shields.io/gem/v/fontist.svg["Gem Version", link="https://rubygems.org/gems/fontist"]
5
5
  image:https://img.shields.io/github/issues-pr-raw/fontist/fontist.svg["Pull Requests", link="https://github.com/fontist/fontist/pulls"]
6
6
 
7
- A simple library to find and download fonts for Windows, Linux and Mac.
7
+ Fontist lets you find and download fonts for Windows, Linux and Mac.
8
+
9
+ Fontist is designed to facilitate automated and unattended management of font
10
+ installations on modern operating systems.
11
+
12
+ Fontist provides a repository of open
13
+ https://github.com/fontist/formulas[Fontist Formulas] that can be easily
14
+ installed, and also supports private font formula repositories for private or
15
+ licensed commercial fonts.
16
+
17
+ Learn more (and find your font) at https://www.fontist.org[fontist.org].
8
18
 
9
19
  :toc:
10
20
 
@@ -468,8 +478,8 @@ styles. You can do that by using:
468
478
  Fontist::Font.all
469
479
  ----
470
480
 
471
- The return values are `OpenStruct` objects, so you can easily do any other
472
- operation you would do in any ruby object.
481
+ The return values are model objects, so you can easily access their properties
482
+ and perform operations on them.
473
483
 
474
484
  === `Fontist::Formula`
475
485
 
@@ -518,8 +528,8 @@ what type fonts can be installed using that formula. Usages:
518
528
  Fontist::Formula.all
519
529
  ----
520
530
 
521
- The return values are `OpenStruct` objects, so you can easily do any other
522
- operation you would do in any ruby object.
531
+ The return values are model objects, so you can easily access their properties
532
+ and perform operations on them.
523
533
 
524
534
  === `Fontist::Manifest`
525
535
 
@@ -916,6 +926,62 @@ fontist create-formula https://www.latofonts.com/files/Lato2OFL.zip
916
926
  cp lato.yml ~/.fontist/formulas/Formulas/
917
927
  ----
918
928
 
929
+ ==== Options for `create-formula`
930
+
931
+ The `create-formula` command supports several options to customize formula generation:
932
+
933
+ `--name`::
934
+ Specify a custom formula name instead of auto-detecting from fonts.
935
+ +
936
+ [source,sh]
937
+ ----
938
+ fontist create-formula https://example.com/fonts.zip --name "My Custom Fonts"
939
+ ----
940
+
941
+ `--subdir`::
942
+ Extract fonts only from a specific subdirectory within the archive.
943
+ Uses `fnmatch` patterns.
944
+ +
945
+ [source,sh]
946
+ ----
947
+ fontist create-formula https://example.com/fonts.zip --subdir "fonts/otf"
948
+ ----
949
+
950
+ `--file-pattern`::
951
+ Filter font files by pattern. Uses `fnmatch` patterns.
952
+ +
953
+ [source,sh]
954
+ ----
955
+ fontist create-formula https://example.com/fonts.zip --file-pattern "*.otf"
956
+ ----
957
+
958
+ `--name-prefix`::
959
+ Add a prefix to all font family names in the generated formula. This is useful
960
+ for distinguishing compatibility or replacement fonts from original proprietary
961
+ fonts.
962
+ +
963
+ [source,sh]
964
+ ----
965
+ fontist create-formula https://dl.winehq.org/wine/source/10.x/wine-10.18.tar.xz \
966
+ --subdir fonts \
967
+ --file-pattern '*.ttf' \
968
+ --name-prefix 'Wine '
969
+ ----
970
+ +
971
+ This will generate a formula where all fonts have names prefixed with `"Wine "`,
972
+ such as "Wine Courier", "Wine Tahoma", "Wine Symbol", etc., making it clear
973
+ these are Wine compatibility fonts rather than the original Microsoft fonts.
974
+
975
+ `--mirror`::
976
+ Specify mirror URLs for the font archive (can be used multiple times).
977
+ +
978
+ [source,sh]
979
+ ----
980
+ fontist create-formula https://example.com/fonts.zip \
981
+ --mirror https://mirror1.example.com/fonts.zip \
982
+ --mirror https://mirror2.example.com/fonts.zip
983
+ ----
984
+
919
985
 
920
986
  ==== Overriding font metadata in Fontist formulas
921
987
 
@@ -45,7 +45,7 @@ This might be useful if you want to know the name of the font or the available s
45
45
  Fontist::Font.all
46
46
  ```
47
47
 
48
- The return values are `OpenStruct` objects, so you can easily do any other operation you would do in any Ruby object.
48
+ The return values are model objects, so you can easily access their properties and perform operations on them.
49
49
 
50
50
  ## Fontist::Formula
51
51
 
@@ -79,7 +79,7 @@ The `Fontist::Formula` interface exposes an interface to list all registered fon
79
79
  Fontist::Formula.all
80
80
  ```
81
81
 
82
- The return values are `OpenStruct` objects, so you can easily do any other operation you would do in any Ruby object.
82
+ The return values are model objects, so you can easily access their properties and perform operations on them.
83
83
 
84
84
  ## Fontist::Manifest
85
85
 
data/fontist.gemspec CHANGED
@@ -30,17 +30,17 @@ Gem::Specification.new do |spec|
30
30
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
31
31
 
32
32
  spec.add_dependency "down", "~> 5.0"
33
- spec.add_dependency "extract_ttc", "~> 0.1"
33
+ spec.add_dependency "extract_ttc", "~> 0.3.7"
34
34
  spec.add_dependency "fuzzy_match", "~> 2.1"
35
35
  spec.add_dependency "json", "~> 2.0"
36
36
  spec.add_dependency "nokogiri", "~> 1.0"
37
37
  spec.add_dependency "mime-types", "~> 3.0"
38
38
  spec.add_dependency "sys-uname", "~> 1.2"
39
- spec.add_dependency "thor", "~> 1.2", ">= 1.2.1"
39
+ spec.add_dependency "thor", "~> 1.4"
40
40
  spec.add_dependency "git", "~> 1.0"
41
41
  spec.add_dependency "ttfunk", "~> 1.6"
42
42
  spec.add_dependency "plist", "~> 3.0"
43
- spec.add_dependency "excavate", "~> 0.3", '>= 0.3.4'
43
+ spec.add_dependency "excavate", "~> 0.3", '>= 0.3.8'
44
44
  spec.add_dependency "socksify", "~> 1.7"
45
45
  spec.add_dependency "lutaml-model", "~> 0.7"
46
46
  end
data/lib/fontist/cli.rb CHANGED
@@ -178,6 +178,8 @@ module Fontist
178
178
  "root dir, e.g.: stixfonts-2.10/fonts/static_otf. May include `fnmatch` patterns."
179
179
  option :file_pattern, desc: "File pattern, e.g. '*.otf'. " \
180
180
  "Uses `fnmatch` patterns."
181
+ option :name_prefix, desc: "Prefix to add to all font family names, " \
182
+ "e.g. 'Wine ' for compatibility fonts"
181
183
  def create_formula(url)
182
184
  handle_class_options(options)
183
185
  require "fontist/import/create_formula"
@@ -1,9 +1,10 @@
1
- require "ostruct"
2
-
3
1
  module Fontist
4
2
  module Helpers
5
- def self.parse_to_object(data)
6
- JSON.parse(data.to_json, object_class: OpenStruct)
3
+ def self.url_object(request)
4
+ return request unless request.include?("\"url\"")
5
+
6
+ obj = JSON.parse(request.gsub("=>", ":"))
7
+ Struct.new(:url, :headers).new(obj["url"], obj["headers"])
7
8
  end
8
9
 
9
10
  def self.run(command)
@@ -111,7 +111,8 @@ module Fontist
111
111
  @extractor ||=
112
112
  RecursiveExtraction.new(archive,
113
113
  subdir: @options[:subdir],
114
- file_pattern: @options[:file_pattern])
114
+ file_pattern: @options[:file_pattern],
115
+ name_prefix: @options[:name_prefix])
115
116
  end
116
117
 
117
118
  def archive
@@ -8,8 +8,9 @@ module Fontist
8
8
  class CollectionFile
9
9
  attr_reader :fonts
10
10
 
11
- def initialize(path)
11
+ def initialize(path, name_prefix: nil)
12
12
  @path = path
13
+ @name_prefix = name_prefix
13
14
  @fonts = read
14
15
  @extension = detect_extension
15
16
  end
@@ -25,26 +26,15 @@ module Fontist
25
26
  private
26
27
 
27
28
  def read
28
- switch_to_temp_dir do |tmp_dir|
29
+ Dir.mktmpdir do |tmp_dir|
29
30
  extract_ttfs(tmp_dir)
30
- .map { |path| Otf::FontFile.new(path) }
31
+ .map { |path| Otf::FontFile.new(path, name_prefix: @name_prefix) }
31
32
  .reject { |font_file| hidden_or_pua_encoded?(font_file) }
32
33
  end
33
34
  end
34
35
 
35
- def switch_to_temp_dir
36
- Dir.mktmpdir do |tmp_dir|
37
- Dir.chdir(tmp_dir) do
38
- yield tmp_dir
39
- end
40
- end
41
- end
42
-
43
36
  def extract_ttfs(tmp_dir)
44
- filenames = ExtractTtc.extract(@path)
45
- filenames.map do |filename|
46
- File.join(tmp_dir, filename)
47
- end
37
+ ExtractTtc.extract(@path, output_dir: tmp_dir)
48
38
  end
49
39
 
50
40
  def hidden_or_pua_encoded?(font_file)
@@ -0,0 +1,22 @@
1
+ module Fontist
2
+ module Import
3
+ class FontStyle
4
+ attr_reader :family_name, :style, :full_name, :post_script_name,
5
+ :version, :description, :filename, :copyright,
6
+ :preferred_family_name, :preferred_style
7
+
8
+ def initialize(attributes = {})
9
+ @family_name = attributes[:family_name]
10
+ @style = attributes[:style]
11
+ @full_name = attributes[:full_name]
12
+ @post_script_name = attributes[:post_script_name]
13
+ @version = attributes[:version]
14
+ @description = attributes[:description]
15
+ @filename = attributes[:filename]
16
+ @copyright = attributes[:copyright]
17
+ @preferred_family_name = attributes[:preferred_family_name]
18
+ @preferred_style = attributes[:preferred_style]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -21,8 +21,9 @@ module Fontist
21
21
 
22
22
  attr_reader :path
23
23
 
24
- def initialize(path)
24
+ def initialize(path, name_prefix: nil)
25
25
  @path = path
26
+ @name_prefix = name_prefix
26
27
  @info = read
27
28
  @extension = detect_extension
28
29
  end
@@ -36,7 +37,8 @@ module Fontist
36
37
  end
37
38
 
38
39
  def family_name
39
- info["Family"]
40
+ name = info["Family"]
41
+ @name_prefix ? "#{@name_prefix}#{name}" : name
40
42
  end
41
43
 
42
44
  def type
@@ -44,7 +46,10 @@ module Fontist
44
46
  end
45
47
 
46
48
  def preferred_family_name
47
- info["Preferred family"]
49
+ name = info["Preferred family"]
50
+ return unless name
51
+
52
+ @name_prefix ? "#{@name_prefix}#{name}" : name
48
53
  end
49
54
 
50
55
  def preferred_type
@@ -1,3 +1,5 @@
1
+ require_relative "font_style"
2
+
1
3
  module Fontist
2
4
  module Import
3
5
  class OtfStyle
@@ -24,7 +26,7 @@ module Fontist
24
26
  style[:preferred_style] = @info["Preferred subfamily"]
25
27
  end
26
28
 
27
- OpenStruct.new(style)
29
+ FontStyle.new(style)
28
30
  end
29
31
 
30
32
  private
@@ -8,10 +8,11 @@ module Fontist
8
8
  LICENSE_PATTERN =
9
9
  /(ofl\.txt|ufl\.txt|licenses?\.txt|license(\.md)?|copying)$/i.freeze
10
10
 
11
- def initialize(archive, subdir: nil, file_pattern: nil)
11
+ def initialize(archive, subdir: nil, file_pattern: nil, name_prefix: nil)
12
12
  @archive = archive
13
13
  @subdir = subdir
14
14
  @file_pattern = file_pattern
15
+ @name_prefix = name_prefix
15
16
  @operations = {}
16
17
  @font_files = []
17
18
  @collection_files = []
@@ -80,10 +81,10 @@ module Fontist
80
81
  def match_font(path)
81
82
  case Files::FontDetector.detect(path)
82
83
  when :font
83
- file = Otf::FontFile.new(path)
84
+ file = Otf::FontFile.new(path, name_prefix: @name_prefix)
84
85
  @font_files << file unless already_exist?(file)
85
86
  when :collection
86
- @collection_files << Files::CollectionFile.new(path)
87
+ @collection_files << Files::CollectionFile.new(path, name_prefix: @name_prefix)
87
88
  end
88
89
  end
89
90
 
@@ -97,7 +98,11 @@ module Fontist
97
98
  end
98
99
 
99
100
  def font_candidate?(path)
100
- font_directory?(path) && file_pattern?(path)
101
+ has_font_extension?(path) && font_directory?(path) && file_pattern?(path)
102
+ end
103
+
104
+ def has_font_extension?(path)
105
+ path.match?(/\.(ttf|otf|ttc|woff|woff2)$/i)
101
106
  end
102
107
 
103
108
  def font_directory?(path)
@@ -33,10 +33,11 @@ module Fontist
33
33
  end
34
34
 
35
35
  def try_download_file(request, source)
36
- info_log(request)
36
+ url = Helpers.url_object(request)
37
+ info_log(url)
37
38
 
38
39
  Fontist::Utils::Downloader.download(
39
- request,
40
+ url,
40
41
  sha: source.sha256,
41
42
  file_size: source.file_size,
42
43
  progress_bar: !@options[:no_progress],
@@ -102,13 +102,15 @@ module Fontist
102
102
  # rubocop:enable Metrics/MethodLength
103
103
 
104
104
  def url
105
- @file.respond_to?(:url) ? @file.url : @file
105
+ obj = Helpers.url_object(@file)
106
+ obj.respond_to?(:url) ? obj.url : obj
106
107
  end
107
108
 
108
109
  def headers
109
- @file.respond_to?(:headers) &&
110
- @file.headers &&
111
- @file.headers.to_h.map { |k, v| [k.to_s, v] }.to_h || # rubocop:disable Style/HashTransformKeys, Metrics/LineLength
110
+ obj = Helpers.url_object(@file)
111
+ obj.respond_to?(:headers) &&
112
+ obj.headers &&
113
+ obj.headers.to_h.map { |k, v| [k.to_s, v] }.to_h || # rubocop:disable Style/HashTransformKeys, Metrics/LineLength
112
114
  {}
113
115
  end
114
116
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "2.0.1".freeze
2
+ VERSION = "2.0.2".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: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-06 00:00:00.000000000 Z
11
+ date: 2025-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: 0.3.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: 0.3.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: fuzzy_match
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -114,20 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '1.2'
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: 1.2.1
117
+ version: '1.4'
121
118
  type: :runtime
122
119
  prerelease: false
123
120
  version_requirements: !ruby/object:Gem::Requirement
124
121
  requirements:
125
122
  - - "~>"
126
123
  - !ruby/object:Gem::Version
127
- version: '1.2'
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: 1.2.1
124
+ version: '1.4'
131
125
  - !ruby/object:Gem::Dependency
132
126
  name: git
133
127
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +173,7 @@ dependencies:
179
173
  version: '0.3'
180
174
  - - ">="
181
175
  - !ruby/object:Gem::Version
182
- version: 0.3.4
176
+ version: 0.3.8
183
177
  type: :runtime
184
178
  prerelease: false
185
179
  version_requirements: !ruby/object:Gem::Requirement
@@ -189,7 +183,7 @@ dependencies:
189
183
  version: '0.3'
190
184
  - - ">="
191
185
  - !ruby/object:Gem::Version
192
- version: 0.3.4
186
+ version: 0.3.8
193
187
  - !ruby/object:Gem::Dependency
194
188
  name: socksify
195
189
  requirement: !ruby/object:Gem::Requirement
@@ -288,6 +282,7 @@ files:
288
282
  - lib/fontist/import/files/collection_file.rb
289
283
  - lib/fontist/import/files/file_requirement.rb
290
284
  - lib/fontist/import/files/font_detector.rb
285
+ - lib/fontist/import/font_style.rb
291
286
  - lib/fontist/import/formula_builder.rb
292
287
  - lib/fontist/import/formula_serializer.rb
293
288
  - lib/fontist/import/google.rb