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.
Source Code
lib/ttfunk/table/hmtx.rb, line 15
15 | def left_side_bearings |
16 | @left_side_bearings
|
17 | end
|
#metrics ⇒ Array<HorizontalMetric> (readonly)
Glyph horizontal metrics.
Source Code
lib/ttfunk/table/hmtx.rb, line 11
11 | def metrics |
12 | @metrics
|
13 | end
|
#widths ⇒ Array<Integer> (readonly)
Glyph widths.
Source Code
lib/ttfunk/table/hmtx.rb, line 19
19 | def widths |
20 | @widths
|
21 | end
|
Class Method Details
.encode(hmtx, mapping) ⇒ Hash{:number_of_metrics => Integer, :table => String}
Encode table.
Source Code
lib/ttfunk/table/hmtx.rb, line 29
29 | def self.encode(hmtx, mapping) |
30 | metrics = |
31 | mapping.keys.sort.map { |new_id| |
32 | metric = hmtx.for(mapping[new_id]) |
33 | [metric.advance_width, metric.left_side_bearing] |
34 | }
|
35 | |
36 | {
|
37 | number_of_metrics: metrics.length, |
38 | table: metrics.flatten.pack('n*'), |
39 | }
|
40 | end
|
Instance Method Details
#for(glyph_id) ⇒ HorizontalMetric
Get horizontal metric for glyph.
Source Code
lib/ttfunk/table/hmtx.rb, line 54
54 | def for(glyph_id) |
55 | @metrics[glyph_id] || |
56 | metrics_cache[glyph_id] ||= |
57 | HorizontalMetric.new( |
58 | @metrics.last.advance_width, |
59 | @left_side_bearings[glyph_id - @metrics.length], |
60 | )
|
61 | end
|