1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:57:44 +00:00

LibWeb: Make text fragment indexing handle multi-code point glyphs

This commit is contained in:
Timothy Flynn 2023-02-22 12:08:44 -05:00 committed by Linus Groh
parent 3d7b13ac03
commit 8d0b0fbdd3

View file

@ -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;
}