Class: Pdfrb::Layout::TextFragment
- Inherits:
-
Object
- Object
- Pdfrb::Layout::TextFragment
- Defined in:
- lib/pdfrb/layout/text_fragment.rb
Overview
A single fragment of styled text — one run of consecutive glyphs with the same Style. Pieces are [[glyph_id, x_offset, width], ...] in font units.
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#pieces ⇒ Object
readonly
Returns the value of attribute pieces.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#y_max ⇒ Object
readonly
Returns the value of attribute y_max.
-
#y_min ⇒ Object
readonly
Returns the value of attribute y_min.
Instance Method Summary collapse
- #ascender ⇒ Object
- #descender ⇒ Object
- #draw(canvas, x, y) ⇒ Object
-
#initialize(pieces:, style:, width:, height:, y_min:, y_max:) ⇒ TextFragment
constructor
A new instance of TextFragment.
Constructor Details
#initialize(pieces:, style:, width:, height:, y_min:, y_max:) ⇒ TextFragment
Returns a new instance of TextFragment.
11 12 13 14 15 16 17 18 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 11 def initialize(pieces:, style:, width:, height:, y_min:, y_max:) @pieces = pieces @style = style @width = width @height = height @y_min = y_min @y_max = y_max end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
9 10 11 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 9 def height @height end |
#pieces ⇒ Object (readonly)
Returns the value of attribute pieces.
9 10 11 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 9 def pieces @pieces end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
9 10 11 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 9 def style @style end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
9 10 11 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 9 def width @width end |
#y_max ⇒ Object (readonly)
Returns the value of attribute y_max.
9 10 11 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 9 def y_max @y_max end |
#y_min ⇒ Object (readonly)
Returns the value of attribute y_min.
9 10 11 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 9 def y_min @y_min end |
Instance Method Details
#ascender ⇒ Object
20 21 22 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 20 def ascender @y_max end |
#descender ⇒ Object
24 25 26 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 24 def descender -@y_min end |
#draw(canvas, x, y) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/pdfrb/layout/text_fragment.rb', line 28 def draw(canvas, x, y) canvas.save_graphics_state do if @style.fill_color canvas.fill_color(@style.fill_color) end canvas.text(@pieces.map(&:first).pack("U*"), at: [x, y], font: font_name_for_canvas, size: @style.font_size) end end |