Class: Pdfrb::Layout::BoxFitter
- Inherits:
-
Object
- Object
- Pdfrb::Layout::BoxFitter
- Defined in:
- lib/pdfrb/layout/box_fitter.rb
Overview
Fits an ordered list of boxes into a Frame, flowing to a new Frame (provided by a block) when one fills up. Delegates area tracking to the Frame (which now properly tracks removed areas and returns non-overlapping positions).
Instance Attribute Summary collapse
-
#boxes ⇒ Object
readonly
Returns the value of attribute boxes.
-
#frame ⇒ Object
readonly
Returns the value of attribute frame.
-
#overflow ⇒ Object
readonly
Returns the value of attribute overflow.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #draw(canvas) ⇒ Object
- #fit ⇒ Object
- #fit_complete? ⇒ Boolean
-
#initialize(boxes:, frame:) ⇒ BoxFitter
constructor
A new instance of BoxFitter.
Constructor Details
#initialize(boxes:, frame:) ⇒ BoxFitter
Returns a new instance of BoxFitter.
12 13 14 15 16 17 |
# File 'lib/pdfrb/layout/box_fitter.rb', line 12 def initialize(boxes:, frame:) @boxes = boxes @frame = frame @result = [] @overflow = [] end |
Instance Attribute Details
#boxes ⇒ Object (readonly)
Returns the value of attribute boxes.
10 11 12 |
# File 'lib/pdfrb/layout/box_fitter.rb', line 10 def boxes @boxes end |
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
10 11 12 |
# File 'lib/pdfrb/layout/box_fitter.rb', line 10 def frame @frame end |
#overflow ⇒ Object (readonly)
Returns the value of attribute overflow.
10 11 12 |
# File 'lib/pdfrb/layout/box_fitter.rb', line 10 def overflow @overflow end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
10 11 12 |
# File 'lib/pdfrb/layout/box_fitter.rb', line 10 def result @result end |
Instance Method Details
#draw(canvas) ⇒ Object
27 28 29 30 31 |
# File 'lib/pdfrb/layout/box_fitter.rb', line 27 def draw(canvas) @result.each do |box, pos| box.draw(canvas, pos[0], pos[1]) end end |
#fit ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/pdfrb/layout/box_fitter.rb', line 19 def fit current_frame = @frame @boxes.each do |box| current_frame = fit_box(box, current_frame) end self end |
#fit_complete? ⇒ Boolean
33 34 35 |
# File 'lib/pdfrb/layout/box_fitter.rb', line 33 def fit_complete? @overflow.empty? end |