From 7ee2e66881e732f1df98a2aa205ca99c8f36635d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 17 Mar 2025 16:37:15 +0100 Subject: [PATCH] Fix Rich Text Box ascender usage in line breaks for correct images placement #3292 --- .../Engine/UI/GUI/Common/RichTextBox.Parsing.cs | 16 ++-------------- Source/Engine/UI/GUI/TextBlock.cs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs b/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs index 599dcde30..c51557530 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs @@ -233,13 +233,7 @@ namespace FlaxEngine.GUI { ref TextBlock textBlock = ref textBlocks[i]; var textBlockSize = textBlock.Bounds.BottomRight - lineOrigin; - var ascender = textBlock.Ascender; - //if (ascender <= 0) - { - var textBlockFont = textBlock.Style.Font.GetFont(); - if (textBlockFont) - ascender = textBlockFont.Ascender; - } + var ascender = textBlock.GetAscender(); lineAscender = Mathf.Max(lineAscender, ascender); lineSize = Float2.Max(lineSize, textBlockSize); } @@ -256,13 +250,7 @@ namespace FlaxEngine.GUI case TextBlockStyle.Alignments.Baseline: { // Match the baseline of the line (use ascender) - var ascender = textBlock.Ascender; - if (ascender <= 0) - { - var textBlockFont = textBlock.Style.Font.GetFont(); - if (textBlockFont) - ascender = textBlockFont.Ascender; - } + var ascender = textBlock.GetAscender(); vOffset = lineAscender - ascender; textBlock.Bounds.Location.Y += vOffset; break; diff --git a/Source/Engine/UI/GUI/TextBlock.cs b/Source/Engine/UI/GUI/TextBlock.cs index a0a5b246b..ac494d895 100644 --- a/Source/Engine/UI/GUI/TextBlock.cs +++ b/Source/Engine/UI/GUI/TextBlock.cs @@ -31,5 +31,18 @@ namespace FlaxEngine.GUI /// The custom tag. /// public object Tag; + + internal float GetAscender() + { + float ascender = Ascender; + if (Mathf.IsZero(ascender)) + { + // Use ascender from the font + var textBlockFont = Style.Font.GetFont(); + if (textBlockFont) + ascender = textBlockFont.Ascender; + } + return ascender; + } } }