Class: Pdfrb::Layout::BoxFitter

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

Instance Method Summary collapse

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

#boxesObject (readonly)

Returns the value of attribute boxes.



10
11
12
# File 'lib/pdfrb/layout/box_fitter.rb', line 10

def boxes
  @boxes
end

#frameObject (readonly)

Returns the value of attribute frame.



10
11
12
# File 'lib/pdfrb/layout/box_fitter.rb', line 10

def frame
  @frame
end

#overflowObject (readonly)

Returns the value of attribute overflow.



10
11
12
# File 'lib/pdfrb/layout/box_fitter.rb', line 10

def overflow
  @overflow
end

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

#fitObject



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

Returns:

  • (Boolean)


33
34
35
# File 'lib/pdfrb/layout/box_fitter.rb', line 33

def fit_complete?
  @overflow.empty?
end