mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09: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:
parent
a391ea3da3
commit
b823f3d29f
Notes:
sideshowbarker
2024-07-16 23:51:45 +09:00
Author: https://github.com/trflynn89
Commit: b823f3d29f
Pull-request: https://github.com/SerenityOS/serenity/pull/17558
3 changed files with 13 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue