mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 01:51:03 +09:00
LibGfx+LibGUI: Support multi code point emojis in text painting :^)
This necessitates switching from passing a single code point to the callback to passing a non-const Utf8CodePointIterator instead. Note that the text selection mechanisms in LibGUI and LibWeb don't handle this properly yet; they still assume that each code point renders as one glyph. Similarly, width calculations for text widths don't either, so a single such an emoji will require space for more than one glyph. It also doesn't work in LibVT's TerminalWidget, where each code point is handled and rendered separately, so LibGfx never gets a chance to check if subsequent code points could result in a combined emoji.
This commit is contained in:
parent
e1eb882b1c
commit
cab032f1ee
Notes:
sideshowbarker
2024-07-17 18:21:00 +09:00
Author: https://github.com/linusg
Commit: cab032f1ee
Pull-request: https://github.com/SerenityOS/serenity/pull/12736
Reviewed-by: https://github.com/davidot ✅
3 changed files with 50 additions and 32 deletions
|
@ -569,9 +569,9 @@ void AbstractView::keydown_event(KeyEvent& event)
|
|||
if (is_searchable()) {
|
||||
if (event.key() == KeyCode::Key_Backspace) {
|
||||
if (!m_highlighted_search.is_null()) {
|
||||
//if (event.modifiers() == Mod_Ctrl) {
|
||||
// TODO: delete last word
|
||||
//}
|
||||
// if (event.modifiers() == Mod_Ctrl) {
|
||||
// TODO: delete last word
|
||||
// }
|
||||
Utf8View view(m_highlighted_search);
|
||||
size_t n_code_points = view.length();
|
||||
if (n_code_points > 1) {
|
||||
|
@ -704,7 +704,7 @@ void AbstractView::draw_item_text(Gfx::Painter& painter, ModelIndex const& index
|
|||
|
||||
// Highlight the text background first
|
||||
auto background_searching_length = searching_length;
|
||||
painter.draw_text([&](Gfx::IntRect const& rect, u32) {
|
||||
painter.draw_text([&](Gfx::IntRect const& rect, Utf8CodePointIterator&) {
|
||||
if (background_searching_length > 0) {
|
||||
background_searching_length--;
|
||||
painter.fill_rect(rect.inflated(0, 2), palette().highlight_searching());
|
||||
|
@ -716,12 +716,12 @@ void AbstractView::draw_item_text(Gfx::Painter& painter, ModelIndex const& index
|
|||
auto text_searching_length = searching_length;
|
||||
auto highlight_text_color = palette().highlight_searching_text();
|
||||
searching_length = searching_text.length();
|
||||
painter.draw_text([&](Gfx::IntRect const& rect, u32 code_point) {
|
||||
painter.draw_text([&](Gfx::IntRect const& rect, Utf8CodePointIterator& it) {
|
||||
if (text_searching_length > 0) {
|
||||
text_searching_length--;
|
||||
painter.draw_glyph_or_emoji(rect.location(), code_point, font, highlight_text_color);
|
||||
painter.draw_glyph_or_emoji(rect.location(), it, font, highlight_text_color);
|
||||
} else {
|
||||
painter.draw_glyph_or_emoji(rect.location(), code_point, font, text_color);
|
||||
painter.draw_glyph_or_emoji(rect.location(), it, font, text_color);
|
||||
}
|
||||
},
|
||||
text_rect, item_text, font, alignment, elision);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue