Class: Fontisan::Commands::ExportCommand

Inherits:
BaseCommand show all
Defined in:
lib/fontisan/commands/export_command.rb

Overview

ExportCommand provides CLI interface for font export to YAML/JSON

This command exports fonts to TTX-like YAML/JSON formats for debugging and font analysis. Supports selective table export and both formats.

Examples:

Exporting entire font

command = ExportCommand.new(
  input: "font.ttf",
  output: "font.yaml"
)
command.run

Exporting specific tables

command = ExportCommand.new(
  input: "font.ttf",
  output: "meta.yaml",
  tables: ["head", "name", "cmap"]
)
command.run

Instance Method Summary collapse

Constructor Details

#initialize(input:, output: nil, format: :yaml, tables: nil, binary_format: :hex, pretty: true) ⇒ ExportCommand

Initialize export command

Parameters:

  • input (String)

    Path to input font file

  • output (String, nil) (defaults to: nil)

    Path to output file (default: stdout)

  • format (Symbol) (defaults to: :yaml)

    Output format (:yaml or :json)

  • tables (Array<String>, nil) (defaults to: nil)

    Specific tables to export

  • binary_format (Symbol) (defaults to: :hex)

    Binary encoding (:hex or :base64)

  • pretty (Boolean) (defaults to: true)

    Pretty-print output



37
38
39
40
41
42
43
44
45
46
# File 'lib/fontisan/commands/export_command.rb', line 37

def initialize(input:, output: nil, format: :yaml, tables: nil,
               binary_format: :hex, pretty: true)
  super()
  @input = input
  @output = output
  @format = format.to_sym
  @tables = tables
  @binary_format = binary_format.to_sym
  @pretty = pretty
end

Instance Method Details

#runInteger

Run the export command

Returns:

  • (Integer)

    Exit code (0 = success, 1 = error)



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fontisan/commands/export_command.rb', line 51

def run
  validate_params!

  # Load font
  font = load_font
  return 1 unless font

  # Create exporter
  exporter = Export::Exporter.new(
    font,
    @input,
    binary_format: @binary_format,
  )

  # Export to model
  export_model = exporter.export(
    tables: @tables || :all,
    format: @format,
  )

  # Output result
  output_export(export_model)

  0
rescue StandardError => e
  puts "Error: #{e.message}"
  puts e.backtrace.join("\n") if ENV["DEBUG"]
  1
end