Class: Arrolio::Flowables::GroupFlowable

Inherits:
Arrolio::Flowable show all
Defined in:
lib/arrolio/flowables/group_flowable.rb

Overview

A keep-together composite: the whole group moves to the next page when it does not fit the remainder (XSL-FO keep-together). Groups taller than a full page split at child boundaries instead of overflowing.

Direct Known Subclasses

FigureFlowable

Instance Attribute Summary collapse

Attributes inherited from Arrolio::Flowable

#style

Instance Method Summary collapse

Methods inherited from Arrolio::Flowable

#keep_together?, #keep_with_next?, #min_keep_height, #page_break_after?, #page_break_before?, #space_after, #space_before, #split

Constructor Details

#initialize(parts, style: Style::Definition.new(keep_together: true)) ⇒ GroupFlowable

Returns a new instance of GroupFlowable.



12
13
14
15
# File 'lib/arrolio/flowables/group_flowable.rb', line 12

def initialize(parts, style: Style::Definition.new(keep_together: true))
  super(style: style)
  @parts = Array(parts)
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



10
11
12
# File 'lib/arrolio/flowables/group_flowable.rb', line 10

def parts
  @parts
end

Instance Method Details

#do_split(width, remaining_height, context = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/arrolio/flowables/group_flowable.rb', line 39

def do_split(width, remaining_height, context = nil)
  head = []
  tail = []
  used = 0.0
  @parts.each do |part|
    part_h = part.height(width, context)
    if used + part_h <= remaining_height || head.empty?
      head << part
      used += part_h
    else
      tail << part
    end
  end
  [self.class.new(head, style: @style),
   tail.empty? ? nil : self.class.new(tail, style: @style)]
end

#emit(x, y, width, context = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/arrolio/flowables/group_flowable.rb', line 21

def emit(x, y, width, context = nil)
  boxes = []
  consumed = 0.0
  cursor = y
  @parts.each do |part|
    part_h = part.height(width, context)
    part_boxes, = part.emit(x, cursor, width, context)
    boxes.concat(part_boxes)
    cursor -= part_h
    consumed += part_h
  end
  [boxes, consumed]
end

#height(width, context = nil) ⇒ Object



17
18
19
# File 'lib/arrolio/flowables/group_flowable.rb', line 17

def height(width, context = nil)
  @parts.sum { |p| p.height(width, context) }
end

#splittable?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/arrolio/flowables/group_flowable.rb', line 35

def splittable?
  true
end