summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-19 18:32:10 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-19 19:16:22 +0200
commit606c0e16726d20b3e644d3b78eb8d5191dc05781 (patch)
treef178e24aab228be06c5af1f7bdfc004f7b95dbdf
parentd3fcba78b04509019245d8c3a0af05d3e1c6d04c (diff)
downloadserenity-606c0e16726d20b3e644d3b78eb8d5191dc05781.zip
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.
-rw-r--r--Libraries/LibGfx/Painter.cpp5
1 files changed, 5 insertions, 0 deletions
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();