diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-04-01 12:41:38 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-01 12:58:03 +0200 |
commit | ee9a2e07156dc4d62f5a4945bd145794cb14d451 (patch) | |
tree | f8be06755067ee0f4665cad6f3530da2b631918f | |
parent | ae2ec45e789cb02db1b4e227c9c16c495a50f170 (diff) | |
download | serenity-ee9a2e07156dc4d62f5a4945bd145794cb14d451.zip |
LibGfx: Implement font kerning for `Painter::draw_text_run`
-rw-r--r-- | Userland/Libraries/LibGfx/Painter.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 05603ab0f3..ba43b5e861 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -2322,14 +2322,17 @@ void Painter::draw_text_run(FloatPoint const& baseline_start, Utf8View const& st int y = baseline_start.y() - pixel_metrics.ascent; float space_width = font.glyph_or_emoji_width(' '); + u32 last_code_point = 0; for (auto code_point : string) { if (code_point == ' ') { x += space_width; + last_code_point = code_point; continue; } - float advance = font.glyph_or_emoji_width(code_point) + font.glyph_spacing(); - draw_glyph_or_emoji({ (int)roundf(x), y }, code_point, font, color); - x += advance; + x += font.glyphs_horizontal_kerning(last_code_point, code_point); + draw_glyph_or_emoji({ static_cast<int>(lroundf(x)), y }, code_point, font, color); + x += font.glyph_or_emoji_width(code_point) + font.glyph_spacing(); + last_code_point = code_point; } } |