Class: Fontisan::Commands::ConvertCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Fontisan::Commands::ConvertCommand
- Defined in:
- lib/fontisan/commands/convert_command.rb
Overview
Command for converting fonts between formats
[‘ConvertCommand`](lib/fontisan/commands/convert_command.rb) provides CLI interface for font format conversion operations using the universal transformation pipeline. It supports:
-
Same-format operations (copy/optimize)
-
TTF ↔ OTF outline format conversion
-
Variable font operations (preserve/instance generation)
-
WOFF/WOFF2 compression
The command uses [‘TransformationPipeline`](lib/fontisan/pipeline/transformation_pipeline.rb) to orchestrate conversions with appropriate strategies.
Instance Method Summary collapse
-
#initialize(font_path, options = {}) ⇒ ConvertCommand
constructor
Initialize convert command.
-
#run ⇒ Hash
Execute the conversion.
Constructor Details
#initialize(font_path, options = {}) ⇒ ConvertCommand
Initialize convert command
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fontisan/commands/convert_command.rb', line 52 def initialize(font_path, = {}) super(font_path, ) @output_path = [:output] # Parse target format @target_format = parse_target_format([:to]) # Parse coordinates if string provided @coordinates = if [:coordinates] parse_coordinates([:coordinates]) elsif [:instance_coordinates] [:instance_coordinates] end @instance_index = [:instance_index] @preserve_variation = [:preserve_variation] @preserve_hints = .fetch(:preserve_hints, false) @validate = ![:no_validate] end |
Instance Method Details
#run ⇒ Hash
Execute the conversion
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/fontisan/commands/convert_command.rb', line 77 def run puts "Converting #{File.basename(font_path)} to #{@target_format}..." unless @options[:quiet] # Build pipeline options = { target_format: @target_format, validate: @validate, verbose: @options[:verbose], } # Add variation options if specified [:coordinates] = @coordinates if @coordinates [:instance_index] = @instance_index if @instance_index unless @preserve_variation.nil? [:preserve_variation] = @preserve_variation end # Add hint preservation option [:preserve_hints] = @preserve_hints if @preserve_hints # Use TransformationPipeline for universal conversion pipeline = Pipeline::TransformationPipeline.new( font_path, @output_path, , ) result = pipeline.transform # Display results unless @options[:quiet] output_size = File.size(@output_path) input_size = File.size(font_path) puts "Conversion complete!" puts " Input: #{font_path} (#{format_size(input_size)})" puts " Output: #{@output_path} (#{format_size(output_size)})" puts " Format: #{result[:details][:source_format]} → #{result[:details][:target_format]}" if result[:details][:variation_preserved] puts " Variation: Preserved (#{result[:details][:variation_strategy]})" elsif result[:details][:variation_strategy] != :preserve puts " Variation: Instance generated (#{result[:details][:variation_strategy]})" end end { success: true, input_path: font_path, output_path: @output_path, source_format: result[:details][:source_format], target_format: result[:details][:target_format], input_size: File.size(font_path), output_size: File.size(@output_path), variation_strategy: result[:details][:variation_strategy], } rescue ArgumentError # Let ArgumentError propagate for validation errors raise rescue StandardError => e raise Error, "Conversion failed: #{e.}" end |