Class: Pdfrb::Font::TrueType::Glyf
- Inherits:
-
Object
- Object
- Pdfrb::Font::TrueType::Glyf
- Defined in:
- lib/pdfrb/font/true_type/glyf.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#loca ⇒ Object
readonly
Returns the value of attribute loca.
Instance Method Summary collapse
- #component_glyphs(glyph_id) ⇒ Object
- #composite?(glyph_id) ⇒ Boolean
- #empty?(glyph_id) ⇒ Boolean
- #glyph_data(glyph_id) ⇒ Object
- #glyph_header(glyph_id) ⇒ Object
-
#initialize(data, loca = nil) ⇒ Glyf
constructor
A new instance of Glyf.
Constructor Details
#initialize(data, loca = nil) ⇒ Glyf
Returns a new instance of Glyf.
9 10 11 12 |
# File 'lib/pdfrb/font/true_type/glyf.rb', line 9 def initialize(data, loca = nil) @data = data @loca = loca end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/pdfrb/font/true_type/glyf.rb', line 7 def data @data end |
#loca ⇒ Object (readonly)
Returns the value of attribute loca.
7 8 9 |
# File 'lib/pdfrb/font/true_type/glyf.rb', line 7 def loca @loca end |
Instance Method Details
#component_glyphs(glyph_id) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pdfrb/font/true_type/glyf.rb', line 48 def component_glyphs(glyph_id) return [] unless composite?(glyph_id) g = glyph_data(glyph_id) return [] unless g components = [] offset = 10 loop do break if offset + 4 > g.bytesize flags = u16(g, offset) glyph_index = u16(g, offset + 2) components << glyph_index offset += 4 offset += 4 if flags & 0x0001 != 0 offset += 2 if flags & 0x0002 != 0 break if flags.nobits?(0x0020) end components end |
#composite?(glyph_id) ⇒ Boolean
38 39 40 41 |
# File 'lib/pdfrb/font/true_type/glyf.rb', line 38 def composite?(glyph_id) h = glyph_header(glyph_id) h && h[:number_of_contours].negative? end |
#empty?(glyph_id) ⇒ Boolean
43 44 45 46 |
# File 'lib/pdfrb/font/true_type/glyf.rb', line 43 def empty?(glyph_id) length = @loca&.glyph_length(glyph_id) || 0 length.zero? end |
#glyph_data(glyph_id) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pdfrb/font/true_type/glyf.rb', line 14 def glyph_data(glyph_id) return nil unless @data && @loca return nil if glyph_id >= @loca.offsets.length - 1 offset = @loca.glyph_offset(glyph_id) length = @loca.glyph_length(glyph_id) return nil if offset.nil? || length.zero? @data.byteslice(offset, length) end |
#glyph_header(glyph_id) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pdfrb/font/true_type/glyf.rb', line 25 def glyph_header(glyph_id) g = glyph_data(glyph_id) return nil unless g && g.bytesize >= 10 { number_of_contours: s16(g, 0), x_min: s16(g, 2), y_min: s16(g, 4), x_max: s16(g, 6), y_max: s16(g, 8), } end |