mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-07 04:10:08 +00:00
TextLayout: Respect the ReadingDirection parameter of AttributedString
This commit is contained in:
parent
03e79f8f12
commit
38f299a054
2 changed files with 25 additions and 2 deletions
|
|
@ -102,6 +102,12 @@ public:
|
|||
return withMember (*this, &ShapedTextOptions::ellipsis, std::move (x));
|
||||
}
|
||||
|
||||
[[nodiscard]] ShapedTextOptions withReadingDirection (std::optional<TextDirection> x) const
|
||||
{
|
||||
return withMember (*this, &ShapedTextOptions::readingDir, x);
|
||||
}
|
||||
|
||||
const auto& getReadingDirection() const { return readingDir; }
|
||||
const auto& getJustification() const { return justification; }
|
||||
const auto& getMaxWidth() const { return maxWidth; }
|
||||
const auto& getHeight() const { return height; }
|
||||
|
|
@ -116,6 +122,7 @@ public:
|
|||
|
||||
private:
|
||||
Justification justification { Justification::topLeft };
|
||||
std::optional<TextDirection> readingDir;
|
||||
std::optional<float> maxWidth;
|
||||
std::optional<float> height;
|
||||
std::vector<FontForRange> fontsForRange { { { 0, std::numeric_limits<int64>::max() },
|
||||
|
|
@ -930,7 +937,7 @@ void SimpleShapedText::shape (const String& data,
|
|||
std::vector<LineChunkInLogicalOrder> lineChunks;
|
||||
int64 numGlyphsInLine = 0;
|
||||
|
||||
const auto analysis = Unicode::performAnalysis (data);
|
||||
const auto analysis = Unicode::performAnalysis (data, options.getReadingDirection());
|
||||
|
||||
IntegralCanBreakBeforeIterator softBreakIterator { makeSpan (analysis) };
|
||||
|
||||
|
|
|
|||
|
|
@ -390,6 +390,21 @@ static MaxFontAscentAndDescent getMaxFontAscentAndDescentInEnclosingLine (const
|
|||
return result;
|
||||
}
|
||||
|
||||
static std::optional<TextDirection> getTextDirection (const AttributedString& text)
|
||||
{
|
||||
using ReadingDirection = AttributedString::ReadingDirection;
|
||||
|
||||
const auto dir = text.getReadingDirection();
|
||||
|
||||
if (dir == ReadingDirection::leftToRight)
|
||||
return TextDirection::ltr;
|
||||
|
||||
if (dir == ReadingDirection::rightToLeft)
|
||||
return TextDirection::rtl;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void TextLayout::createStandardLayout (const AttributedString& text)
|
||||
{
|
||||
detail::RangedValues<Font> fonts;
|
||||
|
|
@ -407,7 +422,8 @@ void TextLayout::createStandardLayout (const AttributedString& text)
|
|||
.withMaxWidth (width)
|
||||
.withLanguage (SystemStats::getUserLanguage())
|
||||
.withTrailingWhitespacesShouldFit (false)
|
||||
.withJustification (justification) };
|
||||
.withJustification (justification)
|
||||
.withReadingDirection (getTextDirection (text)) };
|
||||
|
||||
std::optional<int64> lastLineNumber;
|
||||
std::unique_ptr<Line> line;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue