diff --git a/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp b/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp index 6965f6e58c..b83285dce1 100644 --- a/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp +++ b/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp @@ -102,6 +102,12 @@ public: return withMember (*this, &ShapedTextOptions::ellipsis, std::move (x)); } + [[nodiscard]] ShapedTextOptions withReadingDirection (std::optional 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 readingDir; std::optional maxWidth; std::optional height; std::vector fontsForRange { { { 0, std::numeric_limits::max() }, @@ -930,7 +937,7 @@ void SimpleShapedText::shape (const String& data, std::vector lineChunks; int64 numGlyphsInLine = 0; - const auto analysis = Unicode::performAnalysis (data); + const auto analysis = Unicode::performAnalysis (data, options.getReadingDirection()); IntegralCanBreakBeforeIterator softBreakIterator { makeSpan (analysis) }; diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index 30442a7a98..166c5a8e27 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -390,6 +390,21 @@ static MaxFontAscentAndDescent getMaxFontAscentAndDescentInEnclosingLine (const return result; } +static std::optional 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 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 lastLineNumber; std::unique_ptr line;