Class: Pdfrb::Layout::Frame
- Inherits:
-
Object
- Object
- Pdfrb::Layout::Frame
- Defined in:
- lib/pdfrb/layout/frame.rb
Overview
A rectangular region of a page where boxes are placed. The Frame
tracks which areas are filled and exposes find_available_area
to locate the next free region of a given width and height.
Simple case: the Frame is a plain rectangle. Advanced: the
shape polygon allows non-rectangular regions (L-shaped, with
cutouts around images).
Instance Attribute Summary collapse
-
#bottom ⇒ Object
readonly
Returns the value of attribute bottom.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#shape ⇒ Object
readonly
Returns the value of attribute shape.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#find_available_area(width, height) ⇒ Object
Locate the next free area of (width × height) within this Frame.
- #full? ⇒ Boolean
-
#initialize(left:, bottom:, width:, height:, shape: nil) ⇒ Frame
constructor
A new instance of Frame.
-
#remove_area(x, y, w, h) ⇒ Object
Mark the rectangle at (x, y) of (w × h) as filled.
- #right ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize(left:, bottom:, width:, height:, shape: nil) ⇒ Frame
Returns a new instance of Frame.
15 16 17 18 19 20 21 |
# File 'lib/pdfrb/layout/frame.rb', line 15 def initialize(left:, bottom:, width:, height:, shape: nil) @left = left.to_f @bottom = bottom.to_f @width = width.to_f @height = height.to_f @shape = shape || default_shape end |
Instance Attribute Details
#bottom ⇒ Object (readonly)
Returns the value of attribute bottom.
13 14 15 |
# File 'lib/pdfrb/layout/frame.rb', line 13 def bottom @bottom end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
13 14 15 |
# File 'lib/pdfrb/layout/frame.rb', line 13 def height @height end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
13 14 15 |
# File 'lib/pdfrb/layout/frame.rb', line 13 def left @left end |
#shape ⇒ Object (readonly)
Returns the value of attribute shape.
13 14 15 |
# File 'lib/pdfrb/layout/frame.rb', line 13 def shape @shape end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
13 14 15 |
# File 'lib/pdfrb/layout/frame.rb', line 13 def width @width end |
Instance Method Details
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/pdfrb/layout/frame.rb', line 56 def empty? !full? end |
#find_available_area(width, height) ⇒ Object
Locate the next free area of (width × height) within this Frame.
Returns nil if none fits. After a successful find, callers
typically call remove_area with the returned rectangle to
mark it as used.
35 36 37 38 39 40 41 |
# File 'lib/pdfrb/layout/frame.rb', line 35 def find_available_area(width, height) w = width.to_f h = height.to_f return nil if w > @width || h > @height [@left, @bottom + @height - h] end |
#full? ⇒ Boolean
52 53 54 |
# File 'lib/pdfrb/layout/frame.rb', line 52 def full? @removed&.any? end |
#remove_area(x, y, w, h) ⇒ Object
Mark the rectangle at (x, y) of (w × h) as filled. Subsequent
find_available_area calls avoid this region.
45 46 47 48 49 50 |
# File 'lib/pdfrb/layout/frame.rb', line 45 def remove_area(x, y, w, h) return if x.nil? || y.nil? @removed ||= [] @removed << [x.to_f, y.to_f, w.to_f, h.to_f] end |
#right ⇒ Object
23 24 25 |
# File 'lib/pdfrb/layout/frame.rb', line 23 def right @left + @width end |
#top ⇒ Object
27 28 29 |
# File 'lib/pdfrb/layout/frame.rb', line 27 def top @bottom + @height end |