diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-02-22 12:08:44 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-24 20:28:23 +0100 |
commit | 8d0b0fbdd380571fb16405c465a85336d7580864 (patch) | |
tree | 378dfb1b756f99ab78c4b4c40307b5dd3b8d4a99 | |
parent | 3d7b13ac03cf5486c1d0244596f53c6680bac6c9 (diff) | |
download | serenity-8d0b0fbdd380571fb16405c465a85336d7580864.zip |
LibWeb: Make text fragment indexing handle multi-code point glyphs
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp index 584e415d3a..481473c894 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -58,11 +58,15 @@ int LineBoxFragment::text_index_at(CSSPixels x) const CSSPixels width_so_far = 0; for (auto it = view.begin(); it != view.end(); ++it) { - CSSPixels glyph_width = font.glyph_or_emoji_width(*it); + auto previous_it = it; + CSSPixels glyph_width = font.glyph_or_emoji_width(it); + if ((width_so_far + (glyph_width + glyph_spacing) / 2) > relative_x) - return m_start + view.byte_offset_of(it); + return m_start + view.byte_offset_of(previous_it); + width_so_far += glyph_width + glyph_spacing; } + return m_start + m_length; } |