Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ensure natural column width respects colspan

Fixes #323.
  • Loading branch information...
commit f5635ea3ec75f8c7ea65e04806c8ee4b3b945460 1 parent 3d5e557
Brad Ediger bradediger authored

Showing 2 changed files with 29 additions and 1 deletion. Show diff stats Hide diff stats

  1. +10 1 lib/prawn/table/cells.rb
  2. +19 0 spec/table_spec.rb
11 lib/prawn/table/cells.rb
@@ -122,7 +122,16 @@ def style(options={}, &block)
122 122 # Returns the total width of all columns in the selected set.
123 123 #
124 124 def width
125   - aggregate_cell_values(:column, :width_ignoring_span, :max)
  125 + widths = {}
  126 + each do |cell|
  127 + index = cell.column
  128 + per_cell_width = cell.width_ignoring_span.to_f / cell.colspan
  129 + cell.colspan.times do |n|
  130 + widths[cell.column+n] = [widths[cell.column+n], per_cell_width].
  131 + compact.max
  132 + end
  133 + end
  134 + widths.values.inject(0, &:+)
126 135 end
127 136
128 137 # Returns minimum width required to contain cells in the set.
19 spec/table_spec.rb
@@ -1001,6 +1001,25 @@
1001 1001 widths[0].should == widths[1]
1002 1002 end
1003 1003
  1004 + it "honors a large, explicitly set table width" do
  1005 + t = @pdf.table([[{:content => "AAAAAAAAAA", :colspan => 3}],
  1006 + ["A", "B", "C"]],
  1007 + :width => 400)
  1008 +
  1009 + t.column_widths.inject(0) { |sum, w| sum + w }.
  1010 + should.be.close(400, 0.01)
  1011 + end
  1012 +
  1013 + it "honors a small, explicitly set table width" do
  1014 + t = @pdf.table([[{:content => "Lorem ipsum dolor sit amet " * 20,
  1015 + :colspan => 3}],
  1016 + ["A", "B", "C"]],
  1017 + :width => 200)
  1018 +
  1019 + t.column_widths.inject(0) { |sum, w| sum + w }.
  1020 + should.be.close(200, 0.01)
  1021 + end
  1022 +
1004 1023 it "splits natural_content_height between rows in the group" do
1005 1024 t = @pdf.table([[{:content => "foo", :rowspan => 2}]])
1006 1025 heights = t.row_heights

0 comments on commit f5635ea

Please sign in to comment.
Something went wrong with that request. Please try again.