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.



68
69
70
71
# File 'lib/hexapdf/layout/inline_box.rb', line 68

def initialize(box, valign: :baseline)
  @box = box
  @valign = valign
end

Instance Attribute Details

#boxObject (readonly)

The wrapped Box object.



62
63
64
# File 'lib/hexapdf/layout/inline_box.rb', line 62

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.



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

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.



52
53
54
# File 'lib/hexapdf/layout/inline_box.rb', line 52

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.



90
91
92
# File 'lib/hexapdf/layout/inline_box.rb', line 90

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)


74
75
76
# File 'lib/hexapdf/layout/inline_box.rb', line 74

def empty?
  box.empty?
end

#heightObject

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



84
85
86
# File 'lib/hexapdf/layout/inline_box.rb', line 84

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.



79
80
81
# File 'lib/hexapdf/layout/inline_box.rb', line 79

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.



100
101
102
# File 'lib/hexapdf/layout/inline_box.rb', line 100

def x_max
  width
end

#x_minObject

The minimum x-coordinate which is always 0.



95
96
97
# File 'lib/hexapdf/layout/inline_box.rb', line 95

def x_min
  0
end

#y_maxObject

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



110
111
112
# File 'lib/hexapdf/layout/inline_box.rb', line 110

def y_max
  height
end

#y_minObject

The minimum y-coordinate which is always 0.



105
106
107
# File 'lib/hexapdf/layout/inline_box.rb', line 105

def y_min
  0
end