Class: Fontisan::Commands::PackCommand
- Inherits:
-
Object
- Object
- Fontisan::Commands::PackCommand
- Defined in:
- lib/fontisan/commands/pack_command.rb
Overview
Command for packing multiple fonts into a TTC/OTC collection
This command provides CLI access to font collection creation functionality. It loads multiple font files and combines them into a single TTC (TrueType Collection) or OTC (OpenType Collection) file with shared table deduplication to save space.
Instance Method Summary collapse
-
#initialize(font_paths, options = {}) ⇒ PackCommand
constructor
Initialize pack command.
-
#run ⇒ Hash
Execute the pack command.
Constructor Details
#initialize(font_paths, options = {}) ⇒ PackCommand
Initialize pack command
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fontisan/commands/pack_command.rb', line 44 def initialize(font_paths, = {}) @font_paths = font_paths @options = @output_path = [:output] @format = parse_format([:format] || :ttc) @optimize = .fetch(:optimize, true) @analyze = .fetch(:analyze, false) @verbose = .fetch(:verbose, false) end |
Instance Method Details
#run ⇒ Hash
Execute the pack command
Loads all fonts, analyzes tables, and creates a TTC/OTC collection. Optionally displays analysis before building.
71 72 73 74 75 76 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 |
# File 'lib/fontisan/commands/pack_command.rb', line 71 def run puts "Loading #{@font_paths.size} fonts..." if @verbose # Load all fonts fonts = load_fonts # Create builder builder = Collection::Builder.new(fonts, { format: @format, optimize: @optimize, }) # Validate before building builder.validate! # Show analysis if requested if @analyze || @verbose show_analysis(builder) end # Build collection puts "Building #{@format.upcase} collection..." if @verbose result = builder.build_to_file(@output_path) # Display results if @verbose display_results(result) end result rescue Fontisan::Error => e raise Fontisan::Error, "Collection packing failed: #{e.}" rescue StandardError => e raise Fontisan::Error, "Unexpected error during packing: #{e.}" end |