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

Fix AssertionError in layout.inlines.split_text_box(). #410

Merged
merged 1 commit into from
Jan 11, 2017
Merged

Fix AssertionError in layout.inlines.split_text_box(). #410

merged 1 commit into from
Jan 11, 2017

Conversation

natano
Copy link
Contributor

@natano natano commented Jan 11, 2017

Traceback (most recent call last):
  [...]
  File "/app/env/lib/python3.5/site-packages/weasyprint/layout/inlines.py", line 718, in split_text_box
    'Expected nothing or a preserved line break' % (between,))
AssertionError: Got '1,' between two lines. Expected nothing or a preserved line break

The Assertion Error can be triggered with following minimal test case
(Adobe's Source Sans Pro font must be installed):

<style type="text/css">
    p {
	font-family: 'Source Sans Pro';
	font-size: 24pt;
	width: 275pt;
	overflow-wrap: break-word;
    }
</style>
<p>W1D1,W1D7,W2D14,W3D21,W4D28</p>

With the Adobe Source Sans Font the pango line wrapping algorithm
sometimes produces sporadic results. The wrapping seems to be dependent
on the following text, so that a short text doesn't "fit" on a line, but
does if it is followed by more text. This can be worked around in the
split_first_line() function by computing the resume offset at a later
point, so it is in sync with the actual wrapping behaviour.

See https://bugzilla.gnome.org/show_bug.cgi?id=777093.

Traceback (most recent call last):
  [...]
  File "/app/env/lib/python3.5/site-packages/weasyprint/layout/inlines.py", line 718, in split_text_box
    'Expected nothing or a preserved line break' % (between,))
AssertionError: Got '1,' between two lines. Expected nothing or a preserved line break

The Assertion Error can be triggered with following minimal test case
(Adobe's Source Sans Pro font must be installed):

	<style type="text/css">
	    p {
		font-family: 'Source Sans Pro';
		font-size: 24pt;
		width: 275pt;
		overflow-wrap: break-word;
	    }
	</style>
	<p>W1D1,W1D7,W2D14,W3D21,W4D28</p>

With the Adobe Source Sans Font the pango line wrapping algorithm
sometimes produces sporadic results. The wrapping seems to be dependent
on the following text, so that a short text doesn't "fit" on a line, but
does if it is followed by more text. This can be worked around in the
split_first_line() function by computing the resume offset at a later
point, so it is in sync with the actual wrapping behaviour.

See https://bugzilla.gnome.org/show_bug.cgi?id=777093.
@liZe
Copy link
Member

liZe commented Jan 11, 2017

Thanks a lot for reporting this issue!

Your fix is OK. We have to take the final second line index for resume_at because the temporary second line is only split on words (the second one splits on chars, that's how WRAP_WORD_CHAR works).

I think that we can safely use WRAP_CHAR instead of WRAP_WORD_CHAR as we tried to split the line on words boundaries earlier, and avoid a second split. I'll do this in another commit.

@liZe liZe merged commit 5aa34d7 into Kozea:master Jan 11, 2017
liZe added a commit that referenced this pull request Jan 11, 2017
And add some comments to explain why it doesn't work. Related to #410.
@liZe
Copy link
Member

liZe commented Jan 11, 2017

I think that we can safely use WRAP_CHAR instead of WRAP_WORD_CHAR as we tried to split the line on words boundaries earlier, and avoid a second split. I'll do this in another commit.

It doesn't work. I've added some comments about this.

Thanks again!

jsonn referenced this pull request in jsonn/pkgsrc Mar 3, 2017
Version 0.36
------------

Released on 2017-02-25.

New features:

* `#407 <https://github.com/Kozea/WeasyPrint/pull/407>`_:
  Handle ::first-letter.
* `#423 <https://github.com/Kozea/WeasyPrint/pull/423>`_:
  Warn user about broken cairo versions.

Bug fixes:

* `#411 <https://github.com/Kozea/WeasyPrint/pull/411>`_:
  Typos fixed in command-line help.


Version 0.35
------------

Released on 2017-02-25.

Bug fixes:

* `#410 <https://github.com/Kozea/WeasyPrint/pull/410>`_:
  Fix AssertionError in split_text_box.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants