Skip to content

Commit

Permalink
fixed wrapping bug in text boxes with leading
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmike authored and Daniel Nelson committed Apr 2, 2011
1 parent 533261c commit ff03d51
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/prawn/core/text/formatted/wrap.rb
Expand Up @@ -107,7 +107,7 @@ def enough_height_for_this_line?
if @baseline_y == 0
diff = @ascender + @descender
else
diff = @descender + @line_height
diff = @descender + @line_height + @leading
end
required_total_height = @baseline_y.abs + diff
if required_total_height > @height + 0.0001
Expand Down
67 changes: 67 additions & 0 deletions spec/text_box_spec.rb
Expand Up @@ -522,6 +522,73 @@
end
end

describe "Text::Box with text that fits exactly in the box" do
before(:each) do
create_pdf
@lines = 3
@interlines = @lines - 1
@text = (1..@lines).to_a.join("\n")
@options = {
:width => 162.0,
:height => @pdf.font.ascender + @pdf.font.height * @interlines + @pdf.font.descender,
:document => @pdf
}
end

it "should have the expected height" do
expected_height = @options.delete(:height)
text_box = Prawn::Text::Box.new(@text, @options)
text_box.render
text_box.height.should.be.close(expected_height, 0.0001)
end

it "should print everything" do
text_box = Prawn::Text::Box.new(@text, @options)
text_box.render
text_box.text.should == @text
end

describe "with leading" do
before(:each) do
@options[:leading] = 15
end

it "should not overflow when enough height is added" do
@options[:height] += @options[:leading] * @interlines
text_box = Prawn::Text::Box.new(@text, @options)
text_box.render
text_box.text.should == @text
end

it "should overflow when insufficient height is added" do
@options[:height] += @options[:leading] * @interlines - 1
text_box = Prawn::Text::Box.new(@text, @options)
text_box.render
text_box.text.should.not == @text
end
end

describe "with negative leading" do
before(:each) do
@options[:leading] = -4
end

it "should not overflow when enough height is removed" do
@options[:height] += @options[:leading] * @interlines
text_box = Prawn::Text::Box.new(@text, @options)
text_box.render
text_box.text.should == @text
end

it "should overflow when too much height is removed" do
@options[:height] += @options[:leading] * @interlines - 1
text_box = Prawn::Text::Box.new(@text, @options)
text_box.render
text_box.text.should.not == @text
end
end
end

describe "Text::Box printing UTF-8 string with higher bit characters" do
before(:each) do
create_pdf
Expand Down

0 comments on commit ff03d51

Please sign in to comment.