diff --git a/modules/juce_graphics/fonts/juce_JustifiedText.cpp b/modules/juce_graphics/fonts/juce_JustifiedText.cpp index 22cdd7fd7d..6c367a2dc7 100644 --- a/modules/juce_graphics/fonts/juce_JustifiedText.cpp +++ b/modules/juce_graphics/fonts/juce_JustifiedText.cpp @@ -327,7 +327,7 @@ JustifiedText::JustifiedText (const SimpleShapedText& t, const ShapedTextOptions : getCrossAxisStartingAnchor (options.getJustification(), lineInfos, options.getHeight(), - options.getLeading() - 1.0f); + leading); for (const auto [lineIndex, lineInfo] : enumerate (lineInfos)) { @@ -345,7 +345,7 @@ JustifiedText::JustifiedText (const SimpleShapedText& t, const ShapedTextOptions 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); + y += (1.0f + leading) * (maxDescent + nextLineMaxAscent) + options.getAdditiveLineSpacing(); } rangesToDraw.set ({ 0, (int64) shapedText.getGlyphs().size() }, DrawType::normal); diff --git a/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp b/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp index 1953703277..eda8e4d624 100644 --- a/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp +++ b/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp @@ -77,11 +77,23 @@ public: return withMember (*this, &ShapedTextOptions::firstLineIndent, x); } + /* This controls the space between lines using a proportional value, with a default of 1.0, + meaning single line spacing i.e. the descender of the current line + ascender of the next + line. This value is multiplied by the leading provided here. + */ [[nodiscard]] ShapedTextOptions withLeading (float x) const { return withMember (*this, &ShapedTextOptions::leading, x); } + /* This controls the space between lines using an additive absolute value, with a default of 0.0. + This value is added to the spacing between each two lines. + */ + [[nodiscard]] ShapedTextOptions withAdditiveLineSpacing (float x) const + { + return withMember (*this, &ShapedTextOptions::additiveLineSpacing, x); + } + [[nodiscard]] ShapedTextOptions withBaselineAtZero (bool x = true) const { return withMember (*this, &ShapedTextOptions::baselineAtZero, x); @@ -115,6 +127,7 @@ public: const auto& getLanguage() const { return language; } const auto& getFirstLineIndent() const { return firstLineIndent; } const auto& getLeading() const { return leading; } + const auto& getAdditiveLineSpacing() const { return additiveLineSpacing; } const auto& isBaselineAtZero() const { return baselineAtZero; } const auto& getTrailingWhitespacesShouldFit() const { return trailingWhitespacesShouldFit; } const auto& getMaxNumLines() const { return maxNumLines; } @@ -130,6 +143,7 @@ private: String language = SystemStats::getDisplayLanguage(); float firstLineIndent = 0.0f; float leading = 1.0f; + float additiveLineSpacing = 0.0f; bool baselineAtZero = false; bool trailingWhitespacesShouldFit; int64 maxNumLines = std::numeric_limits::max(); diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index 5421e7194c..245e2e9bf7 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -421,7 +421,8 @@ void TextLayout::createStandardLayout (const AttributedString& text) .withLanguage (SystemStats::getUserLanguage()) .withTrailingWhitespacesShouldFit (false) .withJustification (justification) - .withReadingDirection (getTextDirection (text)); + .withReadingDirection (getTextDirection (text)) + .withAdditiveLineSpacing (text.getLineSpacing()); if (text.getWordWrap() != AttributedString::none) shapedTextOptions = shapedTextOptions.withMaxWidth (width);