Skip to content

Formatted text has wrong leading with one line paragraphs - #922

Closed
maerch wants to merge 1 commit into
prawnpdf:masterfrom
maerch:master
Closed

Formatted text has wrong leading with one line paragraphs#922
maerch wants to merge 1 commit into
prawnpdf:masterfrom
maerch:master

Conversation

@maerch

@maerch maerch commented Dec 7, 2015

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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