Class: Fontisan::Variation::VariationConverter
- Inherits:
-
Object
- Object
- Fontisan::Variation::VariationConverter
- Includes:
- TableAccessor
- Defined in:
- lib/fontisan/variation/converter.rb
Overview
Converts variation data between TrueType (gvar) and CFF2 (blend) formats
This class enables format conversion while preserving variation data:
-
gvar tuples → CFF2 blend operators
-
CFF2 blend operators → gvar tuples
Process for gvar → blend:
-
Extract tuple variations from gvar
-
Map tuple regions to blend regions
-
Embed blend operators in CharStrings at control points
-
Encode delta values in blend format
Process for blend → gvar:
-
Parse CharStrings with blend operators
-
Extract blend deltas and regions
-
Map to gvar tuple format
-
Build gvar table structure
Instance Attribute Summary collapse
-
#axes ⇒ Array<VariationAxisRecord>
readonly
Variation axes.
-
#font ⇒ TrueTypeFont, OpenTypeFont
readonly
Font instance.
Instance Method Summary collapse
-
#blend_to_gvar(_glyph_id) ⇒ Hash?
Convert CFF2 blend operators to gvar tuple format for a glyph.
-
#can_convert? ⇒ Boolean
Check if variation data can be converted.
-
#gvar_to_blend(glyph_id) ⇒ Hash?
Convert gvar tuples to CFF2 blend format for a glyph.
-
#initialize(font, axes) ⇒ VariationConverter
constructor
Initialize converter.
Methods included from TableAccessor
#clear_variation_cache, #clear_variation_table, #has_variation_table?, #require_variation_table, #variation_table
Constructor Details
#initialize(font, axes) ⇒ VariationConverter
Initialize converter
46 47 48 49 50 |
# File 'lib/fontisan/variation/converter.rb', line 46 def initialize(font, axes) @font = font @axes = axes || [] @variation_tables = {} end |
Instance Attribute Details
#axes ⇒ Array<VariationAxisRecord> (readonly)
Returns Variation axes.
40 41 42 |
# File 'lib/fontisan/variation/converter.rb', line 40 def axes @axes end |
#font ⇒ TrueTypeFont, OpenTypeFont (readonly)
Returns Font instance.
37 38 39 |
# File 'lib/fontisan/variation/converter.rb', line 37 def font @font end |
Instance Method Details
#blend_to_gvar(_glyph_id) ⇒ Hash?
Convert CFF2 blend operators to gvar tuple format for a glyph
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fontisan/variation/converter.rb', line 75 def blend_to_gvar(_glyph_id) return nil unless has_variation_table?("CFF2") cff2 = variation_table("CFF2") return nil unless cff2 # Get CharString with blend operators # This is a placeholder - full implementation would parse CharString # and extract blend operator data # Convert blend data to tuples # Placeholder for full implementation nil end |
#can_convert? ⇒ Boolean
Check if variation data can be converted
93 94 95 96 97 98 |
# File 'lib/fontisan/variation/converter.rb', line 93 def can_convert? !@axes.empty? && ( has_variation_table?("gvar") || has_variation_table?("CFF2") ) end |
#gvar_to_blend(glyph_id) ⇒ Hash?
Convert gvar tuples to CFF2 blend format for a glyph
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fontisan/variation/converter.rb', line 56 def gvar_to_blend(glyph_id) return nil unless has_variation_table?("gvar") return nil unless has_variation_table?("glyf") gvar = variation_table("gvar") return nil unless gvar # Get tuple variations for this glyph tuple_data = gvar.glyph_tuple_variations(glyph_id) return nil unless tuple_data # Convert tuples to blend format convert_tuples_to_blend(tuple_data) end |