Class: HexaPDF::Layout::InlineBox
- Inherits:
-
Object
- Object
- HexaPDF::Layout::InlineBox
- Defined in:
- lib/hexapdf/layout/inline_box.rb
Overview
An InlineBox can be used as an item for a LineFragment so that inline graphics are possible. The box must have a fixed size!
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
The height of the box.
-
#valign ⇒ Object
readonly
The vertical alignment of the box.
-
#width ⇒ Object
readonly
The width of the box.
Instance Method Summary collapse
-
#draw(canvas, x, y) ⇒ Object
:call-seq: box.draw(canvas, x, y) -> block_result.
-
#initialize(width, height, valign: :baseline, &block) ⇒ InlineBox
constructor
:call-seq: InlineBox.new(width, height, valign: :baseline) {|box, canvas| block} -> inline_box.
-
#x_max ⇒ Object
The maximum x-coordinate which is equivalent to the width of the box.
-
#x_min ⇒ Object
The minimum x-coordinate which is always 0.
Constructor Details
#initialize(width, height, valign: :baseline, &block) ⇒ InlineBox
:call-seq:
InlineBox.new(width, height, valign: :baseline) {|box, canvas| block} -> inline_box
Creates a new InlineBox object that uses the provided block when it is asked to draw itself on a canvas (see #draw).
Since the final location of the box is not known beforehand, the drawing operations inside the block should draw inside the rectangle (0, 0, width, height).
The valign
argument can be used to specify the vertical alignment of the box relative to other items in the LineFragment - see #valign and LineFragment.
63 64 65 66 67 68 |
# File 'lib/hexapdf/layout/inline_box.rb', line 63 def initialize(width, height, valign: :baseline, &block) @width = width @height = height @valign = valign @draw_block = block end |
Instance Attribute Details
#height ⇒ Object (readonly)
The height of the box.
45 46 47 |
# File 'lib/hexapdf/layout/inline_box.rb', line 45 def height @height end |
#valign ⇒ Object (readonly)
The vertical alignment of the box.
Can be any supported value except :text - see LineFragment for all possible values.
50 51 52 |
# File 'lib/hexapdf/layout/inline_box.rb', line 50 def valign @valign end |
#width ⇒ Object (readonly)
The width of the box.
42 43 44 |
# File 'lib/hexapdf/layout/inline_box.rb', line 42 def width @width end |
Instance Method Details
#draw(canvas, x, y) ⇒ Object
:call-seq:
box.draw(canvas, x, y) -> block_result
Draws the contents of the box onto the canvas at the position (x, y), and returns the result of the drawing block (see #initialize).
The coordinate system is translated so that the origin is at (x, y) during the drawing operations.
78 79 80 |
# File 'lib/hexapdf/layout/inline_box.rb', line 78 def draw(canvas, x, y) canvas.translate(x, y) { @draw_block.call(self, canvas) } end |
#x_max ⇒ Object
The maximum x-coordinate which is equivalent to the width of the box.
88 89 90 |
# File 'lib/hexapdf/layout/inline_box.rb', line 88 def x_max width end |
#x_min ⇒ Object
The minimum x-coordinate which is always 0.
83 84 85 |
# File 'lib/hexapdf/layout/inline_box.rb', line 83 def x_min 0 end |