Class: Fontisan::Subset::TableStrategy::Hmtx

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/subset/table_strategy/hmtx.rb

Overview

Hmtx strategy: emit one LongHorMetric per glyph in the subset's glyph mapping, in the same order as the mapping. Also records the maximum advanceWidth into [SharedState] so Hhea (which is processed alphabetically before Hmtx) can read it.

Tables are processed in profile order — Hhea comes before Hmtx alphabetically — so Hhea reads its max advance via a private helper that walks the source hmtx directly. Hmtx then stashes the value into SharedState for any later consumer.

Class Method Summary collapse

Class Method Details

.call(context:, tag:, table:) ⇒ String

Returns binary hmtx bytes for the subset.

Parameters:

Returns:

  • (String)

    binary hmtx bytes for the subset



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fontisan/subset/table_strategy/hmtx.rb', line 20

def self.call(context:, tag:, table:)
  ensure_parsed!(context, table)

  data = String.new(encoding: Encoding::BINARY)
  max_advance = 0

  context.mapping.old_ids.each do |old_id|
    metric = table.metric_for(old_id)
    next unless metric

    advance = metric[:advance_width]
    max_advance = advance if advance && advance > max_advance
    data << [advance].pack("n")
    data << [metric[:lsb]].pack("n")
  end

  context.state.subset_max_advance = max_advance
  data
end