Class: Pdfrb::Layout::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/layout/box.rb

Overview

Base class for all layout boxes. A Box has a width, height, and content; it knows how to fit itself into a Frame region and how to draw onto a Canvas at a given (x, y) location.

Subclasses override fit (compute height for given width) and draw_content (render to canvas).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: 0, height: 0, style: Style.new(:base)) ⇒ Box

Returns a new instance of Box.



14
15
16
17
18
# File 'lib/pdfrb/layout/box.rb', line 14

def initialize(width: 0, height: 0, style: Style.new(:base), **)
  @width = width.to_f
  @height = height.to_f
  @style = style
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



12
13
14
# File 'lib/pdfrb/layout/box.rb', line 12

def height
  @height
end

#styleObject (readonly)

Returns the value of attribute style.



12
13
14
# File 'lib/pdfrb/layout/box.rb', line 12

def style
  @style
end

#widthObject (readonly)

Returns the value of attribute width.



12
13
14
# File 'lib/pdfrb/layout/box.rb', line 12

def width
  @width
end

Instance Method Details

#draw(canvas, x, y) ⇒ Object

Draw this box at (x, y) on canvas. Subclasses override draw_content.



29
30
31
32
# File 'lib/pdfrb/layout/box.rb', line 29

def draw(canvas, x, y)
  draw_background(canvas, x, y)
  draw_content(canvas, x, y)
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/pdfrb/layout/box.rb', line 38

def empty?
  false
end

#fit?(_available_width, _available_height) ⇒ Boolean

Fit this box into the given available (width, height) region. Returns true if it fits (sets @height); false otherwise. Subclasses override.

Returns:

  • (Boolean)


23
24
25
# File 'lib/pdfrb/layout/box.rb', line 23

def fit?(_available_width, _available_height)
  true
end

#supports_position_flow?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/pdfrb/layout/box.rb', line 34

def supports_position_flow?
  false
end