Class: Fontisan::Cli

Inherits:
Thor
  • Object
show all
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.

Examples:

Run the info command

Fontisan::Cli.start(['info', 'font.ttf'])

Instance Method Summary collapse

Instance Method Details

#dump_table(font_file, table_tag) ⇒ Object

Dump raw binary table data to stdout.

Parameters:

  • font_file (String)

    Path to the font file

  • table_tag (String)

    Four-character table tag (e.g., ‘name’, ‘head’)



133
134
135
136
137
138
139
140
141
142
# File 'lib/fontisan/cli.rb', line 133

def dump_table(font_file, table_tag)
  command = Commands::DumpTableCommand.new(font_file, table_tag, options)
  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

#features(font_file) ⇒ Object

List OpenType features available for scripts. If no script is specified, shows features for all scripts.

Parameters:

  • font_file (String)

    Path to the font file



120
121
122
123
124
125
126
# File 'lib/fontisan/cli.rb', line 120

def features(font_file)
  command = Commands::FeaturesCommand.new(font_file, options)
  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.

Parameters:

  • font_file (String)

    Path to the font file



56
57
58
59
60
61
62
# File 'lib/fontisan/cli.rb', line 56

def glyphs(font_file)
  command = Commands::GlyphsCommand.new(font_file, options)
  result = command.run
  output_result(result)
rescue Errno::ENOENT, Error => e
  handle_error(e)
end

#info(font_file) ⇒ Object

Extract and display comprehensive font metadata.

Parameters:

  • font_file (String)

    Path to the font file



32
33
34
35
36
37
38
# File 'lib/fontisan/cli.rb', line 32

def info(font_file)
  command = Commands::InfoCommand.new(font_file, options)
  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.

Parameters:

  • font_file (String)

    Path to the font file



92
93
94
95
96
97
98
# File 'lib/fontisan/cli.rb', line 92

def optical_size(font_file)
  command = Commands::OpticalSizeCommand.new(font_file, options)
  result = command.run
  output_result(result)
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.

Parameters:

  • font_file (String)

    Path to the font file



104
105
106
107
108
109
110
# File 'lib/fontisan/cli.rb', line 104

def scripts(font_file)
  command = Commands::ScriptsCommand.new(font_file, options)
  result = command.run
  output_result(result)
rescue Errno::ENOENT, Error => e
  handle_error(e)
end

#tables(font_file) ⇒ Object

List all OpenType tables in the font file.

Parameters:

  • font_file (String)

    Path to the font file



44
45
46
47
48
49
50
# File 'lib/fontisan/cli.rb', line 44

def tables(font_file)
  command = Commands::TablesCommand.new(font_file, options)
  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.

Parameters:

  • font_file (String)

    Path to the font file



68
69
70
71
72
73
74
# File 'lib/fontisan/cli.rb', line 68

def unicode(font_file)
  command = Commands::UnicodeCommand.new(font_file, options)
  result = command.run
  output_result(result)
rescue Errno::ENOENT, Error => e
  handle_error(e)
end

#variable(font_file) ⇒ Object

Display variable font variation axes and instances.

Parameters:

  • font_file (String)

    Path to the font file



80
81
82
83
84
85
86
# File 'lib/fontisan/cli.rb', line 80

def variable(font_file)
  command = Commands::VariableCommand.new(font_file, options)
  result = command.run
  output_result(result)
rescue Errno::ENOENT, Error => e
  handle_error(e)
end

#versionObject

Display the Fontisan version.



146
147
148
# File 'lib/fontisan/cli.rb', line 146

def version
  puts "Fontisan version #{Fontisan::VERSION}"
end