Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indent_paragrahs/no final_gap line spacing bug #1079

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/prawn/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,13 @@ def fill_formatted_text_box(text, options)
@all_text_printed = box.everything_printed?

self.y -= box.height
self.y -= box.line_gap + box.leading if @final_gap

# If there's no remaining_text we don't really want to treat this line
# in a special way, we printed everything we wanted so the special
# single_line logic should not be triggered here.
if @final_gap || (options[:single_line] && !@all_text_printed)
self.y -= box.line_gap + box.leading
end

remaining_text
end
Expand Down
38 changes: 38 additions & 0 deletions spec/prawn/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,44 @@
end
end

describe 'when :final_gap is set to false, there should still be ' \
'a gap between the first line and the rest' do
it 'spaces the first and the second line correctly' do
text = 'hello ' * 30
original_y = pdf.y
# First rendering with no indentation so we know what the correct
# render height should be
pdf.text(text, final_gap: false)
height_with_no_indentation = original_y - pdf.y
y_between_paragraphs = pdf.y
# The indentation size doesn't matter, it's about triggering
# a different path in the code
pdf.text(text, indent_paragraphs: 1, final_gap: false)
height_with_indentation = y_between_paragraphs - pdf.y
expect(height_with_indentation).to be_within(0.0001)
.of(height_with_no_indentation)
end
end

describe 'single line height with no final_gap should not depend on '\
'indentation' do
it 'does not affect the height of a single line' do
text = 'hello'
original_y = pdf.y
# First rendering with no indentation so we know what the correct
# render height should be
pdf.text(text, final_gap: false)
height_with_no_indentation = original_y - pdf.y
y_between_paragraphs = pdf.y
# The indentation size doesn't matter, it's about triggering
# a different path in the code
pdf.text(text, indent_paragraphs: 1, final_gap: false)
height_with_indentation = y_between_paragraphs - pdf.y
expect(height_with_indentation).to be_within(0.0001)
.of(height_with_no_indentation)
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
Loading