Class: TTFunk::Table::Hmtx
- Inherits:
-
TTFunk::Table
- Object
- TTFunk::Table
- TTFunk::Table::Hmtx
- Defined in:
- lib/ttfunk/table/hmtx.rb
Overview
Horizontal Metrics (‘hmtx`) table.
Defined Under Namespace
Classes: HorizontalMetric
Instance Attribute Summary collapse
-
#left_side_bearings ⇒ Array<Ingteger>
readonly
Left side bearings.
-
#metrics ⇒ Array<HorizontalMetric>
readonly
Glyph horizontal metrics.
-
#widths ⇒ Array<Integer>
readonly
Glyph widths.
Attributes inherited from TTFunk::Table
Class Method Summary collapse
Instance Method Summary collapse
-
#for(glyph_id) ⇒ HorizontalMetric
Get horizontal metric for glyph.
Methods inherited from TTFunk::Table
#exists?, #initialize, #raw, #tag
Constructor Details
This class inherits a constructor from TTFunk::Table
Instance Attribute Details
#left_side_bearings ⇒ Array<Ingteger> (readonly)
Left side bearings.
15 16 17 |
# File 'lib/ttfunk/table/hmtx.rb', line 15 def left_side_bearings @left_side_bearings end |
#metrics ⇒ Array<HorizontalMetric> (readonly)
Glyph horizontal metrics.
11 12 13 |
# File 'lib/ttfunk/table/hmtx.rb', line 11 def metrics @metrics end |
#widths ⇒ Array<Integer> (readonly)
Glyph widths.
19 20 21 |
# File 'lib/ttfunk/table/hmtx.rb', line 19 def widths @widths end |
Class Method Details
.encode(hmtx, mapping) ⇒ Hash{:number_of_metrics => Integer, :table => String}
Encode table.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ttfunk/table/hmtx.rb', line 29 def self.encode(hmtx, mapping) metrics = mapping.keys.sort.map { |new_id| metric = hmtx.for(mapping[new_id]) [metric.advance_width, metric.left_side_bearing] } { number_of_metrics: metrics.length, table: metrics.flatten.pack('n*'), } end |
Instance Method Details
#for(glyph_id) ⇒ HorizontalMetric
Get horizontal metric for glyph.
54 55 56 57 58 59 60 61 |
# File 'lib/ttfunk/table/hmtx.rb', line 54 def for(glyph_id) @metrics[glyph_id] || metrics_cache[glyph_id] ||= HorizontalMetric.new( @metrics.last.advance_width, @left_side_bearings[glyph_id - @metrics.length], ) end |