Class: HexaPDF::Layout::InlineBox

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

Instance Method Summary collapse

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

#heightObject (readonly)

The height of the box.



45
46
47
# File 'lib/hexapdf/layout/inline_box.rb', line 45

def height
  @height
end

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

#widthObject (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_maxObject

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_minObject

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