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

First word breaks unnecessarily at the end of the line #429

Closed
mndzielski opened this issue Jan 14, 2020 · 5 comments
Closed

First word breaks unnecessarily at the end of the line #429

mndzielski opened this issue Jan 14, 2020 · 5 comments

Comments

@mndzielski
Copy link

mndzielski commented Jan 14, 2020

Hi,
I use css word-wrap: break-word; to force long words to break. Unfortunately if at the end of line there is new html element like <b>text ...</b> first word breaks. If there is enough place situation doesn't appear for second word. In third case if I don't use word-wrap b element doesn't break.

HTML code:

<html>
<head>
<style>
.wrap {
	word-wrap: break-word;
}
</style>
</head>
<body>

<div class="wrap">
	1. OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF <b>OpenHTMLtoPDF OpenHTMLtoPDF  OpenHTMLtoPDF OpenHTMLtoPDF</b>
</div><br/>
<div class="wrap">
	2. OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF <b>OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF</b>
</div><br/>
<div>
	3. OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF OpenHTMLtoPDF <b>OpenHTMLtoPDF OpenHTMLtoPDF</b>
</div>
</body>
</html>

and the result:

image

What can I do to fix it?

danfickle added a commit that referenced this issue Jan 25, 2020
Now a long word will not break unless it would not fit on a line by itself.

+ Refactored InlineBoxing::layoutContent to several methods.
+ Added test by @mndzielski from issue.
+ Had to update columns test proof as work on line breaking fixed a previously unnoticed issue in the output.
+ Updated existing break-word test to test all three cases:
  + Normal fitting word.
  + Word too long for current line and would not fit on a line by itself.
  + Word too long for current line but would fit on a line by itself.
+ Added unit tests for new break character mode text breaker.
+ Some code documentation.
@mndzielski
Copy link
Author

Hi @danfickle
I've started to test your changes and I've discovered that there is a significant issue with word-wrap: break-word;.

Code:

<html>
<head>
    <style>
        @page {
            size: 210mm 7cm;
        }
        body {
            border: 1px solid black;
        }
        .wrap {
            word-wrap: break-word;
        }
    </style>
</head>
<body>

<div class="wrap">
   aaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa123456789 bbbbbbbbbbbb ccccccccccc
</div><br/>
<div class="wrap">
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa123456789 bbbbbbbbbbbb ccccccccccc
</div>
</body>
</html>

Previously the result was:
image

And now it is:
image

So now if the first word in the line is too long it not breaks at all (case 2). 😢
If problem is with the second one I think current behavior is better (case 1) 😄

danfickle added a commit that referenced this issue Jan 29, 2020
Take two, with additional tests.
@danfickle
Copy link
Owner

I've committed take 2 on fixing this issue. I think it is more robust. Thanks for taking time to find my bugs!

@mndzielski
Copy link
Author

Hi @danfickle
Now code works better. 😄
I've found another issue unfortunately. I've added to your test issue-429-break-word-extra CSS code:

body { text-align: center; }.

The result is:
image

The bug as well exists with text-align: right and justify .

danfickle added a commit that referenced this issue Feb 1, 2020
I had taken care of breaking itself, but measurement (required for non-left aligned text) was previously forgotten. Now fixed.
@danfickle
Copy link
Owner

Thanks again @mndzielski, I hope take 3 is finally correct!

@danfickle
Copy link
Owner

This feature will be in the next release.

danfickle added a commit that referenced this issue Jun 7, 2020
…w line.

With test to prove that we don't trigger safety valve with lots of unbreakable words. Safety valve should only be triggered if there is still a bug in our code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants