Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix ColumnBox width under indent()

  • Loading branch information...
commit 390b7c759dc6045759a8894ae1cf752f50e524e9 1 parent 4f25394
@bradediger bradediger authored
Showing with 44 additions and 1 deletion.
  1. +21 −1 lib/prawn/document/column_box.rb
  2. +23 −0 spec/bounding_box_spec.rb
View
22 lib/prawn/document/column_box.rb
@@ -57,7 +57,7 @@ def initialize(document, parent, point, options={}) #:nodoc:
# how long a line of text can be.
#
def width
- super / @columns - @spacer
+ super / @columns - @spacer - @total_left_padding - @total_right_padding
end
# Column width including the spacer.
@@ -89,6 +89,26 @@ def move_past_bottom
end
end
+ # Override the padding functions so as not to split the padding amount
+ # between all columns on the page.
+
+ def add_left_padding(left_padding)
+ @total_left_padding += left_padding
+ @x += left_padding
+ end
+
+ def subtract_left_padding(left_padding)
+ @total_left_padding -= left_padding
+ @x -= left_padding
+ end
+
+ def add_right_padding(right_padding)
+ @total_right_padding += right_padding
+ end
+
+ def subtract_right_padding(right_padding)
+ @total_right_padding -= right_padding
+ end
end
end
end
View
23 spec/bounding_box_spec.rb
@@ -254,6 +254,29 @@
@pdf.bounds.width.should == 200
end
end
+
+ describe "in a ColumnBox" do
+ it "should subtract the given indentation from the available width" do
+ @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width,
+ :height => 200, :columns => 2, :spacer => 20) do
+ width = @pdf.bounds.width
+ @pdf.indent(20) do
+ @pdf.bounds.width.should.be.close(width - 20, 0.01)
+ end
+ end
+ end
+
+ it "should subtract right padding from the available width" do
+ @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width,
+ :height => 200, :columns => 2, :spacer => 20) do
+ width = @pdf.bounds.width
+ @pdf.indent(20, 30) do
+ @pdf.bounds.width.should.be.close(width - 50, 0.01)
+ end
+ end
+ end
+
+ end
end
describe "A canvas" do
Please sign in to comment.
Something went wrong with that request. Please try again.