From 8d446239cc1f27b18f37a07fb8312c25d3b14a34 Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Tue, 20 Feb 2024 21:49:54 +0100 Subject: [PATCH] If the enforced lineheight is less than the regular line height adjust the ascent so the text is properly centered (#14669) --- src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs index d9e6d6486d..6eff737444 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs @@ -1336,6 +1336,13 @@ namespace Avalonia.Media.TextFormatting if (!double.IsNaN(lineHeight) && !MathUtilities.IsZero(lineHeight)) { + if (lineHeight < height) + { + var offset = Math.Max(0, height - lineHeight) / 2; + + ascent += offset; + } + height = lineHeight; }