1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 00:21:15 +03:00

Don’t retry to split a line if it contains spaces

Splitting the line twice takes too much time, and we know (hope?) that we can
always split lines after a space.
This commit is contained in:
Guillaume Ayoub 2020-10-26 22:11:29 +01:00
parent bf89df5b67
commit 5497991fb4

View File

@ -1041,9 +1041,9 @@ def split_first_line(text, style, context, max_width, justification_spacing,
# Step #3: Try to put the first word of the second line on the first line
# https://mail.gnome.org/archives/gtk-i18n-list/2013-September/msg00006
# is a good thread related to this problem.
if first_line_width <= max_width:
first_line_text = utf8_slice(text, slice(index))
if first_line_width <= max_width or ' ' in first_line_text.strip():
# The first line may have been cut too early by Pango
first_line_text = utf8_slice(text, slice(index))
second_line_text = utf8_slice(text, slice(index, None))
else:
# We try to know whether the line could have split earlier. We cant
@ -1055,7 +1055,6 @@ def split_first_line(text, style, context, max_width, justification_spacing,
zero_first_line_width, _ = get_size(zero_first_line, style)
if zero_first_line_width < first_line_width:
# The line can be split earlier, it actually fits.
first_line_text = utf8_slice(text, slice(index))
if index is None:
second_line_text = ''
else: