Class: Fontisan::Variable::MetricDeltaProcessor

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

Overview

Applies metric deltas from HVAR, VVAR, and MVAR tables

Processes variation data for font metrics including:

  • Horizontal metrics (advance widths, LSB, RSB) via HVAR
  • Vertical metrics (advance heights, TSB, BSB) via VVAR
  • Font-level metrics (ascent, descent, line gap, etc.) via MVAR

Uses ItemVariationStore and region scalars to calculate accumulated deltas which are then applied to original metric values.

Examples:

Apply metric deltas

processor = MetricDeltaProcessor.new(hvar, vvar, mvar)
deltas = processor.apply_deltas(glyph_id, region_scalars)
# => { advance_width: 10, lsb: -2, ... }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hvar: nil, vvar: nil, mvar: nil, config: {}) ⇒ MetricDeltaProcessor

Initialize the processor

Parameters:



31
32
33
34
35
36
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 31

def initialize(hvar: nil, vvar: nil, mvar: nil, config: {})
  @hvar = hvar
  @vvar = vvar
  @mvar = mvar
  @config = load_config.merge(config)
end

Instance Attribute Details

#configHash (readonly)

Returns Configuration settings.

Returns:

  • (Hash)

    Configuration settings



23
24
25
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 23

def config
  @config
end

Instance Method Details

#advance_width_delta(glyph_id, region_scalars) ⇒ Integer

Get advance width delta for a glyph

Parameters:

  • glyph_id (Integer)

    Glyph ID

  • region_scalars (Array<Float>)

    Region scalars

Returns:

  • (Integer)

    Advance width delta



86
87
88
89
90
91
92
93
94
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 86

def advance_width_delta(glyph_id, region_scalars)
  return 0 unless @hvar

  delta_set = @hvar.advance_width_delta_set(glyph_id)
  return 0 unless delta_set

  accumulated = calculate_accumulated_delta(delta_set, region_scalars)
  apply_rounding(accumulated)
end

#apply_deltas(glyph_id, region_scalars) ⇒ Hash

Apply all metric deltas for a glyph

Parameters:

  • glyph_id (Integer)

    Glyph ID

  • region_scalars (Array<Float>)

    Scalar for each region

Returns:

  • (Hash)

    Metric deltas



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 43

def apply_deltas(glyph_id, region_scalars)
  result = {}

  # Apply horizontal metric deltas if HVAR present
  if @hvar && @config.dig(:metric_deltas, :apply_hvar)
    result[:horizontal] = apply_hvar_deltas(glyph_id, region_scalars)
  end

  # Apply vertical metric deltas if VVAR present
  if @vvar && @config.dig(:metric_deltas, :apply_vvar)
    result[:vertical] = apply_vvar_deltas(glyph_id, region_scalars)
  end

  result
end

#apply_font_metrics(region_scalars) ⇒ Hash

Apply font-level metric deltas

Parameters:

  • region_scalars (Array<Float>)

    Scalar for each region

Returns:

  • (Hash)

    Font-level metric deltas



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 63

def apply_font_metrics(region_scalars)
  return {} unless @mvar && @config.dig(:metric_deltas, :apply_mvar)

  result = {}

  # Process each metric tag in MVAR
  @mvar.metric_tags.each do |tag|
    delta_set = @mvar.metric_delta_set(tag)
    next unless delta_set

    # Calculate accumulated delta
    accumulated = calculate_accumulated_delta(delta_set, region_scalars)
    result[tag] = apply_rounding(accumulated)
  end

  result
end

#has_hvar?Boolean

Check if horizontal variations are present

Returns:

  • (Boolean)

    True if HVAR present



129
130
131
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 129

def has_hvar?
  !@hvar.nil?
end

#has_mvar?Boolean

Check if font metric variations are present

Returns:

  • (Boolean)

    True if MVAR present



143
144
145
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 143

def has_mvar?
  !@mvar.nil?
end

#has_vvar?Boolean

Check if vertical variations are present

Returns:

  • (Boolean)

    True if VVAR present



136
137
138
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 136

def has_vvar?
  !@vvar.nil?
end

#lsb_delta(glyph_id, region_scalars) ⇒ Integer

Get LSB delta for a glyph

Parameters:

  • glyph_id (Integer)

    Glyph ID

  • region_scalars (Array<Float>)

    Region scalars

Returns:

  • (Integer)

    LSB delta



101
102
103
104
105
106
107
108
109
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 101

def lsb_delta(glyph_id, region_scalars)
  return 0 unless @hvar

  delta_set = @hvar.lsb_delta_set(glyph_id)
  return 0 unless delta_set

  accumulated = calculate_accumulated_delta(delta_set, region_scalars)
  apply_rounding(accumulated)
end

#rsb_delta(glyph_id, region_scalars) ⇒ Integer

Get RSB delta for a glyph

Parameters:

  • glyph_id (Integer)

    Glyph ID

  • region_scalars (Array<Float>)

    Region scalars

Returns:

  • (Integer)

    RSB delta



116
117
118
119
120
121
122
123
124
# File 'lib/fontisan/variable/metric_delta_processor.rb', line 116

def rsb_delta(glyph_id, region_scalars)
  return 0 unless @hvar

  delta_set = @hvar.rsb_delta_set(glyph_id)
  return 0 unless delta_set

  accumulated = calculate_accumulated_delta(delta_set, region_scalars)
  apply_rounding(accumulated)
end