diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-28 23:51:24 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-28 23:54:10 +0100 |
commit | 13594b7146cc4791625280123a6071805a0be7c3 (patch) | |
tree | 746902dbb741ae3b31865c891dd4957838300101 /Libraries/LibGfx | |
parent | 9af33e2e4b22500ff9fd96fb181a8ac89ad4b3a3 (diff) | |
download | serenity-13594b7146cc4791625280123a6071805a0be7c3.zip |
LibGfx+AK: Make text elision work with multi-byte characters
This was causing WindowServer and Taskbar to crash sometimes when the
stars aligned and we tried cutting off a string ending with "..." right
on top of an emoji. :^)
Diffstat (limited to 'Libraries/LibGfx')
-rw-r--r-- | Libraries/LibGfx/Painter.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index ca96ef068b..70aa7ec77f 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -918,7 +918,8 @@ void draw_text_line(const IntRect& a_rect, const TextType& text, const Font& fon int new_width = font.width("..."); if (new_width < text_width) { size_t offset = 0; - for (auto code_point : text) { + for (auto it = text.begin(); it != text.end(); ++it) { + auto code_point = *it; int glyph_width = font.glyph_or_emoji_width(code_point); // NOTE: Glyph spacing should not be added after the last glyph on the line, // but since we are here because the last glyph does not actually fit on the line, @@ -927,7 +928,7 @@ void draw_text_line(const IntRect& a_rect, const TextType& text, const Font& fon if (width_with_this_glyph_included > rect.width()) break; new_width += glyph_width + glyph_spacing; - offset++; + offset = text.iterator_offset(it); } apply_elision(final_text, elided_text, offset); } |