Class: HexaPDF::Layout::InlineBox

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#boxObject (readonly)

The wrapped Box object.



59
60
61
# File 'lib/hexapdf/layout/inline_box.rb', line 59

def box
  @box
end

#valignObject (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.

Returns:

  • (Boolean)


71
72
73
# File 'lib/hexapdf/layout/inline_box.rb', line 71

def empty?
  box.empty?
end

#heightObject

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

#widthObject

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_maxObject

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_minObject

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