Class: TTFunk::Table::Hmtx

Inherits:
TTFunk::Table show all
Defined in:
lib/ttfunk/table/hmtx.rb

Defined Under Namespace

Classes: HorizontalMetric

Instance Attribute Summary collapse

Attributes inherited from TTFunk::Table

#file, #length, #offset

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TTFunk::Table

#exists?, #initialize, #raw, #tag

Constructor Details

This class inherits a constructor from TTFunk::Table

Instance Attribute Details

#left_side_bearingsObject (readonly)

Returns the value of attribute left_side_bearings.



7
8
9
# File 'lib/ttfunk/table/hmtx.rb', line 7

def left_side_bearings
  @left_side_bearings
end

#metricsObject (readonly)

Returns the value of attribute metrics.



6
7
8
# File 'lib/ttfunk/table/hmtx.rb', line 6

def metrics
  @metrics
end

#widthsObject (readonly)

Returns the value of attribute widths.



8
9
10
# File 'lib/ttfunk/table/hmtx.rb', line 8

def widths
  @widths
end

Class Method Details

.encode(hmtx, mapping) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/ttfunk/table/hmtx.rb', line 10

def self.encode(hmtx, mapping)
  metrics = mapping.keys.sort.map do |new_id|
    metric = hmtx.for(mapping[new_id])
    [metric.advance_width, metric.left_side_bearing]
  end

  { :number_of_metrics => metrics.length,
    :table => metrics.flatten.pack("n*") }
end

Instance Method Details

#for(glyph_id) ⇒ Object



22
23
24
25
26
# File 'lib/ttfunk/table/hmtx.rb', line 22

def for(glyph_id)
  @metrics[glyph_id] ||
    HorizontalMetric.new(@metrics.last.advance_width,
      @left_side_bearings[glyph_id - @metrics.length])
end