fontist 3.0.35 → 3.0.36

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: 1ade396e3811d8a2df5ae15cce0af89df56bf723bc9c915f42f72b487073de39
4
- data.tar.gz: ab738ce85235d7cdf811c0cf51ec23b28488637d09f7c9bc77ca9b91c8afb2e6
3
+ metadata.gz: d9740ba780da1a789c85954976ffa0d49227705ee62a24dc266dbc4448e63d84
4
+ data.tar.gz: 05dd6af4bb8303c4ee4807c6b0a1b2f24607dffbd448352ba9dc8dd145d924c2
5
5
  SHA512:
6
- metadata.gz: 69e7e9ef3fd5200939a9c2820cd58e19af2cef6890ee4f91b317c227c5e33b46d5ae71046663e565c4883a89bda147a39f9c723a51383ab03203c8e59ac73fcf
7
- data.tar.gz: 3e08dc9b127f6e313ddf2f6fcae9fa174832d57c0ae0bc4bb7730094f2fbc05a0171966ce1d793f1af87ef08808b88b0771630acf374347210dcb6ac8bc10f41
6
+ metadata.gz: 8663ae799c949874b9b61a23c382812f6654a379702f93907530ed8602158725ebf83dd9320cde2539b6e757e51c209833efdc167f820f7d4d695983ad0c27f0
7
+ data.tar.gz: 6f01160c9dfc7c11ace56ebac1b92c332be258716b64bd0eb8a95d8271913efc14c1499897c962e170cee914385f1ccbd79b9157f2060582f3ace220b7f3ccde
data/README.adoc CHANGED
@@ -363,6 +363,20 @@ Keeps only the glyphs for those characters. Options can be combined with
363
363
  fontist pack family.ttc Regular.ttf Bold.ttf
364
364
  ----
365
365
 
366
+ ==== Transform a font file you already have
367
+
368
+ `fontist convert` runs the same operations on a local file, without
369
+ installing anything. Each output is written next to the source unless
370
+ `--output` (or `--output-dir`) is given, and the source is never overwritten.
371
+
372
+ [source,sh]
373
+ ----
374
+ fontist convert format Lato-Regular.ttf woff2
375
+ fontist convert extract NotoSansCJK.ttc --index 1 --output-dir out
376
+ fontist convert instance "Roboto[wdth,wght].ttf" wght=300,wdth=90
377
+ fontist convert subset Lato-Regular.ttf --unicodes "U+0020-007E" --text "é"
378
+ ----
379
+
366
380
  ==== Ruby API
367
381
 
368
382
  [source,ruby]
