Class: Fontisan::Cli
- Inherits:
-
Thor
- Object
- Thor
- Fontisan::Cli
- Defined in:
- lib/fontisan/cli.rb
Overview
Command-line interface for Fontisan.
This class provides the Thor-based CLI with commands for extracting font information and listing tables. It supports multiple output formats (text, YAML, JSON) and various options for controlling output behavior.
Instance Method Summary collapse
-
#convert(font_file) ⇒ Object
Convert a font to a different format using the universal transformation pipeline.
-
#dump_table(font_file, table_tag) ⇒ Object
Dump raw binary table data to stdout.
- #export(font_file) ⇒ Object
-
#features(font_file) ⇒ Object
List OpenType features available for scripts.
-
#glyphs(font_file) ⇒ Object
List glyph names from the font file.
-
#info(path) ⇒ Object
Extract and display comprehensive font metadata.
-
#instance(font_file) ⇒ Object
Generate static font instance from variable font.
-
#ls(file) ⇒ Object
List contents of font files with auto-detection.
-
#optical_size(font_file) ⇒ Object
Display optical size information from the font file.
-
#pack(*font_files) ⇒ Object
Create a TTC (TrueType Collection) or OTC (OpenType Collection) from multiple font files.
-
#scripts(font_file) ⇒ Object
List all scripts supported by the font from GSUB and GPOS tables.
-
#subset(font_file) ⇒ Object
Subset a font to specific glyphs.
-
#tables(font_file) ⇒ Object
List all OpenType tables in the font file.
-
#unicode(font_file) ⇒ Object
List Unicode to glyph index mappings from the font file.
-
#unpack(font_file) ⇒ Object
Extract individual fonts from a TTC (TrueType Collection) or OTC (OpenType Collection) file.
- #validate(font_file) ⇒ Object
-
#variable(font_file) ⇒ Object
Display variable font variation axes and instances.
-
#version ⇒ Object
Display the Fontisan version.
Instance Method Details
#convert(font_file) ⇒ Object
Convert a font to a different format using the universal transformation pipeline.
Supported conversions:
-
TTF ↔ OTF: Outline format conversion
-
WOFF/WOFF2: Web font packaging
-
Variable fonts: Automatic variation preservation or instance generation
Variable Font Operations: The pipeline automatically detects whether variation data can be preserved based on source and target formats. For same outline family (TTF→WOFF or OTF→WOFF2), variation is preserved automatically. For cross-family conversions (TTF↔OTF), an instance is generated unless –preserve-variation is explicitly set.
Instance Generation: Use –coordinates to specify exact axis values (e.g., wght=700,wdth=100) or –instance-index to use a named instance. Individual axis options (–wght, –wdth) are also supported for convenience.
267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/fontisan/cli.rb', line 267 def convert(font_file) # Build instance coordinates from axis options instance_coords = build_instance_coordinates() # Merge coordinates into options = .to_h.dup [:instance_coordinates] = instance_coords if instance_coords.any? command = Commands::ConvertCommand.new(font_file, ) command.run rescue Errno::ENOENT, Error => e handle_error(e) end |
#dump_table(font_file, table_tag) ⇒ Object
Dump raw binary table data to stdout.
336 337 338 339 340 341 342 343 344 345 |
# File 'lib/fontisan/cli.rb', line 336 def dump_table(font_file, table_tag) command = Commands::DumpTableCommand.new(font_file, table_tag, ) raw_data = command.run # Write binary data directly to stdout $stdout.binmode $stdout.write(raw_data) rescue Errno::ENOENT, Error => e handle_error(e) end |
#export(font_file) ⇒ Object
369 370 371 372 373 374 375 376 377 378 |
# File 'lib/fontisan/cli.rb', line 369 def export(font_file) command = Commands::ExportCommand.new( font_file, output: [:output], format: [:format].to_sym, tables: [:tables], binary_format: [:binary_format].to_sym, ) exit command.run end |
#features(font_file) ⇒ Object
List OpenType features available for scripts. If no script is specified, shows features for all scripts.
146 147 148 149 150 151 152 |
# File 'lib/fontisan/cli.rb', line 146 def features(font_file) command = Commands::FeaturesCommand.new(font_file, ) result = command.run output_result(result) rescue Errno::ENOENT, Error => e handle_error(e) end |
#glyphs(font_file) ⇒ Object
List glyph names from the font file.
82 83 84 85 86 87 88 |
# File 'lib/fontisan/cli.rb', line 82 def glyphs(font_file) command = Commands::GlyphsCommand.new(font_file, ) result = command.run output_result(result) rescue Errno::ENOENT, Error => e handle_error(e) end |
#info(path) ⇒ Object
Extract and display comprehensive font metadata.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fontisan/cli.rb', line 32 def info(path) command = Commands::InfoCommand.new(path, ) info = command.run output_result(info) unless [:quiet] rescue Errno::ENOENT => e if [:verbose] raise else warn "File not found: #{path}" unless [:quiet] exit 1 end end |
#instance(font_file) ⇒ Object
Generate static font instance from variable font.
You can specify axis coordinates using –wght, –wdth, etc., or use a predefined named instance with –named-instance. Use –list-instances to see available named instances.
324 325 326 327 328 329 |
# File 'lib/fontisan/cli.rb', line 324 def instance(font_file) command = Commands::InstanceCommand.new command.execute(font_file, ) rescue Errno::ENOENT, Error => e handle_error(e) end |
#ls(file) ⇒ Object
List contents of font files with auto-detection.
For collections (TTC/OTC): Lists all fonts in the collection For individual fonts (TTF/OTF): Shows quick font summary
58 59 60 61 62 63 64 |
# File 'lib/fontisan/cli.rb', line 58 def ls(file) command = Commands::LsCommand.new(file, ) result = command.run output_result(result) rescue Errno::ENOENT, Error => e handle_error(e) end |
#optical_size(font_file) ⇒ Object
Display optical size information from the font file.
118 119 120 121 122 123 124 |
# File 'lib/fontisan/cli.rb', line 118 def optical_size(font_file) command = Commands::OpticalSizeCommand.new(font_file, ) result = command.run output_result(result) rescue Errno::ENOENT, Error => e handle_error(e) end |
#pack(*font_files) ⇒ Object
Create a TTC (TrueType Collection) or OTC (OpenType Collection) from multiple font files.
This command combines multiple fonts into a single collection file with shared table deduplication to save space. It supports both TTC and OTC formats.
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/fontisan/cli.rb', line 463 def pack(*font_files) command = Commands::PackCommand.new(font_files, ) result = command.run unless [:quiet] puts "Collection created successfully:" puts " Output: #{result[:output]}" puts " Format: #{result[:format].upcase}" puts " Fonts: #{result[:num_fonts]}" puts " Size: #{format_size(result[:output_size])}" if result[:space_savings].positive? puts " Space saved: #{format_size(result[:space_savings])}" puts " Sharing: #{result[:sharing_percentage]}%" end end rescue Errno::ENOENT, Error => e handle_error(e) end |
#scripts(font_file) ⇒ Object
List all scripts supported by the font from GSUB and GPOS tables.
130 131 132 133 134 135 136 |
# File 'lib/fontisan/cli.rb', line 130 def scripts(font_file) command = Commands::ScriptsCommand.new(font_file, ) result = command.run output_result(result) rescue Errno::ENOENT, Error => e handle_error(e) end |
#subset(font_file) ⇒ Object
Subset a font to specific glyphs.
You must specify one of –text, –glyphs, or –unicode to define which glyphs to include in the subset.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/fontisan/cli.rb', line 184 def subset(font_file) command = Commands::SubsetCommand.new(font_file, ) result = command.run unless [:quiet] puts "Subset font created:" puts " Input: #{result[:input]}" puts " Output: #{result[:output]}" puts " Original glyphs: #{result[:original_glyphs]}" puts " Subset glyphs: #{result[:subset_glyphs]}" puts " Profile: #{result[:profile]}" puts " Size: #{format_size(result[:size])}" end rescue Errno::ENOENT, Error => e handle_error(e) end |
#tables(font_file) ⇒ Object
List all OpenType tables in the font file.
70 71 72 73 74 75 76 |
# File 'lib/fontisan/cli.rb', line 70 def tables(font_file) command = Commands::TablesCommand.new(font_file, ) result = command.run output_result(result) rescue Errno::ENOENT, Error => e handle_error(e) end |
#unicode(font_file) ⇒ Object
List Unicode to glyph index mappings from the font file.
94 95 96 97 98 99 100 |
# File 'lib/fontisan/cli.rb', line 94 def unicode(font_file) command = Commands::UnicodeCommand.new(font_file, ) result = command.run output_result(result) rescue Errno::ENOENT, Error => e handle_error(e) end |
#unpack(font_file) ⇒ Object
Extract individual fonts from a TTC (TrueType Collection) or OTC (OpenType Collection) file.
This command unpacks fonts from collection files, optionally converting them to different formats during extraction.
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/fontisan/cli.rb', line 417 def unpack(font_file) command = Commands::UnpackCommand.new(font_file, ) result = command.run unless [:quiet] puts "Collection unpacked successfully:" puts " Input: #{result[:collection]}" puts " Output directory: #{result[:output_dir]}" puts " Fonts extracted: #{result[:fonts_extracted]}/#{result[:num_fonts]}" result[:extracted_files].each do |file| size = File.size(file) puts " - #{File.basename(file)} (#{format_size(size)})" end end rescue Errno::ENOENT, Error => e handle_error(e) end |
#validate(font_file) ⇒ Object
350 351 352 353 |
# File 'lib/fontisan/cli.rb', line 350 def validate(font_file) command = Commands::ValidateCommand.new(font_file, verbose: [:verbose]) exit command.run end |
#variable(font_file) ⇒ Object
Display variable font variation axes and instances.
106 107 108 109 110 111 112 |
# File 'lib/fontisan/cli.rb', line 106 def variable(font_file) command = Commands::VariableCommand.new(font_file, ) result = command.run output_result(result) rescue Errno::ENOENT, Error => e handle_error(e) end |