Class: Fontisan::Variable::GlyphDeltaProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/variable/glyph_delta_processor.rb

Overview

Applies glyph outline deltas from gvar table

Processes delta values for glyph control points and phantom points, applying them based on region scalars to modify glyph outlines.

Handles both simple and compound glyphs, and processes phantom points which affect glyph metrics.

Examples:

Apply deltas to a glyph

processor = GlyphDeltaProcessor.new(gvar_table, shared_tuples)
modified = processor.apply_deltas(glyph_id, region_scalars)
# => { x_deltas: [...], y_deltas: [...], phantom_deltas: [...] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gvar, config = {}) ⇒ GlyphDeltaProcessor

Initialize the processor

Parameters:

  • gvar (Fontisan::Tables::Gvar)

    Glyph variations table

  • config (Hash) (defaults to: {})

    Optional configuration overrides



27
28
29
30
31
# File 'lib/fontisan/variable/glyph_delta_processor.rb', line 27

def initialize(gvar, config = {})
  @gvar = gvar
  @config = load_config.merge(config)
  @shared_tuples = gvar&.shared_tuples || []
end

Instance Attribute Details

#configHash (readonly)

Returns Configuration settings.

Returns:

  • (Hash)

    Configuration settings



21
22
23
# File 'lib/fontisan/variable/glyph_delta_processor.rb', line 21

def config
  @config
end

Instance Method Details

#apply_deltas(glyph_id, region_scalars) ⇒ Hash?

Apply deltas to a glyph

Parameters:

  • glyph_id (Integer)

    Glyph ID

  • region_scalars (Array<Float>)

    Scalar for each region

Returns:

  • (Hash, nil)

    Delta information or nil



38
39
40
41
42
43
44
45
46
47
# File 'lib/fontisan/variable/glyph_delta_processor.rb', line 38

def apply_deltas(glyph_id, region_scalars)
  return nil unless @gvar

  # Get tuple variations for this glyph
  tuple_info = @gvar.glyph_tuple_variations(glyph_id)
  return nil unless tuple_info

  # Calculate accumulated deltas
  calculate_accumulated_deltas(tuple_info, region_scalars)
end

#glyph_countInteger

Get number of glyphs with variations

Returns:

  • (Integer)

    Glyph count



63
64
65
# File 'lib/fontisan/variable/glyph_delta_processor.rb', line 63

def glyph_count
  @gvar&.glyph_count || 0
end

#has_variations?(glyph_id) ⇒ Boolean

Check if glyph has variation data

Parameters:

  • glyph_id (Integer)

    Glyph ID

Returns:

  • (Boolean)

    True if glyph has variations



53
54
55
56
57
58
# File 'lib/fontisan/variable/glyph_delta_processor.rb', line 53

def has_variations?(glyph_id)
  return false unless @gvar

  data = @gvar.glyph_variation_data(glyph_id)
  !data.nil? && !data.empty?
end