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

Problem with soft-hyphens and text-width #775

Closed
Mario1988 opened this Issue Sep 29, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@Mario1988
Contributor

Mario1988 commented Sep 29, 2014

There is another bug with soft_hyphens. Look at these two examples:

    require 'prawn'
    Prawn::Document.generate('test.pdf') do |pdf|
      pdf.formatted_text([{text: "Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}nat#{Prawn::Text::SHY}ion "*10}])
    end
    require 'prawn'
    Prawn::Document.generate('test2.pdf') do |pdf|
      pdf.formatted_text([{text: "Hyphenation " * 6 + "Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}nat#{Prawn::Text::SHY}ion "*4}])
    end

Both of them should produce exactly the same document because the first six words must not be wrapped. Therefore it should not matter if there are soft-hyphens in these words or not.

But in the current version it does matter (In the first version we get a page break at the 7th word, in the second version we get a line break at the 8th word)

During the computation of line wraps the method add_fragment_to_line uses @document.width_of to compute the width of the current fragment.
The problem is that a soft-hyphen changes the result of this computation:
(@document.width_of('Hy') = 14.664 but @document.width_of('Hy\xAD') = 18.66)

Therefore we get lines which are too short.

@practicingruby

This comment has been minimized.

Member

practicingruby commented Oct 1, 2014

Thanks. If you have an idea of how we might go about fixing this, a pull request is welcome.

@practicingruby

This comment has been minimized.

Member

practicingruby commented Oct 5, 2014

@Mario1988: I was able to reproduce.

To restate what you've said, is the underlying issue that we should be computing width_of based on what hyphens will actually appear in the rendered text (if any), but what Prawn currently is doing is computing the width of all soft hyphens in the text, regardless if they are rendered or not?

@Mario1988

This comment has been minimized.

Contributor

Mario1988 commented Oct 6, 2014

Yes, this is correct.
I am not sure how to fix the bug.
Should have a soft hyphen a width unequal to zero or not?
If not the fix should be more or less easy.

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