Permalink
Browse files

Merge branch 'master' of https://github.com/giuseb/prawn

  • Loading branch information...
2 parents 1dab0e5 + bf1cf6a commit c8218f36d91af524490c62898d23a81c11b10c4c @bradediger bradediger committed Dec 9, 2011
Showing with 92 additions and 5 deletions.
  1. +10 −5 lib/prawn/document/column_box.rb
  2. +82 −0 spec/bounding_box_spec.rb
@@ -53,18 +53,23 @@ def initialize(document, parent, point, options={}) #:nodoc:
@current_column = 0
end
- # The column width, not the width of the whole box. Used to calculate
- # how long a line of text can be.
+ # The column width, not the width of the whole box,
+ # before left and/or right padding
+ def bare_column_width
+ (@width - @spacer * (@columns - 1)) / @columns
+ end
+
+ # The column width after padding.
+ # Used to calculate how long a line of text can be.
#
def width
- (super - @spacer * (@columns - 1)) / @columns -
- (@total_left_padding + @total_right_padding)
+ bare_column_width - (@total_left_padding + @total_right_padding)
end
# Column width including the spacer.
#
def width_of_column
- width + @spacer
+ bare_column_width + @spacer
end
# x coordinate of the left edge of the current column
View
@@ -285,6 +285,88 @@
end
end
+ it "should maintain the same left indentation across column breaks" do
+ @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
+ 3.times do |column|
+ x = @pdf.bounds.left_side
+ @pdf.indent(20) do
+ @pdf.bounds.left_side.should == x+20
+ end
+ @pdf.bounds.move_past_bottom
+ end
+ end
+ end
+
+ it "should not change the right margin if only left indentation is requested" do
+ @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
+ 3.times do |column|
+ x = @pdf.bounds.right_side
+ @pdf.indent(20) do
+ @pdf.bounds.right_side.should == x
+ end
+ @pdf.bounds.move_past_bottom
+ end
+ end
+ end
+
+ it "should maintain the same right indentation across columns" do
+ @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
+ 3.times do |column|
+ x = @pdf.bounds.right_side
+ @pdf.indent(20, 10) do
+ @pdf.bounds.right_side.should == x-10
+ end
+ @pdf.bounds.move_past_bottom
+ end
+ end
+ end
+
+ it "should keep the right indentation after nesting indents" do
+ @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
+ 3.times do |column|
+ # I am giving a right indent of 10...
+ @pdf.indent(20, 10) do
+ x = @pdf.bounds.right_side
+ # ...and no right indent here...
+ @pdf.indent(20) do
+ # right indent is inherited from the parent!
+ @pdf.bounds.right_side.should == x
+ end
+ end
+ @pdf.bounds.move_past_bottom
+ end
+ end
+ end
+
+ it "should revert the right indentation if negative indent is given in nested indent" do
+ @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
+ 3.times do |column|
+ x = @pdf.bounds.right_side
+ @pdf.indent(20, 10) do
+ # requesting a negative right-indent of equivalent size...
+ @pdf.indent(20, -10) do
+ # ...resets the right margin to that of the column!
+ @pdf.bounds.right_side.should == x
+ end
+ end
+ @pdf.bounds.move_past_bottom
+ end
+ end
+ end
+
+ it "should reduce the available column width by the sum of all nested indents" do
+ @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
+ 3.times do |column|
+ w = @pdf.bounds.width
+ @pdf.indent(20, 10) do
+ @pdf.indent(20, 10) do
+ @pdf.bounds.width.should == w - 60
+ end
+ end
+ @pdf.bounds.move_past_bottom
+ end
+ end
+ end
end
end

0 comments on commit c8218f3

Please sign in to comment.