From aee65c147ecbd2c2121679540303f2c066efd860 Mon Sep 17 00:00:00 2001 From: attila Date: Wed, 8 May 2024 12:49:32 +0200 Subject: [PATCH] JustifiedText: Fix line spacing for multi-font text Prior to this change, the spacing between line N and line N + 1 would be lineHeight (N). This resulted in incorrect spacing when using multiple fonts in a text. This commit uses the correct spacing, which is maxDescent (N) + maxAscent (N + 1). This is also the same rule that was used by TextLayout prior to JUCE 8, and the rule that CoreText's AttributedString features are using as a general rule. Note: lineHeight (N) = maxAscent (N) + maxDescent (N). --- modules/juce_graphics/fonts/juce_JustifiedText.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/juce_graphics/fonts/juce_JustifiedText.cpp b/modules/juce_graphics/fonts/juce_JustifiedText.cpp index 1b6b238a44..7fd8518d56 100644 --- a/modules/juce_graphics/fonts/juce_JustifiedText.cpp +++ b/modules/juce_graphics/fonts/juce_JustifiedText.cpp @@ -342,7 +342,10 @@ JustifiedText::JustifiedText (const SimpleShapedText& t, const ShapedTextOptions whitespaceStretch.set (stretchRange, lineInfo.mainAxisLineAlignment.extraWhitespaceAdvance); - y += (1.0f + leading) * lineInfo.lineHeight; + const auto maxDescent = lineInfo.lineHeight - lineInfo.maxAscent; + const auto nextLineMaxAscent = lineIndex < (int) lineInfos.size() - 1 ? lineInfos[(size_t) lineIndex + 1].maxAscent : 0.0f; + + y += (1.0f + leading) * (maxDescent + nextLineMaxAscent); } rangesToDraw.set ({ 0, (int64) shapedText.getGlyphs().size() }, DrawType::normal);