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

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

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

Comments

@mkastner
Copy link

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
Copy link
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 as completed Dec 8, 2012
@mkastner
Copy link
Author

mkastner commented Mar 8, 2013

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

benhell commented Mar 10, 2013

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

benhell commented Mar 10, 2013

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
Copy link
Member

@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?

Hello Brad,

I'll have to re-familiarize myself with that code and get back to you.

Best,

Daniel

Thanks!
-be


Reply to this email directly or view it on GitHub.

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

@no-dashes
Copy link

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

@practicingruby
Copy link
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 added a commit to Mario1988/prawn that referenced this issue Sep 26, 2014
@practicingruby
Copy link
Member

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

@no-dashes
Copy link

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

@practicingruby
Copy link
Member

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

@practicingruby
Copy link
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
Development

No branches or pull requests

7 participants