Class: PDFGen::Div
- Inherits:
-
BaseRegion
- Object
- BaseRegion
- PDFGen::Div
- Includes:
- CaptionContainer, Composite, DivContainer, ImageContainer, SpanContainer, TableContainer
- Defined in:
- lib/div.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#count_rendered_region ⇒ Object
Returns the value of attribute count_rendered_region.
-
#horizontal_align ⇒ Object
Returns the value of attribute horizontal_align.
-
#horizontal_interval ⇒ Object
Returns the value of attribute horizontal_interval.
-
#optional_border ⇒ Object
Returns the value of attribute optional_border.
Attributes inherited from BaseRegion
Attributes included from BaseAttributes
#background_color, #border_bottom, #border_color, #border_left, #border_right, #border_style, #border_top, #border_width, #height, #is_breakable, #pad_bottom, #pad_left, #pad_right, #pad_top, #page_pad_top, #width
Instance Method Summary collapse
- #add_border(x, y, x1, y1) ⇒ Object
- #add_border_bottom(x, y) ⇒ Object
-
#add_border_sides(x, y, y_new) ⇒ Object
border left and right.
- #add_border_top(x, y) ⇒ Object
- #add_optional_border(x, y) ⇒ Object
- #calculate_minimal_height ⇒ Object
-
#initialize(parent) ⇒ Div
constructor
A new instance of Div.
- #render(pos, av_height, test = false) ⇒ Object
- #render_regions(pos, av_height, test = false) ⇒ Object
- #reset_count_rendered_regions ⇒ Object
Methods included from Composite
#[], #add_region, #apply_values, #elements, #page_pad_top=, #regions
Methods included from CaptionContainer
Methods included from SpanContainer
Methods included from DivContainer
Methods included from ImageContainer
Methods included from TableContainer
Methods inherited from BaseRegion
#check_fit_in_height, #document, #minimal_height, #set_properties, #value
Methods included from BaseAttributes
#av_width, #border=, #border_params, #breakable?, included, #paddings=, #var_init
Methods included from BaseAttributes::ClassMethods
Constructor Details
#initialize(parent) ⇒ Div
Returns a new instance of Div.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/div.rb', line 17 def initialize parent super @horizontal_interval = 0 @horizontal_align = false @optional_border = false @is_breakable = true @count_rendered_region = 0 @rendered_height = 0 end |
Instance Attribute Details
#count_rendered_region ⇒ Object
Returns the value of attribute count_rendered_region.
29 30 31 |
# File 'lib/div.rb', line 29 def count_rendered_region @count_rendered_region end |
#horizontal_align ⇒ Object
Returns the value of attribute horizontal_align.
28 29 30 |
# File 'lib/div.rb', line 28 def horizontal_align @horizontal_align end |
#horizontal_interval ⇒ Object
Returns the value of attribute horizontal_interval.
28 29 30 |
# File 'lib/div.rb', line 28 def horizontal_interval @horizontal_interval end |
#optional_border ⇒ Object
Returns the value of attribute optional_border.
28 29 30 |
# File 'lib/div.rb', line 28 def optional_border @optional_border end |
Instance Method Details
#add_border(x, y, x1, y1) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/div.rb', line 45 def add_border(x, y, x1, y1) document.pdf.save_state document.pdf.stroke_color! border_color document.pdf.stroke_style! border_params document.pdf.line(x, y, x1, y1).stroke document.pdf.restore_state end |
#add_border_bottom(x, y) ⇒ Object
35 36 37 |
# File 'lib/div.rb', line 35 def add_border_bottom(x, y) add_border(x, y, x + width, y) if border_bottom end |
#add_border_sides(x, y, y_new) ⇒ Object
border left and right
40 41 42 43 |
# File 'lib/div.rb', line 40 def add_border_sides(x, y, y_new) add_border(x, y, x, y_new) if border_left add_border(x + width, y, x + width, y_new) if border_right end |
#add_border_top(x, y) ⇒ Object
31 32 33 |
# File 'lib/div.rb', line 31 def add_border_top(x, y) add_border(x, y, x + width, y) if border_top end |
#add_optional_border(x, y) ⇒ Object
53 54 55 |
# File 'lib/div.rb', line 53 def add_optional_border(x, y) add_border(x, y, x + width, y) end |
#calculate_minimal_height ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/div.rb', line 57 def calculate_minimal_height sum_height = regions.inject(0) do |sum, region| h = region.height h += horizontal_interval unless region == regions.last sum + h end sum_height + pad_top + pad_bottom end |
#render(pos, av_height, test = false) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/div.rb', line 118 def render(pos, av_height, test=false) pos_x, pos_y = pos fill(pos) add_border_top(pos_x, pos_y) if @rendered_height.zero? status = render_regions([pos_x, pos_y], av_height, test) pos_y -= status[0] if (status[1]) bottom = (av_height - self.height) > 0 ? (av_height - self.height) : pos_y add_border_bottom(pos_x, bottom) add_border_sides(pos_x, av_height, bottom) else add_border_sides(pos_x, av_height, 0) end status end |
#render_regions(pos, av_height, test = false) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/div.rb', line 66 def render_regions(pos, av_height, test=false) pos_x, pos_y = pos remain_regions = regions.slice(@count_rendered_region..regions.size) if @count_rendered_region.zero? && @rendered_height.zero? @rendered_height += pad_top pos_y -= pad_top end pos_x += pad_left remain_regions.each do |region| self.fit_width(region) if pos_y >= region.height @count_rendered_region += 1 unless test region_height = region.render([pos_x, pos_y], pos_y, test)[0] @rendered_height += region_height pos_y -= region_height @rendered_height += horizontal_interval unless region == regions.last pos_y -= horizontal_interval unless region == regions.last if region == regions.last pos_y -= pad_bottom @rendered_height += pad_bottom end else if region.breakable? status = region.render([pos_x, pos_y], pos_y, test) @rendered_height += status[0] pos_y -= status[0] @rendered_height += horizontal_interval unless region == regions.last pos_y -= horizontal_interval unless region == regions.last if region == regions.last and status[1] pos_y -= pad_bottom @rendered_height += pad_bottom end return [av_height - pos_y, status[1]] else region.check_fit_in_height return [av_height - pos_y, false] end end end [av_height - pos_y, true] end |
#reset_count_rendered_regions ⇒ Object
144 145 146 |
# File 'lib/div.rb', line 144 def reset_count_rendered_regions @count_rendered_region = 0 end |