Class: Fontisan::Converters::TableCopier
- Inherits:
-
Object
- Object
- Fontisan::Converters::TableCopier
- Includes:
- ConversionStrategy
- Defined in:
- lib/fontisan/converters/table_copier.rb
Overview
Strategy for same-format font operations (copy/optimize)
TableCopier handles
conversions where the source and target formats are the same.
This is useful for:
- Creating a clean copy of a font
- Re-ordering tables
- Removing corruption
- Normalizing structure
The strategy simply copies all tables from the source font and reassembles them with proper checksums and offsets.
Instance Method Summary collapse
-
#convert(font, _options = {}) ⇒ Hash<String, String>
Convert font by copying all tables.
-
#supported_conversions ⇒ Array<Array<Symbol>>
Get supported conversions.
-
#validate(font, target_format) ⇒ Boolean
Validate font for copying.
Methods included from ConversionStrategy
Instance Method Details
#convert(font, _options = {}) ⇒ Hash<String, String>
Convert font by copying all tables
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fontisan/converters/table_copier.rb', line 30 def convert(font, = {}) raise ArgumentError, "Font cannot be nil" if font.nil? unless font.respond_to?(:tables) raise ArgumentError, "Font must respond to :tables" end unless font.respond_to?(:table_data) raise ArgumentError, "Font must respond to :table_data" end target_format = detect_format(font) validate(font, target_format) tables = {} # Copy all tables from source font font.table_data.each do |tag, data| tables[tag] = data if data end tables end |
#supported_conversions ⇒ Array<Array<Symbol>>
Get supported conversions
Supports same-format conversions for TTF and OTF
59 60 61 62 63 64 |
# File 'lib/fontisan/converters/table_copier.rb', line 59 def supported_conversions [ %i[ttf ttf], %i[otf otf], ] end |
#validate(font, target_format) ⇒ Boolean
Validate font for copying
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fontisan/converters/table_copier.rb', line 73 def validate(font, target_format) raise ArgumentError, "Font cannot be nil" if font.nil? unless font.respond_to?(:tables) raise ArgumentError, "Font must respond to :tables" end unless font.respond_to?(:table_data) raise ArgumentError, "Font must respond to :table_data" end # Detect source format and verify it matches target source_format = detect_format(font) unless source_format == target_format raise Fontisan::Error, "TableCopier requires source and target formats to match. " \ "Got source: #{source_format}, target: #{target_format}" end true end |