1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

TextEditor: Restore JUCE 7 behaviour for the first line's alignment when line spacing > 1

This commit is contained in:
attila 2025-04-23 12:28:11 +02:00 committed by Attila Szarvas
parent 56b7b7621e
commit 6a53ddcb77
2 changed files with 24 additions and 1 deletions

View file

@ -817,8 +817,24 @@ float TextEditor::getYOffset() const
{
const auto bottomY = getMaximumTextHeight();
const auto juce7LineSpacingOffset = std::invoke ([&]
{
if (approximatelyEqual (lineSpacing, 1.0f) || textStorage->isEmpty())
return 0.0f;
const auto& lineMetrics = textStorage->front().value->getShapedText().getLineMetricsForGlyphRange();
if (lineMetrics.isEmpty())
return 0.0f;
const auto& line = lineMetrics.front().value;
jassert (lineSpacing >= 1.0f);
return line.maxAscent * (1.0f / lineSpacing - 1.0f);
});
if (justification.testFlags (Justification::top) || isTextStorageHeightGreaterEqualThan ((float) bottomY))
return 0;
return juce7LineSpacingOffset;
auto bottom = jmax (0.0f, (float) bottomY - getTextStorageHeight());

View file

@ -202,6 +202,12 @@ public:
bool isEmpty() const { return storage.empty(); }
ParagraphItem front() const
{
jassert (! ranges.isEmpty());
return { ranges.get (0), storage.front() };
}
ParagraphItem back() const
{
jassert (! ranges.isEmpty());
@ -417,6 +423,7 @@ public:
auto end() const { return paragraphs.end(); }
auto isEmpty() const { return paragraphs.isEmpty(); }
auto front() const { return paragraphs.front(); }
auto back() const { return paragraphs.back(); }
std::optional<Font> getLastFont() const