From 606c0e16726d20b3e644d3b78eb8d5191dc05781 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 19 Sep 2020 18:32:10 +0200 Subject: [PATCH] LibGfx: Move vertically centered text down slightly based on baseline To make slightly more aesthetically pleasing use of the vertical space, we now move all vertically centered text lines down by half the amount of space below the font's baseline. This is probably not the "correct" way to do this, but it does make things look nicer with some of our fonts already. --- Libraries/LibGfx/Painter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index 9d14df6de8..b6a044b7be 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -907,6 +907,11 @@ void Painter::draw_text_line(const IntRect& a_rect, const Utf8View& text, const ASSERT_NOT_REACHED(); } + if (is_vertically_centered_text_alignment(alignment)) { + int distance_from_baseline_to_bottom = (font.glyph_height() - 1) - font.baseline(); + rect.move_by(0, distance_from_baseline_to_bottom / 2); + } + auto point = rect.location(); int space_width = font.glyph_width(' ') + font.glyph_spacing();