Module: Thinreports::SectionReport::Renderer::SectionHeight
- Included in:
- SectionRenderer, StackViewRowRenderer
- Defined in:
- lib/thinreports/section_report/pdf/renderer/section_height.rb
Defined Under Namespace
Classes: LayoutInfo
Instance Method Summary collapse
- #calc_float_content_bottom(section) ⇒ Object
- #calc_text_block_height(shape) ⇒ Object
- #image_block_layout(section, shape) ⇒ Object
- #item_layout(section, shape) ⇒ Object
- #section_height(section) ⇒ Object
- #stack_view_layout(section, shape) ⇒ Object
- #static_layout(section, shape, y, height) ⇒ Object
- #text_layout(section, shape) ⇒ Object
Instance Method Details
#calc_float_content_bottom(section) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/thinreports/section_report/pdf/renderer/section_height.rb', line 25 def calc_float_content_bottom(section) item_layouts = section.items.map { |item| item_layout(section, item.internal) }.compact item_layouts .map { |l| l.top_margin + l.content_height } .max.to_f end |
#calc_text_block_height(shape) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/thinreports/section_report/pdf/renderer/section_height.rb', line 68 def calc_text_block_height(shape) height = 0 pdf.draw_shape_tblock(shape) do |array, | = .merge(at: [0, 10_000], height: 10_000) height = pdf.pdf.height_of_formatted(array, ) end height end |
#image_block_layout(section, shape) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/thinreports/section_report/pdf/renderer/section_height.rb', line 56 def image_block_layout(section, shape) y, height = shape.format.attributes.values_at('y', 'height') if shape.style.finalized_styles['position-y'] == 'top' dimensions = pdf.shape_iblock_dimenions(shape) content_height = dimensions ? dimensions[1] : 0 LayoutInfo.new(shape, content_height, y, section.schema.height - height - y) else static_layout(section, shape, y, height) end end |
#item_layout(section, shape) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/thinreports/section_report/pdf/renderer/section_height.rb', line 32 def item_layout(section, shape) if shape.type_of?(Core::Shape::TextBlock::TYPE_NAME) text_layout(section, shape) elsif shape.type_of?(Core::Shape::StackView::TYPE_NAME) stack_view_layout(section, shape) elsif shape.type_of?(Core::Shape::ImageBlock::TYPE_NAME) image_block_layout(section, shape) elsif shape.type_of?('ellipse') cy, ry = shape.format.attributes.values_at('cy', 'ry') static_layout(section, shape, cy - ry, ry * 2) elsif shape.type_of?('line') y1, y2 = shape.format.attributes.values_at('y1', 'y2') static_layout(section, shape, [y1, y2].min, (y2 - y1).abs) else y, height = shape.format.attributes.values_at('y', 'height') raise ArgumentError.new("Unknown layout for #{shape}") if height == nil || y == nil static_layout(section, shape, y, height) end end |
#section_height(section) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/thinreports/section_report/pdf/renderer/section_height.rb', line 9 def section_height(section) return [section.min_height || 0, section.schema.height].max if !section.schema.auto_stretch? || section.items.empty? item_layouts = section.items.map { |item| item_layout(section, item.internal) }.compact min_bottom_margin = item_layouts.each_with_object([]) do |l, margins| margins << l.bottom_margin if l.shape.format.affect_bottom_margin? end.min.to_f max_content_bottom = item_layouts.each_with_object([]) do |l, bottoms| bottoms << l.top_margin + l.content_height if l.shape.format.affect_bottom_margin? end.max.to_f [section.min_height || 0, max_content_bottom + min_bottom_margin].max end |
#stack_view_layout(section, shape) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/thinreports/section_report/pdf/renderer/section_height.rb', line 90 def stack_view_layout(section, shape) schema_height = 0 shape.format.rows.each {|row| schema_height += row.attributes['height']} y = shape.format.attributes['y'] LayoutInfo.new(shape, stack_view_renderer.section_height(shape), y, section.schema.height - schema_height - y) end |
#static_layout(section, shape, y, height) ⇒ Object
52 53 54 |
# File 'lib/thinreports/section_report/pdf/renderer/section_height.rb', line 52 def static_layout(section, shape, y, height) LayoutInfo.new(shape, height, y, section.schema.height - height - y) end |
#text_layout(section, shape) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/thinreports/section_report/pdf/renderer/section_height.rb', line 78 def text_layout(section, shape) y, schema_height = shape.format.attributes.values_at('y', 'height') content_height = if shape.style.finalized_styles['overflow'] == 'expand' [schema_height, calc_text_block_height(shape)].max else schema_height end LayoutInfo.new(shape, content_height, y, section.schema.height - schema_height - y) end |