Class: Fontisan::Commands::UnpackCommand
- Inherits:
-
Object
- Object
- Fontisan::Commands::UnpackCommand
- Defined in:
- lib/fontisan/commands/unpack_command.rb
Overview
Command for unpacking fonts from TTC/OTC collections
This command extracts individual font files from a TTC (TrueType Collection) or OTC (OpenType Collection) file. It can extract all fonts or a specific font by index, optionally converting to different formats during extraction.
Instance Method Summary collapse
-
#initialize(collection_path, options = {}) ⇒ UnpackCommand
constructor
Initialize unpack command.
-
#run ⇒ Hash
Execute the unpack command.
Constructor Details
#initialize(collection_path, options = {}) ⇒ UnpackCommand
Initialize unpack command
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fontisan/commands/unpack_command.rb', line 43 def initialize(collection_path, = {}) @collection_path = collection_path @options = @output_dir = [:output_dir] @font_index = [:font_index] @format = parse_format([:format]) @prefix = [:prefix] @verbose = .fetch(:verbose, false) end |
Instance Method Details
#run ⇒ Hash
Execute the unpack command
Extracts fonts from the collection and writes them as individual files.
66 67 68 69 70 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 |
# File 'lib/fontisan/commands/unpack_command.rb', line 66 def run puts "Loading collection from #{File.basename(@collection_path)}..." if @verbose # Load collection collection = load_collection # Create output directory FileUtils.mkdir_p(@output_dir) unless Dir.exist?(@output_dir) # Determine which fonts to extract indices_to_extract = determine_indices(collection) puts "Extracting #{indices_to_extract.size} font(s)..." if @verbose # Extract fonts extracted_files = extract_fonts(collection, indices_to_extract) # Display results if @verbose display_results(collection, extracted_files) end { collection: @collection_path, output_dir: @output_dir, num_fonts: collection.font_count, fonts_extracted: extracted_files.size, extracted_files: extracted_files, } rescue Fontisan::Error => e raise Fontisan::Error, "Collection unpacking failed: #{e.}" rescue ArgumentError # Let ArgumentError propagate for validation errors raise rescue StandardError => e raise Fontisan::Error, "Unexpected error during unpacking: #{e.}" end |