1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:57:42 +00:00

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.
This commit is contained in:
Timothy Flynn 2023-02-20 13:15:06 -05:00 committed by Andreas Kling
parent a391ea3da3
commit b823f3d29f
3 changed files with 13 additions and 8 deletions

View file

@ -171,8 +171,7 @@ DeprecatedString TextLayout::elide_text_from_right(Utf8View text) const
if (ellipsis_width < text_width) {
size_t offset = 0;
for (auto it = text.begin(); !it.done(); ++it) {
auto code_point = *it;
auto glyph_width = m_font.glyph_or_emoji_width(code_point);
auto glyph_width = m_font.glyph_or_emoji_width(it);
// 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,
// we don't have to worry about spacing.