summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorSimon Danner <danner.simon@gmail.com>2022-04-11 19:09:22 +0200
committerAndreas Kling <kling@serenityos.org>2022-04-11 21:09:52 +0200
commit9ad9c72827b1cbfc408f489a100a3bf5f65a71bf (patch)
tree2d94c47ec8c6f8debc52686f21a750b77f763428 /Userland
parentf64ff945b2600bf50f9e63720101d6ed2f66b117 (diff)
downloadserenity-9ad9c72827b1cbfc408f489a100a3bf5f65a71bf.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGfx/Painter.cpp8
1 files 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<int>(lroundf(x)), y }, code_point, font, color);
+ draw_glyph_or_emoji({ static_cast<int>(lroundf(x)), y }, code_point_iterator, font, color);
x += font.glyph_or_emoji_width(code_point) + font.glyph_spacing();
last_code_point = code_point;
}