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

Formatted text has wrong leading with one line paragraphs #922

Closed
wants to merge 1 commit into from

Conversation

maerch
Copy link
Contributor

@maerch maerch commented Dec 7, 2015

What's wrong: If you are indenting a paragraph, but have only one line to print, it will be printed by draw_indented_formatted_line completely. Thus, remaining_text is empty, but Prawn tries to print it anyway. The problem is that fill_formatted_text_box is still changing the y value of the document if you specify leading:

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

box.height and box.line_gap are zero for an empty remaining text, but box.leading is not. This causes a wrong leading in your text if you have single line paragraphs.

Example:

require "prawn"

Prawn::Document.generate("too_much_leading.pdf") do
  text_options = {
    indent_paragraphs: 30,
    leading: 20
  }
  text "Hello World!", text_options
  text "Second paragraph on more than one line!"*5, text_options
  text "Third paragraph on more than one line!"*5, text_options
end

Space between the first paragraphs is too large. It should have the same leading as between the second and third paragraph.

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.
@pointlessone
Copy link
Member

@maerch Thank you for your contribution. I've rebased this PR on master and merged it but GitHub didn't pick it up. I will close this PR now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants