From 66320234989bf3cbc8f0e27c991f7644977314d2 Mon Sep 17 00:00:00 2001 From: MacDue Date: Wed, 4 Jan 2023 20:10:00 +0100 Subject: [PATCH] LibGfx: Enable subpixel accurate text rendering in Painter::draw_text() This improves kerning and alignment jittering quite a bit :^) --- Userland/Libraries/LibGfx/Painter.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 27c5e6480b..519ae136e9 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1382,13 +1382,14 @@ FLATTEN void Painter::draw_glyph(FloatPoint point, u32 code_point, Color color) FLATTEN void Painter::draw_glyph(FloatPoint point, u32 code_point, Font const& font, Color color) { - auto glyph = font.glyph(code_point); - auto top_left = point + IntPoint(glyph.left_bearing(), 0); + auto top_left = point + FloatPoint(font.glyph_left_bearing(code_point), 0); + auto glyph_position = Gfx::GlyphRasterPosition::get_nearest_fit_for(top_left); + auto glyph = font.glyph(code_point, glyph_position.subpixel_offset); if (glyph.is_glyph_bitmap()) { draw_bitmap(top_left.to_type(), glyph.glyph_bitmap(), color); } else { - blit_filtered(top_left.to_type(), *glyph.bitmap(), glyph.bitmap()->rect(), [color](Color pixel) -> Color { + blit_filtered(glyph_position.blit_position, *glyph.bitmap(), glyph.bitmap()->rect(), [color](Color pixel) -> Color { return pixel.multiply(color); }); }