class HexaPDF::Layout::InlineBox

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!

Attributes

box[R]

The wrapped Box object.

valign[R]

The vertical alignment of the box.

Can be any supported value except :text - see Line for all possible values.

Public Class Methods

create(valign: :baseline, **args, &block) click to toggle source

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.

# File lib/hexapdf/layout/inline_box.rb, line 51
def self.create(valign: :baseline, **args, &block)
  new(Box.create(**args, &block), valign: valign)
end
new(box, valign: :baseline) click to toggle source

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.

# File lib/hexapdf/layout/inline_box.rb, line 67
def initialize(box, valign: :baseline)
  @box = box
  @valign = valign
end

Public Instance Methods

draw(canvas, x, y) click to toggle source

Draws the wrapped box. If the box has margins specified, the x and y offsets are correctly adjusted.

# File lib/hexapdf/layout/inline_box.rb, line 89
def draw(canvas, x, y)
  box.draw(canvas, x + box.style.margin.left, y + box.style.margin.bottom)
end
empty?() click to toggle source

Returns true if this inline box is just a placeholder without drawing operations.

# File lib/hexapdf/layout/inline_box.rb, line 73
def empty?
  box.empty?
end
height() click to toggle source

Returns the height of the wrapped box plus its top and bottom margins.

# File lib/hexapdf/layout/inline_box.rb, line 83
def height
  box.height + box.style.margin.top + box.style.margin.bottom
end
width() click to toggle source

Returns the width of the wrapped box plus its left and right margins.

# File lib/hexapdf/layout/inline_box.rb, line 78
def width
  box.width + box.style.margin.left + box.style.margin.right
end
x_max() click to toggle source

The maximum x-coordinate which is equivalent to the width of the inline box.

# File lib/hexapdf/layout/inline_box.rb, line 99
def x_max
  width
end
x_min() click to toggle source

The minimum x-coordinate which is always 0.

# File lib/hexapdf/layout/inline_box.rb, line 94
def x_min
  0
end
y_max() click to toggle source

The maximum y-coordinate which is equivalent to the height of the inline box.

# File lib/hexapdf/layout/inline_box.rb, line 109
def y_max
  height
end
y_min() click to toggle source

The minimum y-coordinate which is always 0.

# File lib/hexapdf/layout/inline_box.rb, line 104
def y_min
  0
end