Class: Prawn::Table::Cell
- Inherits:
-
Object
- Object
- Prawn::Table::Cell
- Defined in:
- lib/prawn/table/cell.rb,
lib/prawn/table/cell/text.rb,
lib/prawn/table/cell/image.rb,
lib/prawn/table/cell/in_table.rb,
lib/prawn/table/cell/subtable.rb,
lib/prawn/table/cell/span_dummy.rb
Overview
A Cell is a rectangular area of the page into which content is drawn. It has a framework for sizing itself and adding padding and simple styling. There are several standard Cell subclasses that handle things like text, Tables, and (in the future) stamps, images, and arbitrary content.
Cells are a basic building block for table support (see Prawn::Table).
Please subclass me if you want new content types! I’m designed to be very extensible. See the different standard Cell subclasses in lib/prawn/table/cell/*.rb for a template.
Defined Under Namespace
Modules: InTable Classes: Image, SpanDummy, Subtable, Text
Experimental API collapse
- FPTolerance =
A small amount added to the bounding box width to cover over floating- point errors when round-tripping from content_width to width and back. This does not change cell positioning; it only slightly expands each cell’s bounding box width so that rounding error does not prevent a cell from rendering.
1
Experimental API collapse
-
#background_color ⇒ Object
The background color, if any, for this cell.
-
#border_colors ⇒ Object
readonly
HTML RGB-format (“ccffff”) border colors: [top, right, bottom, left].
-
#border_lines ⇒ Object
readonly
Line style.
-
#border_widths ⇒ Object
readonly
Width, in PDF points, of the cell’s borders: [top, right, bottom, left].
-
#borders ⇒ Object
Specifies which borders to enable.
-
#colspan ⇒ Object
Number of columns this cell spans.
-
#content ⇒ Object
Specifies the content for the cell.
-
#dummy_cells ⇒ Object
readonly
Array of SpanDummy cells (if any) that represent the other cells in this span group.
-
#height ⇒ Object
Returns the cell’s height in points, inclusive of padding.
-
#padding ⇒ Object
Amount of dead space (in PDF points) inside the borders but outside the content.
-
#rowspan ⇒ Object
Number of rows this cell spans.
Experimental API collapse
-
.draw_cells(cells) ⇒ Object
Given an array of pairs [cell, pt], draws each cell at its corresponding pt, making sure all backgrounds are behind all borders and content.
-
.make(pdf, content, options = {}) ⇒ Object
Instantiates a Cell based on the given options.
- .stringify_content?(content) ⇒ Boolean
-
#avg_spanned_min_width ⇒ Object
Min-width of the span divided by the number of columns.
- #border_bottom_color ⇒ Object
- #border_bottom_color=(val) ⇒ Object
- #border_bottom_line ⇒ Object
- #border_bottom_line=(val) ⇒ Object
- #border_bottom_width ⇒ Object
- #border_bottom_width=(val) ⇒ Object
-
#border_color=(color) ⇒ Object
(also: #border_colors=)
Sets border colors on this cell.
- #border_left_color ⇒ Object
- #border_left_color=(val) ⇒ Object
- #border_left_line ⇒ Object
- #border_left_line=(val) ⇒ Object
- #border_left_width ⇒ Object
- #border_left_width=(val) ⇒ Object
-
#border_line=(line) ⇒ Object
(also: #border_lines=)
Sets border line style on this cell.
- #border_right_color ⇒ Object
- #border_right_color=(val) ⇒ Object
- #border_right_line ⇒ Object
- #border_right_line=(val) ⇒ Object
- #border_right_width ⇒ Object
- #border_right_width=(val) ⇒ Object
- #border_top_color ⇒ Object
- #border_top_color=(val) ⇒ Object
- #border_top_line ⇒ Object
- #border_top_line=(val) ⇒ Object
- #border_top_width ⇒ Object
- #border_top_width=(val) ⇒ Object
-
#border_width=(width) ⇒ Object
(also: #border_widths=)
Sets border widths on this cell.
-
#content_height ⇒ Object
Returns the height of the bare content in the cell, excluding padding.
-
#content_width ⇒ Object
Returns the width of the bare content in the cell, excluding padding.
-
#draw(pt = [x, y]) ⇒ Object
Draws the cell onto the document.
-
#draw_background(pt) ⇒ Object
Draws the cell’s background color.
-
#draw_borders(pt) ⇒ Object
Draws borders around the cell.
-
#draw_bounded_content(pt) ⇒ Object
Draws the cell’s content at the point provided.
-
#draw_content ⇒ Object
Draws cell content within the cell’s bounding box.
-
#height_ignoring_span ⇒ Object
Returns the cell’s height in points, inclusive of padding, in its first row only.
-
#initialize(pdf, point, options = {}) ⇒ Cell
constructor
Sets up a cell on the document
pdf
, at the given x/y locationpoint
, with the givenoptions
. -
#max_width ⇒ Object
Maximum width of the entire span group this cell controls.
-
#max_width_ignoring_span ⇒ Object
If provided, the maximum width that this cell can be drawn in, within its column.
-
#min_width ⇒ Object
Minimum width of the entire span group this cell controls.
-
#min_width_ignoring_span ⇒ Object
If provided, the minimum width that this cell in its column will permit.
-
#natural_content_height ⇒ Object
Returns the height this cell would naturally take on, absent constraints.
-
#natural_content_width ⇒ Object
Returns the width this cell would naturally take on, absent other constraints.
- #padding_bottom ⇒ Object
- #padding_bottom=(val) ⇒ Object
- #padding_left ⇒ Object
- #padding_left=(val) ⇒ Object
- #padding_right ⇒ Object
- #padding_right=(val) ⇒ Object
- #padding_top ⇒ Object
- #padding_top=(val) ⇒ Object
- #relative_x ⇒ Object
- #relative_y(offset = 0) ⇒ Object
-
#set_width_constraints ⇒ Object
Sets the cell’s minimum and maximum width.
-
#spanned_content_height ⇒ Object
Height of the entire span group.
-
#spanned_content_width ⇒ Object
Width of the entire span group.
-
#style(options = {}, &block) ⇒ Object
Supports setting multiple properties at once.
-
#width ⇒ Object
Returns the cell’s width in points, inclusive of padding.
-
#width=(w) ⇒ Object
Manually sets the cell’s width, inclusive of padding.
-
#width_ignoring_span ⇒ Object
Returns the width of the cell in its first column alone, ignoring any colspans.
-
#x ⇒ Object
x-position of the cell within the parent bounds.
-
#x=(val) ⇒ Object
Set the x-position of the cell within the parent bounds.
-
#y ⇒ Object
y-position of the cell within the parent bounds.
-
#y=(val) ⇒ Object
Set the y-position of the cell within the parent bounds.
Constructor Details
#initialize(pdf, point, options = {}) ⇒ Cell
Sets up a cell on the document pdf
, at the given x/y location point
, with the given options
. Cell, like Table, follows the “options set accessors” paradigm (see “Options” under the Table documentation), so any cell accessor cell.foo = :bar
can be set by providing the option :foo => :bar
here.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/prawn/table/cell.rb', line 213 def initialize(pdf, point, ={}) @pdf = pdf @point = point # Set defaults; these can be changed by options @padding = [5, 5, 5, 5] @borders = [:top, :bottom, :left, :right] @border_widths = [1] * 4 @border_colors = ['000000'] * 4 @border_lines = [:solid] * 4 @colspan = 1 @rowspan = 1 @dummy_cells = [] style() @initializer_run = true end |
Instance Attribute Details
#background_color ⇒ Object
The background color, if any, for this cell. Specified in HTML RGB format, e.g., “ccffff”. The background is drawn under the whole cell, including any padding.
142 143 144 |
# File 'lib/prawn/table/cell.rb', line 142 def background_color @background_color end |
#border_colors ⇒ Object (readonly)
HTML RGB-format (“ccffff”) border colors: [top, right, bottom, left].
126 127 128 |
# File 'lib/prawn/table/cell.rb', line 126 def border_colors @border_colors end |
#border_lines ⇒ Object (readonly)
Line style
130 131 132 |
# File 'lib/prawn/table/cell.rb', line 130 def border_lines @border_lines end |
#border_widths ⇒ Object (readonly)
Width, in PDF points, of the cell’s borders: [top, right, bottom, left].
122 123 124 |
# File 'lib/prawn/table/cell.rb', line 122 def border_widths @border_widths end |
#borders ⇒ Object
Specifies which borders to enable. Must be an array of zero or more of: [:left, :right, :top, :bottom]
.
118 119 120 |
# File 'lib/prawn/table/cell.rb', line 118 def borders @borders end |
#colspan ⇒ Object
Number of columns this cell spans. Defaults to 1.
146 147 148 |
# File 'lib/prawn/table/cell.rb', line 146 def colspan @colspan end |
#content ⇒ Object
Specifies the content for the cell. Must be a “cellable” object. See the “Data” section of the Prawn::Table documentation for details on cellable objects.
136 137 138 |
# File 'lib/prawn/table/cell.rb', line 136 def content @content end |
#dummy_cells ⇒ Object (readonly)
Array of SpanDummy cells (if any) that represent the other cells in this span group. They know their own width / height, but do not draw anything.
156 157 158 |
# File 'lib/prawn/table/cell.rb', line 156 def dummy_cells @dummy_cells end |
#height ⇒ Object
Returns the cell’s height in points, inclusive of padding. If the cell is the master cell of a rowspan, returns the width of the entire span group.
321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/prawn/table/cell.rb', line 321 def height return height_ignoring_span if @colspan == 1 && @rowspan == 1 # We're in a span group; get the maximum height per row (including the # master cell) and sum each row. row_heights = Hash.new(0) dummy_cells.each do |cell| row_heights[cell.row] = [row_heights[cell.row], cell.height].max end row_heights[row] = [row_heights[row], height_ignoring_span].max row_heights.values.inject(0, &:+) end |
#padding ⇒ Object
Amount of dead space (in PDF points) inside the borders but outside the content. Padding defaults to 5pt.
57 58 59 |
# File 'lib/prawn/table/cell.rb', line 57 def padding @padding end |
#rowspan ⇒ Object
Number of rows this cell spans. Defaults to 1.
150 151 152 |
# File 'lib/prawn/table/cell.rb', line 150 def rowspan @rowspan end |
Class Method Details
.draw_cells(cells) ⇒ Object
Given an array of pairs [cell, pt], draws each cell at its corresponding pt, making sure all backgrounds are behind all borders and content.
416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/prawn/table/cell.rb', line 416 def self.draw_cells(cells) cells.each do |cell, pt| cell.set_width_constraints cell.draw_background(pt) end cells.each do |cell, pt| cell.draw_borders(pt) cell.draw_bounded_content(pt) end end |
.make(pdf, content, options = {}) ⇒ Object
Instantiates a Cell based on the given options. The particular class of cell returned depends on the :content argument. See the Prawn::Table documentation under “Data” for allowable content types.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/prawn/table/cell.rb', line 162 def self.make(pdf, content, ={}) at = .delete(:at) || [0, pdf.cursor] return Cell::Image.new(pdf, at, content) if content.is_a?(Hash) && content[:image] if content.is_a?(Hash) .update(content) content = [:content] end content = content.to_s if stringify_content?(content) [:content] = content case content when Prawn::Table::Cell content when String Cell::Text.new(pdf, at, ) when Prawn::Table Cell::Subtable.new(pdf, at, ) when Array subtable = Prawn::Table.new([:content], pdf, {}) Cell::Subtable.new(pdf, at, .merge(:content => subtable)) else raise Errors::UnrecognizedTableContent end end |
.stringify_content?(content) ⇒ Boolean
190 191 192 193 194 195 196 197 |
# File 'lib/prawn/table/cell.rb', line 190 def self.stringify_content?(content) return true if content.nil? return true if content.kind_of?(Numeric) return true if content.kind_of?(Date) return true if content.kind_of?(Time) false end |
Instance Method Details
#avg_spanned_min_width ⇒ Object
Min-width of the span divided by the number of columns.
83 84 85 |
# File 'lib/prawn/table/cell.rb', line 83 def avg_spanned_min_width min_width.to_f / colspan end |
#border_bottom_color ⇒ Object
573 574 575 |
# File 'lib/prawn/table/cell.rb', line 573 def border_bottom_color @border_colors[2] end |
#border_bottom_color=(val) ⇒ Object
577 578 579 |
# File 'lib/prawn/table/cell.rb', line 577 def border_bottom_color=(val) @border_colors[2] = val end |
#border_bottom_line ⇒ Object
699 700 701 |
# File 'lib/prawn/table/cell.rb', line 699 def border_bottom_line @borders.include?(:bottom) ? @border_lines[2] : 0 end |
#border_bottom_line=(val) ⇒ Object
703 704 705 |
# File 'lib/prawn/table/cell.rb', line 703 def border_bottom_line=(val) @border_lines[2] = val end |
#border_bottom_width ⇒ Object
631 632 633 |
# File 'lib/prawn/table/cell.rb', line 631 def border_bottom_width @borders.include?(:bottom) ? @border_widths[2] : 0 end |
#border_bottom_width=(val) ⇒ Object
635 636 637 |
# File 'lib/prawn/table/cell.rb', line 635 def border_bottom_width=(val) @border_widths[2] = val end |
#border_color=(color) ⇒ Object Also known as: border_colors=
Sets border colors on this cell. The argument can be one of:
-
an integer (sets all colors)
-
a two-element array [vertical, horizontal]
-
a three-element array [top, horizontal, bottom]
-
a four-element array [top, right, bottom, left]
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'lib/prawn/table/cell.rb', line 538 def border_color=(color) @border_colors = case when color.nil? ["000000"] * 4 when String === color # all colors [color, color, color, color] when color.length == 2 # vert, horiz [color[0], color[1], color[0], color[1]] when color.length == 3 # top, horiz, bottom [color[0], color[1], color[2], color[1]] when color.length == 4 # top, right, bottom, left [color[0], color[1], color[2], color[3]] else raise ArgumentError, ":border_color must be a string " + "or an array [v,h] or [t,r,b,l]" end end |
#border_left_color ⇒ Object
581 582 583 |
# File 'lib/prawn/table/cell.rb', line 581 def border_left_color @border_colors[3] end |
#border_left_color=(val) ⇒ Object
585 586 587 |
# File 'lib/prawn/table/cell.rb', line 585 def border_left_color=(val) @border_colors[3] = val end |
#border_left_line ⇒ Object
707 708 709 |
# File 'lib/prawn/table/cell.rb', line 707 def border_left_line @borders.include?(:left) ? @border_lines[3] : 0 end |
#border_left_line=(val) ⇒ Object
711 712 713 |
# File 'lib/prawn/table/cell.rb', line 711 def border_left_line=(val) @border_lines[3] = val end |
#border_left_width ⇒ Object
639 640 641 |
# File 'lib/prawn/table/cell.rb', line 639 def border_left_width @borders.include?(:left) ? @border_widths[3] : 0 end |
#border_left_width=(val) ⇒ Object
643 644 645 |
# File 'lib/prawn/table/cell.rb', line 643 def border_left_width=(val) @border_widths[3] = val end |
#border_line=(line) ⇒ Object Also known as: border_lines=
Sets border line style on this cell. The argument can be one of:
Possible values are: :solid, :dashed, :dotted
-
one value (sets all lines)
-
a two-element array [vertical, horizontal]
-
a three-element array [top, horizontal, bottom]
-
a four-element array [top, right, bottom, left]
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/prawn/table/cell.rb', line 664 def border_line=(line) @border_lines = case when line.nil? [:solid] * 4 when line.length == 1 # all lines [line[0]] * 4 when line.length == 2 [line[0], line[1], line[0], line[1]] when line.length == 3 [line[0], line[1], line[2], line[1]] when line.length == 4 [line[0], line[1], line[2], line[3]] else raise ArgumentError, "border_line must be one of :solid, :dashed, " ":dotted or an array [v,h] or [t,r,b,l]" end end |
#border_right_color ⇒ Object
565 566 567 |
# File 'lib/prawn/table/cell.rb', line 565 def border_right_color @border_colors[1] end |
#border_right_color=(val) ⇒ Object
569 570 571 |
# File 'lib/prawn/table/cell.rb', line 569 def border_right_color=(val) @border_colors[1] = val end |
#border_right_line ⇒ Object
691 692 693 |
# File 'lib/prawn/table/cell.rb', line 691 def border_right_line @borders.include?(:right) ? @border_lines[1] : 0 end |
#border_right_line=(val) ⇒ Object
695 696 697 |
# File 'lib/prawn/table/cell.rb', line 695 def border_right_line=(val) @border_lines[1] = val end |
#border_right_width ⇒ Object
623 624 625 |
# File 'lib/prawn/table/cell.rb', line 623 def border_right_width @borders.include?(:right) ? @border_widths[1] : 0 end |
#border_right_width=(val) ⇒ Object
627 628 629 |
# File 'lib/prawn/table/cell.rb', line 627 def border_right_width=(val) @border_widths[1] = val end |
#border_top_color ⇒ Object
557 558 559 |
# File 'lib/prawn/table/cell.rb', line 557 def border_top_color @border_colors[0] end |
#border_top_color=(val) ⇒ Object
561 562 563 |
# File 'lib/prawn/table/cell.rb', line 561 def border_top_color=(val) @border_colors[0] = val end |
#border_top_line ⇒ Object
683 684 685 |
# File 'lib/prawn/table/cell.rb', line 683 def border_top_line @borders.include?(:top) ? @border_lines[0] : 0 end |
#border_top_line=(val) ⇒ Object
687 688 689 |
# File 'lib/prawn/table/cell.rb', line 687 def border_top_line=(val) @border_lines[0] = val end |
#border_top_width ⇒ Object
615 616 617 |
# File 'lib/prawn/table/cell.rb', line 615 def border_top_width @borders.include?(:top) ? @border_widths[0] : 0 end |
#border_top_width=(val) ⇒ Object
619 620 621 |
# File 'lib/prawn/table/cell.rb', line 619 def border_top_width=(val) @border_widths[0] = val end |
#border_width=(width) ⇒ Object Also known as: border_widths=
Sets border widths on this cell. The argument can be one of:
-
an integer (sets all widths)
-
a two-element array [vertical, horizontal]
-
a three-element array [top, horizontal, bottom]
-
a four-element array [top, right, bottom, left]
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File 'lib/prawn/table/cell.rb', line 596 def border_width=(width) @border_widths = case when width.nil? ["000000"] * 4 when Numeric === width # all widths [width, width, width, width] when width.length == 2 # vert, horiz [width[0], width[1], width[0], width[1]] when width.length == 3 # top, horiz, bottom [width[0], width[1], width[2], width[1]] when width.length == 4 # top, right, bottom, left [width[0], width[1], width[2], width[3]] else raise ArgumentError, ":border_width must be a string " + "or an array [v,h] or [t,r,b,l]" end end |
#content_height ⇒ Object
Returns the height of the bare content in the cell, excluding padding.
336 337 338 339 340 341 342 |
# File 'lib/prawn/table/cell.rb', line 336 def content_height if defined?(@height) && @height # manually set return @height - padding_top - padding_bottom end natural_content_height end |
#content_width ⇒ Object
Returns the width of the bare content in the cell, excluding padding.
286 287 288 289 290 291 292 |
# File 'lib/prawn/table/cell.rb', line 286 def content_width if defined?(@width) && @width # manually set return @width - padding_left - padding_right end natural_content_width end |
#draw(pt = [x, y]) ⇒ Object
Draws the cell onto the document. Pass in a point [x,y] to override the location at which the cell is drawn.
If drawing a group of cells at known positions, look into Cell.draw_cells, which ensures that the backgrounds, borders, and content are all drawn in correct order so as not to overlap.
408 409 410 |
# File 'lib/prawn/table/cell.rb', line 408 def draw(pt=[x, y]) Prawn::Table::Cell.draw_cells([[self, pt]]) end |
#draw_background(pt) ⇒ Object
Draws the cell’s background color.
717 718 719 720 721 722 723 724 |
# File 'lib/prawn/table/cell.rb', line 717 def draw_background(pt) return unless background_color @pdf.mask(:fill_color) do @pdf.fill_color background_color @pdf.fill_rectangle pt, width, height end end |
#draw_borders(pt) ⇒ Object
Draws borders around the cell. Borders are centered on the bounds of the cell outside of any padding, so the caller is responsible for setting appropriate padding to ensure the border does not overlap with cell content.
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 |
# File 'lib/prawn/table/cell.rb', line 731 def draw_borders(pt) x, y = pt @pdf.mask(:line_width, :stroke_color) do @borders.each do |border| idx = {:top => 0, :right => 1, :bottom => 2, :left => 3}[border] border_color = @border_colors[idx] border_width = @border_widths[idx] border_line = @border_lines[idx] next if border_width <= 0 # Left and right borders are drawn one-half border beyond the center # of the corner, so that the corners end up square. from, to = case border when :top [[x, y], [x+width, y]] when :bottom [[x, y-height], [x+width, y-height]] when :left [[x, y + (border_top_width / 2.0)], [x, y - height - (border_bottom_width / 2.0)]] when :right [[x+width, y + (border_top_width / 2.0)], [x+width, y - height - (border_bottom_width / 2.0)]] end case border_line when :dashed @pdf.dash border_width * 4 when :dotted @pdf.dash border_width, :space => border_width * 2 when :solid # normal line style else raise ArgumentError, "border_line must be :solid, :dotted or" + " :dashed" end @pdf.line_width = border_width @pdf.stroke_color = border_color @pdf.stroke_line(from, to) @pdf.undash end end end |
#draw_bounded_content(pt) ⇒ Object
Draws the cell’s content at the point provided.
430 431 432 433 434 435 436 437 438 |
# File 'lib/prawn/table/cell.rb', line 430 def draw_bounded_content(pt) @pdf.float do @pdf.bounding_box([pt[0] + padding_left, pt[1] - padding_top], :width => spanned_content_width + FPTolerance, :height => spanned_content_height + FPTolerance) do draw_content end end end |
#draw_content ⇒ Object
Draws cell content within the cell’s bounding box. Must be implemented in subclasses.
781 782 783 |
# File 'lib/prawn/table/cell.rb', line 781 def draw_content raise NotImplementedError, "subclasses must implement draw_content" end |
#height_ignoring_span ⇒ Object
Returns the cell’s height in points, inclusive of padding, in its first row only.
311 312 313 314 315 |
# File 'lib/prawn/table/cell.rb', line 311 def height_ignoring_span # We can't ||= here because the FP error accumulates on the round-trip # from #content_height. defined?(@height) && @height || (content_height + padding_top + padding_bottom) end |
#max_width ⇒ Object
Maximum width of the entire span group this cell controls.
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/prawn/table/cell.rb', line 97 def max_width return max_width_ignoring_span if @colspan == 1 # Sum the smallest max-width from each column in the group, including # myself. max_widths = Hash.new(0) dummy_cells.each do |cell| max_widths[cell.column] = [max_widths[cell.column], cell.max_width].min end max_widths[column] = [max_widths[column], max_width_ignoring_span].min max_widths.values.inject(0, &:+) end |
#max_width_ignoring_span ⇒ Object
If provided, the maximum width that this cell can be drawn in, within its column.
90 91 92 93 |
# File 'lib/prawn/table/cell.rb', line 90 def max_width_ignoring_span set_width_constraints @max_width end |
#min_width ⇒ Object
Minimum width of the entire span group this cell controls.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/prawn/table/cell.rb', line 68 def min_width return min_width_ignoring_span if @colspan == 1 # Sum up the largest min-width from each column, including myself. min_widths = Hash.new(0) dummy_cells.each do |cell| min_widths[cell.column] = [min_widths[cell.column], cell.min_width].max end min_widths[column] = [min_widths[column], min_width_ignoring_span].max min_widths.values.inject(0, &:+) end |
#min_width_ignoring_span ⇒ Object
If provided, the minimum width that this cell in its column will permit.
61 62 63 64 |
# File 'lib/prawn/table/cell.rb', line 61 def min_width_ignoring_span set_width_constraints @min_width end |
#natural_content_height ⇒ Object
Returns the height this cell would naturally take on, absent constraints. Must be implemented in subclasses.
353 354 355 356 |
# File 'lib/prawn/table/cell.rb', line 353 def natural_content_height raise NotImplementedError, "subclasses must implement natural_content_height" end |
#natural_content_width ⇒ Object
Returns the width this cell would naturally take on, absent other constraints. Must be implemented in subclasses.
303 304 305 306 |
# File 'lib/prawn/table/cell.rb', line 303 def natural_content_width raise NotImplementedError, "subclasses must implement natural_content_width" end |
#padding_bottom ⇒ Object
515 516 517 |
# File 'lib/prawn/table/cell.rb', line 515 def padding_bottom @padding[2] end |
#padding_bottom=(val) ⇒ Object
519 520 521 |
# File 'lib/prawn/table/cell.rb', line 519 def padding_bottom=(val) @padding[2] = val end |
#padding_left ⇒ Object
523 524 525 |
# File 'lib/prawn/table/cell.rb', line 523 def padding_left @padding[3] end |
#padding_left=(val) ⇒ Object
527 528 529 |
# File 'lib/prawn/table/cell.rb', line 527 def padding_left=(val) @padding[3] = val end |
#padding_right ⇒ Object
507 508 509 |
# File 'lib/prawn/table/cell.rb', line 507 def padding_right @padding[1] end |
#padding_right=(val) ⇒ Object
511 512 513 |
# File 'lib/prawn/table/cell.rb', line 511 def padding_right=(val) @padding[1] = val end |
#padding_top ⇒ Object
499 500 501 |
# File 'lib/prawn/table/cell.rb', line 499 def padding_top @padding[0] end |
#padding_top=(val) ⇒ Object
503 504 505 |
# File 'lib/prawn/table/cell.rb', line 503 def padding_top=(val) @padding[0] = val end |
#relative_x ⇒ Object
452 453 454 455 456 |
# File 'lib/prawn/table/cell.rb', line 452 def relative_x # Translate coordinates to the bounds we are in, since drawing is # relative to the cursor, not ref_bounds. x + @pdf.bounds.left_side - @pdf.bounds.absolute_left end |
#relative_y(offset = 0) ⇒ Object
470 471 472 |
# File 'lib/prawn/table/cell.rb', line 470 def relative_y(offset = 0) y + offset - @pdf.bounds.absolute_bottom end |
#set_width_constraints ⇒ Object
Sets the cell’s minimum and maximum width. Deferred until requested because padding and size can change.
650 651 652 653 |
# File 'lib/prawn/table/cell.rb', line 650 def set_width_constraints @min_width ||= padding_left + padding_right @max_width ||= @pdf.bounds.width end |
#spanned_content_height ⇒ Object
Height of the entire span group.
346 347 348 |
# File 'lib/prawn/table/cell.rb', line 346 def spanned_content_height height - padding_top - padding_bottom end |
#spanned_content_width ⇒ Object
Width of the entire span group.
296 297 298 |
# File 'lib/prawn/table/cell.rb', line 296 def spanned_content_width width - padding_left - padding_right end |
#style(options = {}, &block) ⇒ Object
Supports setting multiple properties at once.
cell.style(:padding => 0, :border_width => 2)
is the same as:
cell.padding = 0
cell.border_width = 2
241 242 243 244 245 246 247 248 249 |
# File 'lib/prawn/table/cell.rb', line 241 def style(={}, &block) .each do |k, v| send("#{k}=", v) if respond_to?("#{k}=") end # The block form supports running a single block for multiple cells, as # in Cells#style. block.call(self) if block end |
#width ⇒ Object
Returns the cell’s width in points, inclusive of padding. If the cell is the master cell of a colspan, returns the width of the entire span group.
264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/prawn/table/cell.rb', line 264 def width return width_ignoring_span if @colspan == 1 && @rowspan == 1 # We're in a span group; get the maximum width per column (including # the master cell) and sum each column. column_widths = Hash.new(0) dummy_cells.each do |cell| column_widths[cell.column] = [column_widths[cell.column], cell.width].max end column_widths[column] = [column_widths[column], width_ignoring_span].max column_widths.values.inject(0, &:+) end |
#width=(w) ⇒ Object
Manually sets the cell’s width, inclusive of padding.
280 281 282 |
# File 'lib/prawn/table/cell.rb', line 280 def width=(w) @width = @min_width = @max_width = w end |
#width_ignoring_span ⇒ Object
Returns the width of the cell in its first column alone, ignoring any colspans.
254 255 256 257 258 |
# File 'lib/prawn/table/cell.rb', line 254 def width_ignoring_span # We can't ||= here because the FP error accumulates on the round-trip # from #content_width. defined?(@width) && @width || (content_width + padding_left + padding_right) end |
#x ⇒ Object
x-position of the cell within the parent bounds.
442 443 444 |
# File 'lib/prawn/table/cell.rb', line 442 def x @point[0] end |
#x=(val) ⇒ Object
Set the x-position of the cell within the parent bounds.
448 449 450 |
# File 'lib/prawn/table/cell.rb', line 448 def x=(val) @point[0] = val end |
#y ⇒ Object
y-position of the cell within the parent bounds.
460 461 462 |
# File 'lib/prawn/table/cell.rb', line 460 def y @point[1] end |
#y=(val) ⇒ Object
Set the y-position of the cell within the parent bounds.
466 467 468 |
# File 'lib/prawn/table/cell.rb', line 466 def y=(val) @point[1] = val end |