mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibWeb: Make text fragment indexing handle multi-code point glyphs
This commit is contained in:
parent
3d7b13ac03
commit
8d0b0fbdd3
1 changed files with 6 additions and 2 deletions
|
@ -58,11 +58,15 @@ int LineBoxFragment::text_index_at(CSSPixels x) const
|
||||||
|
|
||||||
CSSPixels width_so_far = 0;
|
CSSPixels width_so_far = 0;
|
||||||
for (auto it = view.begin(); it != view.end(); ++it) {
|
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)
|
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;
|
width_so_far += glyph_width + glyph_spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_start + m_length;
|
return m_start + m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue