Skip to content

Commit 4ee42e4

Browse files
committed
Remove last word before ellipses when hyphenated
Fix #1305.
1 parent ece5f06 commit 4ee42e4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

weasyprint/text.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,17 @@ def show_first_line(context, textbox, text_overflow, block_ellipsis):
12561256
else:
12571257
assert block_ellipsis[0] == 'string'
12581258
ellipsis = block_ellipsis[1]
1259-
textbox.pango_layout.set_text(textbox.pango_layout.text + ellipsis)
1259+
1260+
# Remove last word if hyphenated
1261+
new_text = textbox.pango_layout.text
1262+
if new_text.endswith(textbox.style['hyphenate_character']):
1263+
last_word_end = get_last_word_end(
1264+
new_text[:-len(textbox.style['hyphenate_character'])],
1265+
textbox.style['lang'])
1266+
if last_word_end:
1267+
new_text = new_text[:last_word_end]
1268+
1269+
textbox.pango_layout.set_text(new_text + ellipsis)
12601270

12611271
first_line, second_line = textbox.pango_layout.get_first_line()
12621272

0 commit comments

Comments
 (0)