Class: Fontisan::Commands::SubsetCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Fontisan::Commands::SubsetCommand
- Defined in:
- lib/fontisan/commands/subset_command.rb
Overview
Command for subsetting fonts
This command provides CLI access to font subsetting functionality. It supports multiple input methods for specifying glyphs:
-
Text input: Subset to characters in a text string
-
Glyph IDs: Subset to specific glyph IDs
-
Unicode codepoints: Subset to specific Unicode values
The command also supports various subsetting options:
-
Profile selection (pdf, web, minimal)
-
Glyph ID retention
-
Hint dropping
-
Name dropping
Instance Method Summary collapse
-
#initialize(font_path, options = {}) ⇒ SubsetCommand
constructor
Initialize subset command.
-
#run ⇒ Hash
Execute the subset command.
Constructor Details
#initialize(font_path, options = {}) ⇒ SubsetCommand
Initialize subset command
52 53 54 55 56 |
# File 'lib/fontisan/commands/subset_command.rb', line 52 def initialize(font_path, = {}) super(font_path, ) @output_path = [:output] end |
Instance Method Details
#run ⇒ Hash
Execute the subset command
63 64 65 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 |
# File 'lib/fontisan/commands/subset_command.rb', line 63 def run # Determine glyph IDs to subset glyph_ids = determine_glyph_ids # Build subsetting options = # Create builder and perform subsetting builder = Subset::Builder.new(font, glyph_ids, ) subset_binary = builder.build # Write output file (create parent directories if needed) FileUtils.mkdir_p(File.dirname(@output_path)) File.binwrite(@output_path, subset_binary) # Return result { input: font_path, output: @output_path, original_glyphs: font.table("maxp").num_glyphs, subset_glyphs: builder.mapping.size, profile: .profile, size: subset_binary.bytesize, } rescue Fontisan::SubsettingError => e raise Fontisan::SubsettingError, "Subsetting failed: #{e.}" end |