Skip to content

Commit

Permalink
TextLayout: Fix ignored AttributedText::getLineSpacing() parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
szarvas committed Jul 22, 2024
1 parent 5de96da commit 04d9d36
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions modules/juce_graphics/fonts/juce_JustifiedText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions modules/juce_graphics/fonts/juce_SimpleShapedText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,23 @@ class ShapedTextOptions
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);
Expand Down Expand Up @@ -115,6 +127,7 @@ class ShapedTextOptions
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; }
Expand All @@ -130,6 +143,7 @@ class ShapedTextOptions
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<int64>::max();
Expand Down
3 changes: 2 additions & 1 deletion modules/juce_graphics/fonts/juce_TextLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 04d9d36

Please sign in to comment.