diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-02-20 13:15:06 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-22 10:14:36 +0100 |
commit | b823f3d29f746fe49192f862aa50e0b6af2a751a (patch) | |
tree | fbb69d1dc6d1449943b15e851a57890f17c035ab /Userland/Libraries/LibGfx/Font | |
parent | a391ea3da3f555d63e4d6aaffa3ec4d8e664ede1 (diff) | |
download | serenity-b823f3d29f746fe49192f862aa50e0b6af2a751a.zip |
LibGfx: Consider multi-code point glyphs when computing text width
Currently, we compute the width of text one code point at a time. This
ignores grapheme clusters (emoji in particular). One effect of this is
when highlighting a multi-code point emoji. We will errantly increase
the highlight rect to the sum of all code point widths, rather than
just the width of the resolved emoji bitmap.
Diffstat (limited to 'Userland/Libraries/LibGfx/Font')
-rw-r--r-- | Userland/Libraries/LibGfx/Font/BitmapFont.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp index 14e22ed0e3..052db62e0f 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp @@ -357,7 +357,9 @@ ALWAYS_INLINE int BitmapFont::unicode_view_width(T const& view) const int width = 0; int longest_width = 0; - for (u32 code_point : view) { + for (auto it = view.begin(); it != view.end(); ++it) { + auto code_point = *it; + if (code_point == '\n' || code_point == '\r') { first = true; longest_width = max(width, longest_width); @@ -367,8 +369,10 @@ ALWAYS_INLINE int BitmapFont::unicode_view_width(T const& view) const if (!first) width += glyph_spacing(); first = false; - width += glyph_or_emoji_width(code_point); + + width += glyph_or_emoji_width(it); } + longest_width = max(width, longest_width); return longest_width; } |