Skip to content

Commit ece5f06

Browse files
committed
Fix last word detection
get_log_attrs indices are for Unicode characters, not for bytes. Related to #1305.
1 parent 142d23d commit ece5f06

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

weasyprint/text.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1267,8 +1267,7 @@ def show_first_line(context, textbox, text_overflow, block_ellipsis):
12671267
textbox.style['lang'])
12681268
if last_word_end is None:
12691269
break
1270-
new_text = utf8_slice(
1271-
textbox.pango_layout.text, slice(0, last_word_end))
1270+
new_text = textbox.pango_layout.text[:last_word_end]
12721271
textbox.pango_layout.set_text(new_text + ellipsis)
12731272
first_line, second_line = textbox.pango_layout.get_first_line()
12741273

@@ -1324,4 +1323,4 @@ def get_last_word_end(text, lang):
13241323
bytestring, log_attrs = get_log_attrs(text, lang)
13251324
for i, attr in enumerate(list(log_attrs)[::-1]):
13261325
if i and attr.is_word_end:
1327-
return len(bytestring) - i
1326+
return len(text) - i

0 commit comments

Comments
 (0)