@@ -204,6 +204,7 @@ export default defineConfig({
204
204
  { text: "repo", link: "/cli/repo" },
205
205
  { text: "fontconfig", link: "/cli/fontconfig" },
206
206
  { text: "import", link: "/cli/import" },
207
+ { text: "convert", link: "/cli/convert" },
207
208
  { text: "index", link: "/cli/index-cmd" },
208
209
  { text: "create-formula", link: "/cli/create-formula" },
209
210
  ],
@@ -0,0 +1,38 @@
1
+ # fontist convert
2
+
3
+ Transform a font file you already have, using [Fontisan](https://github.com/fontist/fontisan). Nothing is installed.
4
+
5
+ ## Syntax
6
+
7
+ ```sh
8
+ fontist convert format FONT_FILE FORMAT [--output FILE]
9
+ fontist convert extract COLLECTION --index N [--output-dir DIR]
10
+ fontist convert instance FONT_FILE AXES [--output FILE]
11
+ fontist convert subset FONT_FILE [--unicodes LIST] [--text TEXT] [--output FILE]
12
+ ```
13
+
14
+ ## Subcommands
15
+
16
+ | Subcommand | Description |
17
+ |------------|-------------|
18
+ | `format` | Convert to `ttf`, `otf`, `woff` or `woff2` |
19
+ | `extract` | Write one member of a TTC/OTC collection as a standalone font |
20
+ | `instance` | Write a static instance of a variable font at the given axis values |
21
+ | `subset` | Keep only the glyphs for the given characters |
22
+
23
+ By default each output is written next to the source: `Lato.woff2`, `Font-wght300.ttf`, `Lato-subset.ttf`. A command never overwrites its source font.
24
+
25
+ ## Examples
26
+
27
+ ```sh
28
+ fontist convert format Lato-Regular.ttf woff2
29
+ fontist convert extract NotoSansCJK.ttc --index 1 --output-dir out
30
+ fontist convert instance "Roboto[wdth,wght].ttf" wght=300,wdth=90
31
+ fontist convert subset Lato-Regular.ttf --unicodes "U+0020-007E" --text "é"
32
+ ```
33
+
34
+ Axis tags and values are checked against the font: an unknown axis or a value outside its range fails with an error.
35
+
36
+ ## Related Commands
37
+
38
+ - [fontist install](/cli/install) - The same operations while installing (`--format`, `--collection-index`, `--instance`, `--subset-*`)
data/docs/cli/index.md CHANGED
@@ -23,6 +23,7 @@ Complete command-line interface reference for Fontist.
23
23
  | [`fontist repo`](/cli/repo) | Custom repositories |
24
24
  | [`fontist fontconfig`](/cli/fontconfig) | Fontconfig integration |
25
25
  | [`fontist import`](/cli/import) | Import fonts |
26
+ | [`fontist convert`](/cli/convert) | Convert, extract, instance or subset a font file |
26
27
  | [`fontist index`](/cli/index-cmd) | System font index |
27
28
  | [`fontist create-formula`](/cli/create-formula) | Create formulas |
28
29
 
data/lib/fontist/cli.rb CHANGED
@@ -33,6 +33,7 @@ module Fontist
33
33
  Fontist::Errors::CollectionIndexError => [STATUS_UNKNOWN_ERROR],
34
34
  Fontist::Errors::UnsupportedTranscodeError => [STATUS_UNKNOWN_ERROR],
35
35
  Fontist::Errors::SourceNotFoundError => [STATUS_UNKNOWN_ERROR],
36
+ Fontist::Errors::InstanceError => [STATUS_UNKNOWN_ERROR],
36
37
  Fontist::Errors::SizeLimitError => [
37
38
  STATUS_SIZE_LIMIT_ERROR,
38
39
  :append,
@@ -470,6 +471,10 @@ module Fontist
470
471
  desc "config SUBCOMMAND ...ARGS", "Manage fontist config"
471
472
  subcommand "config", Fontist::ConfigCLI
472
473
 
474
+ desc "convert SUBCOMMAND ...ARGS",
475
+ "Convert, extract, instance or subset a font file"
476
+ subcommand "convert", Fontist::ConvertCLI
477
+
473
478
  desc "cache SUBCOMMAND ...ARGS", "Manage fontist cache"
474
479
  subcommand "cache", Fontist::CacheCLI
475
480
 
@@ -0,0 +1,88 @@
1
+ module Fontist
2
+ # `fontist convert ...`: Fontisan operations on font files the user
3
+ # already has, without installing anything.
4
+ class ConvertCLI < Thor
5
+ include CLI::ClassOptions
6
+
7
+ desc "format FONT_FILE FORMAT",
8
+ "Convert FONT_FILE to FORMAT (ttf, otf, woff, woff2)"
9
+ option :output, aliases: :o,
10
+ desc: "Output file (default: FONT_FILE, new extension)"
11
+ def to_format(source, target)
12
+ default = replace_ext(source, ".#{target.to_s.downcase}")
13
+ write_font do
14
+ output = output_for(source, default)
15
+ FontOperations::Convert.call(source, target, output)
16
+ end
17
+ end
18
+ map "format" => :to_format
19
+
20
+ desc "extract COLLECTION", "Write one member of a TTC/OTC collection"
21
+ option :index, type: :numeric, required: true,
22
+ desc: "Zero-based member index"
23
+ option :output_dir, desc: "Output directory (default: next to COLLECTION)"
24
+ def extract(collection)
25
+ dir = options[:output_dir] || File.dirname(collection)
26
+ write_font do
27
+ FontOperations::Extract.call(collection, index: options[:index],
28
+ output_dir: dir)
29
+ end
30
+ end
31
+
32
+ desc "instance FONT_FILE AXES",
33
+ "Write a static instance of a variable font (e.g. wght=300,wdth=90)"
34
+ option :output, aliases: :o,
35
+ desc: "Output file (default: FONT_FILE named after AXES)"
36
+ def instance(source, axes)
37
+ write_font do
38
+ coords = FontOperations::Instance.parse(axes)
39
+ name = FontOperations::Instance.file_name(File.basename(source), coords)
40
+ default = File.join(File.dirname(source), name)
41
+ FontOperations::Instance.call(source, output_for(source, default),
42
+ coordinates: coords)
43
+ end
44
+ end
45
+
46
+ desc "subset FONT_FILE", "Keep only the glyphs for the given characters"
47
+ option :unicodes, desc: "Codepoints to keep (e.g. 'U+0020-007E,U+00E9')"
48
+ option :text, desc: "Characters to keep"
49
+ option :output, aliases: :o,
50
+ desc: "Output file (default: FONT_FILE with -subset)"
51
+ def subset(source)
52
+ default = replace_ext(source, "-subset#{File.extname(source)}")
53
+ write_font do
54
+ FontOperations::Subset.call(source, output_for(source, default),
55
+ unicodes: options[:unicodes],
56
+ text: options[:text])
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def write_font
63
+ handle_class_options(options)
64
+ path = yield
65
+ Fontist.ui.success("Written to #{path}")
66
+ CLI::STATUS_SUCCESS
67
+ rescue Errors::GeneralError => e
68
+ Fontist.ui.error(e.message)
69
+ CLI::STATUS_UNKNOWN_ERROR
70
+ end
71
+
72
+ # The given --output, or +default+; never the source itself.
73
+ def output_for(source, default)
74
+ output = options[:output] || default
75
+ if File.expand_path(output) == File.expand_path(source)
76
+ raise FontOperations::Error,
77
+ "Output would overwrite #{source}. Give a different --output."
78
+ end
79
+
80
+ output
81
+ end
82
+
83
+ def replace_ext(path, suffix)
84
+ File.join(File.dirname(path),
85
+ File.basename(path, File.extname(path)) + suffix)
86
+ end
87
+ end
88
+ end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "3.0.35".freeze
2
+ VERSION = "3.0.36".freeze
3
3
  end
data/lib/fontist.rb CHANGED
@@ -82,6 +82,7 @@ module Fontist
82
82
  autoload :CLI, "#{__dir__}/fontist/cli"
83
83
  autoload :CacheCLI, "#{__dir__}/fontist/cache_cli"
84
84
  autoload :ConfigCLI, "#{__dir__}/fontist/config_cli"
85
+ autoload :ConvertCLI, "#{__dir__}/fontist/convert_cli"
85
86
  autoload :FontconfigCLI, "#{__dir__}/fontist/fontconfig_cli"
86
87
  autoload :ImportCLI, "#{__dir__}/fontist/import_cli"
87
88
  autoload :IndexCLI, "#{__dir__}/fontist/index_cli"
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: 3.0.35
4
+ version: 3.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -277,6 +277,7 @@ files:
277
277
  - docs/api/manifest.md
278
278
  - docs/cli/cache.md
279
279
  - docs/cli/config.md
280
+ - docs/cli/convert.md
280
281
  - docs/cli/create-formula.md
281
282
  - docs/cli/exit-codes.md
282
283
  - docs/cli/fontconfig.md
@@ -343,6 +344,7 @@ files:
343
344
  - lib/fontist/collection_file.rb
344
345
  - lib/fontist/config.rb
345
346
  - lib/fontist/config_cli.rb
347
+ - lib/fontist/convert_cli.rb
346
348
  - lib/fontist/css.rb
347
349
  - lib/fontist/css/google_family.rb
348
350
  - lib/fontist/css/local.rb