From 9ad9c72827b1cbfc408f489a100a3bf5f65a71bf Mon Sep 17 00:00:00 2001 From: Simon Danner Date: Mon, 11 Apr 2022 19:09:22 +0200 Subject: [PATCH] LibGfx: Draw complex emojis correctly Previously draw_text_run only passed a single code point to draw_glyph_or_emoji. This lead e.g. to broken unicode flag support. Improve this by passing along the code_point iterator, so the emoji code can detect the correct emojis and advance it as needed. --- Userland/Libraries/LibGfx/Painter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 0264902af9..3d3730bc2c 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -2323,14 +2323,18 @@ void Painter::draw_text_run(FloatPoint const& baseline_start, Utf8View const& st float space_width = font.glyph_or_emoji_width(' '); u32 last_code_point = 0; - for (auto code_point : string) { + + for (auto code_point_iterator = string.begin(); code_point_iterator != string.end(); ++code_point_iterator) { + auto code_point = *code_point_iterator; if (code_point == ' ') { x += space_width; last_code_point = code_point; continue; } + + // FIXME: this is probably not the real space taken for complex emojis x += font.glyphs_horizontal_kerning(last_code_point, code_point); - draw_glyph_or_emoji({ static_cast(lroundf(x)), y }, code_point, font, color); + draw_glyph_or_emoji({ static_cast(lroundf(x)), y }, code_point_iterator, font, color); x += font.glyph_or_emoji_width(code_point) + font.glyph_spacing(); last_code_point = code_point; }