Class: Fontisan::Variation::DeltaApplier
- Inherits:
-
Object
- Object
- Fontisan::Variation::DeltaApplier
- Includes:
- TableAccessor
- Defined in:
- lib/fontisan/variation/delta_applier.rb
Overview
Applies variation deltas to glyph outlines
This class handles the complete delta application process for TrueType variable fonts using gvar table data:
-
Parse base glyph outline points
-
Match active tuple variations to coordinates
-
Parse and decompress deltas
-
Apply deltas: new_point = base + Σ(delta × scalar)
-
Expand IUP (Inferred Untouched Points)
Reference: OpenType specification, gvar table
Instance Attribute Summary collapse
-
#delta_parser ⇒ DeltaParser
readonly
Delta parser.
-
#font ⇒ Font
readonly
Font object.
-
#interpolator ⇒ Interpolator
readonly
Coordinate interpolator.
-
#region_matcher ⇒ RegionMatcher
readonly
Region matcher.
Instance Method Summary collapse
-
#apply_deltas(glyph_id, coordinates) ⇒ Array<Hash>?
Apply deltas to a glyph at given coordinates.
-
#extract_glyph_points(glyph_id, glyf) ⇒ Array<Hash>?
Extract outline points from glyph.
-
#initialize(font, interpolator, region_matcher) ⇒ DeltaApplier
constructor
Initialize delta applier.
Methods included from TableAccessor
#clear_variation_cache, #clear_variation_table, #has_variation_table?, #require_variation_table, #variation_table
Constructor Details
#initialize(font, interpolator, region_matcher) ⇒ DeltaApplier
Initialize delta applier
45 46 47 48 49 50 51 |
# File 'lib/fontisan/variation/delta_applier.rb', line 45 def initialize(font, interpolator, region_matcher) @font = font @interpolator = interpolator @region_matcher = region_matcher @delta_parser = DeltaParser.new @variation_tables = {} end |
Instance Attribute Details
#delta_parser ⇒ DeltaParser (readonly)
Returns Delta parser.
38 39 40 |
# File 'lib/fontisan/variation/delta_applier.rb', line 38 def delta_parser @delta_parser end |
#font ⇒ Font (readonly)
Returns Font object.
29 30 31 |
# File 'lib/fontisan/variation/delta_applier.rb', line 29 def font @font end |
#interpolator ⇒ Interpolator (readonly)
Returns Coordinate interpolator.
32 33 34 |
# File 'lib/fontisan/variation/delta_applier.rb', line 32 def interpolator @interpolator end |
#region_matcher ⇒ RegionMatcher (readonly)
Returns Region matcher.
35 36 37 |
# File 'lib/fontisan/variation/delta_applier.rb', line 35 def region_matcher @region_matcher end |
Instance Method Details
#apply_deltas(glyph_id, coordinates) ⇒ Array<Hash>?
Apply deltas to a glyph at given coordinates
58 59 60 61 62 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 |
# File 'lib/fontisan/variation/delta_applier.rb', line 58 def apply_deltas(glyph_id, coordinates) gvar = variation_table("gvar") glyf = variation_table("glyf") return nil unless gvar && glyf # Get base glyph outline points base_points = extract_glyph_points(glyph_id, glyf) return nil if base_points.nil? || base_points.empty? # Get tuple variations for this glyph tuple_data = gvar.glyph_tuple_variations(glyph_id) return base_points if tuple_data.nil? || tuple_data[:tuples].empty? # Match active tuples to coordinates matches = @region_matcher.match_tuples( coordinates: coordinates, tuples: tuple_data[:tuples], ) return base_points if matches.empty? # Apply each active tuple's deltas adjusted_points = base_points.dup matches.each do |match| apply_tuple_deltas(adjusted_points, match, tuple_data, base_points.length) end adjusted_points end |
#extract_glyph_points(glyph_id, glyf) ⇒ Array<Hash>?
Extract outline points from glyph
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fontisan/variation/delta_applier.rb', line 94 def extract_glyph_points(glyph_id, glyf) # This is a simplified version - full implementation would parse # complete glyf table data including composite glyphs glyph_data = glyf.glyph_data(glyph_id) return nil if glyph_data.nil? # Parse glyph outline (simplified) # Real implementation would fully parse SimpleGlyph or CompositeGlyph [] end |