Class: HexaPDF::Layout::InlineBox
- Inherits:
-
Object
- Object
- HexaPDF::Layout::InlineBox
- Defined in:
- lib/hexapdf/layout/inline_box.rb
Overview
An InlineBox wraps a regular Box so that it can be used as an item for a Line. This enables inline graphics.
The wrapped box must have a fixed size!
Instance Attribute Summary collapse
-
#box ⇒ Object
readonly
The wrapped Box object.
-
#valign ⇒ Object
readonly
The vertical alignment of the box.
Class Method Summary collapse
-
.create(valign: :baseline, **args, &block) ⇒ Object
Creates an InlineBox that wraps a basic Box.
Instance Method Summary collapse
-
#draw(canvas, x, y) ⇒ Object
Draws the wrapped box.
-
#empty? ⇒ Boolean
Returns
true
if this inline box is just a placeholder without drawing operations. -
#height ⇒ Object
Returns the height of the wrapped box plus its top and bottom margins.
-
#initialize(box, valign: :baseline) ⇒ InlineBox
constructor
Creates a new InlineBox object wrapping
box
. -
#width ⇒ Object
Returns the width of the wrapped box plus its left and right margins.
-
#x_max ⇒ Object
The maximum x-coordinate which is equivalent to the width of the inline box.
-
#x_min ⇒ Object
The minimum x-coordinate which is always 0.
Constructor Details
#initialize(box, valign: :baseline) ⇒ InlineBox
Creates a new InlineBox object wrapping box
.
The valign
argument can be used to specify the vertical alignment of the box relative to other items in the Line.
65 66 67 68 |
# File 'lib/hexapdf/layout/inline_box.rb', line 65 def initialize(box, valign: :baseline) @box = box @valign = valign end |
Instance Attribute Details
#box ⇒ Object (readonly)
The wrapped Box object.
59 60 61 |
# File 'lib/hexapdf/layout/inline_box.rb', line 59 def box @box end |
#valign ⇒ Object (readonly)
The vertical alignment of the box.
Can be any supported value except :text - see Line for all possible values.
56 57 58 |
# File 'lib/hexapdf/layout/inline_box.rb', line 56 def valign @valign end |
Class Method Details
.create(valign: :baseline, **args, &block) ⇒ Object
Creates an InlineBox that wraps a basic Box. All arguments (except valign
) and the block are passed to Box::create.
See ::new for the valign
argument.
49 50 51 |
# File 'lib/hexapdf/layout/inline_box.rb', line 49 def self.create(valign: :baseline, **args, &block) new(Box.create(**args, &block), valign: valign) end |
Instance Method Details
#draw(canvas, x, y) ⇒ Object
Draws the wrapped box. If the box has margins specified, the x and y offsets are correctly adjusted.
87 88 89 |
# File 'lib/hexapdf/layout/inline_box.rb', line 87 def draw(canvas, x, y) box.draw(canvas, x + box.style.margin.left, y + box.style.margin.bottom) end |
#empty? ⇒ Boolean
Returns true
if this inline box is just a placeholder without drawing operations.
71 72 73 |
# File 'lib/hexapdf/layout/inline_box.rb', line 71 def empty? box.empty? end |
#height ⇒ Object
Returns the height of the wrapped box plus its top and bottom margins.
81 82 83 |
# File 'lib/hexapdf/layout/inline_box.rb', line 81 def height box.height + box.style.margin.top + box.style.margin.bottom end |
#width ⇒ Object
Returns the width of the wrapped box plus its left and right margins.
76 77 78 |
# File 'lib/hexapdf/layout/inline_box.rb', line 76 def width box.width + box.style.margin.left + box.style.margin.right end |
#x_max ⇒ Object
The maximum x-coordinate which is equivalent to the width of the inline box.
97 98 99 |
# File 'lib/hexapdf/layout/inline_box.rb', line 97 def x_max width end |
#x_min ⇒ Object
The minimum x-coordinate which is always 0.
92 93 94 |
# File 'lib/hexapdf/layout/inline_box.rb', line 92 def x_min 0 end |