Hyphenation character rendered in last line of each paragraph of column_box #347

Closed
mkastner opened this Issue Apr 29, 2012 · 13 comments

7 participants

@mkastner

Hi,

it seems like I ran into a problem with hyphenation. If a word in the last line of a paragraph within a column_box contains hyphenation characters, they are being rendered.

Everything regarding hyphenation works fine in any other line but when it comes to the last line of the paragraph, the issue arises.

I've placed a simple example code in this gist, which reproduces the problem (I'm using ruby 1.9.3 on mac and freebsd):

https://gist.github.com/2547562

BTW: thanks for all your great work with prawn!

Michael

@yob
prawnpdf member
yob commented Dec 8, 2012

Thanks for the report Michael.

Just to clarify - are you saying that the hyphens on the final line of the first column aren't being rendered?

I just tested this against prawn master and I can't reproduce it. I'll close the issue for now, but if you're able to provide more information please feel free to re-open it!

@yob yob closed this Dec 8, 2012
@mkastner

Yob,

sorry getting back to your response after such a long time. What I am saying is, that the hyphen character is being rendered, if the hyphenated word is printed in the last line of a column. Obviously, that shouldn't happen.

I've checked on ruby 1.8.7 and 2.0.0 – with prawn 1.0.0 rc1 and prawn 1.0.0 rc2.

Here's my short code to reproduce the problem:

hyphentest.rb

require 'prawn'

class Hyphen < Prawn::Document

  def initialize
    super(:margin => [10,10,10,10], :page_size => 'A4')
    column_box([0, cursor], columns: 2, width: bounds.width) do
      text "This is a test where the very important Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}na#{Prawn::Text::SHY}tion works fine here, but which contains Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}na#{Prawn::Text::SHY}tion\n in the last line of the paragraph Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}na#{Prawn::Text::SHY}ted\n"
      bounds.move_past_bottom
      text "second column"
    end
  end

end

Hyphen.new.render_file('hyphentest.pdf')

hyphentest

@bradediger
prawnpdf member

Thanks @mkastner. Simpler test case reproducing and clarifying the issue:

Prawn::Document.generate('test.pdf') do
  content =  "blah " * 20 + "Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}na#{Prawn::Text::SHY}tion"

  text(content) # hyphenated correctly
  text("#{content}\n") # hyphenated incorrectly
end

Lines ending in \n are triggering hyphenation at every soft-hyphen point, not just the one they are broken on.

From reading the code, this appears to be caused by the fact that :exclude_trailing_white_space is present in the format hash of the correct example, but not in the incorrect one -- because this is explicitly disabled when the line ends in a newline. This causes Prawn::Text::Formatted::Fragment#process_text not to remove the soft hyphens, so they are rendered.

@Bluejade, can you clarify the purpose of :exclude_trailing_white_space? From my reading, it appears to be used to exclude trailing white space from width calculations. What was the reasoning behind process_text skipping soft-hyphen processing on fragments where this option is enabled?

Thanks!
-be

@bradediger bradediger reopened this Mar 8, 2013
@benhell

I don't know if this is a variant of the same problem, but consider the following:

class Hyphen < Prawn::Document
  def initialize
    super
    content =  "blah " * 20 + "Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}na#{Prawn::Text::SHY}tion"
    formatted_text([{text: content}, {text: content}])
  end
end

In this one, the word "Hyphenation" from the first hash incorrectly shows all hyphens, but "Hyphenation" from the second hash does not. I mention it only because this does not involve a carriage return.

@benhell

I suspect it is the same issue. My guess is "exclude_trailing_white_space? only gets set for the last hash in a formatted_text array (probably because trailing whitespace is only an issue at the end of the paragraph). No longer skipping soft-hyphen processing when :exclude_trailing_white_space? is false ought to solve this problem too.

@Bluejade
prawnpdf member
@practicingruby
prawnpdf member

I don't fully understand this issue, but it appears to still exist in 1.0.0 so I'm reopening for further commentary and discussion.

@practicingruby practicingruby added bug-confirmed and removed stale labels Mar 17, 2014
@no-dashes

Is there any hope that this issue may be addressed soonish?

@practicingruby
prawnpdf member

@no-dashes: Sure, investigate, add additional research to the ticket, and optionally a patch. We'll be able to help answer questions about the code if you have any.

@Mario1988 Mario1988 added a commit to Mario1988/prawn that referenced this issue Sep 26, 2014
@Mario1988 Mario1988 spec for issue #347 021a7f6
@practicingruby
prawnpdf member

@no-dashes: Can you try the code on #773 and see if it fixes your problem?

@no-dashes

@sandal: Well... @Mario1988 tried to fix the problem we had with this bug. So yeah, I confirm it fixes the bug for us.

@practicingruby
prawnpdf member

@no-dashes: Great, hopefully we'll get this merged and released soon, then.

@practicingruby
prawnpdf member

I've merged a revised version of @Mario1988's patch in master!

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