Skip to content

Commit

Permalink
Do not try to print text if no more text is available
Browse files Browse the repository at this point in the history
Since `fill_formatted_text_box` is changing the `y` state of the
document even if you do not print anything (box.leading is subtracted)
calling this will cause a wrong leading for any paragraphs which have
only one single line.
  • Loading branch information
maerch committed Dec 7, 2015
1 parent 8d36954 commit d3dc96b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/prawn/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ def formatted_text(array, options = {})
end
end

remaining_text = fill_formatted_text_box(remaining_text, options)
draw_remaining_formatted_text_on_new_pages(remaining_text, options)
unless @all_text_printed
remaining_text = fill_formatted_text_box(remaining_text, options)
draw_remaining_formatted_text_on_new_pages(remaining_text, options)
end
end
else
remaining_text = fill_formatted_text_box(array, options)
Expand Down
11 changes: 11 additions & 0 deletions spec/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,17 @@
expect(x_positions[3]).to eq(0)
end

describe "when paragraph has only one line, it should not add" \
" additional leading" do
let(:leading) { 100 }

it 'should add leading only once' do
_y = @pdf.y
@pdf.text("hello", indent_paragraphs: 10, leading: leading)
expect(_y - @pdf.y).to be < leading*2
end
end

describe "when wrap to new page, and first line of new page" \
" is not the start of a new paragraph, that line should" \
" not be indented" do
Expand Down

0 comments on commit d3dc96b

Please sign in to comment.