Class: Pdfrb::Font::TrueType::Hmtx
- Inherits:
-
Object
- Object
- Pdfrb::Font::TrueType::Hmtx
- Defined in:
- lib/pdfrb/font/true_type/hmtx.rb
Overview
hmtx (Horizontal Metrics) table parser. Provides per-glyph
advance widths and left-side bearings.
Layout: numberOfHMetrics records of (u16 advance, u16 lsb),
followed by (numGlyphs - numberOfHMetrics) u16 lsbs (those
glyphs share the last advance width).
Instance Attribute Summary collapse
-
#advances ⇒ Object
readonly
Returns the value of attribute advances.
-
#lsbs ⇒ Object
readonly
Returns the value of attribute lsbs.
-
#number_of_hmetrics ⇒ Object
readonly
Returns the value of attribute number_of_hmetrics.
Instance Method Summary collapse
- #advance_width(glyph_id) ⇒ Object
-
#initialize(data, number_of_hmetrics:) ⇒ Hmtx
constructor
A new instance of Hmtx.
- #lsb(glyph_id) ⇒ Object
Constructor Details
#initialize(data, number_of_hmetrics:) ⇒ Hmtx
Returns a new instance of Hmtx.
15 16 17 18 19 |
# File 'lib/pdfrb/font/true_type/hmtx.rb', line 15 def initialize(data, number_of_hmetrics:) @data = data || "".b @number_of_hmetrics = number_of_hmetrics parse end |
Instance Attribute Details
#advances ⇒ Object (readonly)
Returns the value of attribute advances.
13 14 15 |
# File 'lib/pdfrb/font/true_type/hmtx.rb', line 13 def advances @advances end |
#lsbs ⇒ Object (readonly)
Returns the value of attribute lsbs.
13 14 15 |
# File 'lib/pdfrb/font/true_type/hmtx.rb', line 13 def lsbs @lsbs end |
#number_of_hmetrics ⇒ Object (readonly)
Returns the value of attribute number_of_hmetrics.
13 14 15 |
# File 'lib/pdfrb/font/true_type/hmtx.rb', line 13 def number_of_hmetrics @number_of_hmetrics end |
Instance Method Details
#advance_width(glyph_id) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/pdfrb/font/true_type/hmtx.rb', line 21 def advance_width(glyph_id) return 0 if @advances.empty? if glyph_id < @number_of_hmetrics @advances[glyph_id] else @advances.last end end |
#lsb(glyph_id) ⇒ Object
31 32 33 |
# File 'lib/pdfrb/font/true_type/hmtx.rb', line 31 def lsb(glyph_id) @lsbs[glyph_id] || @lsbs.last || 0 end |