diff --git a/modules/juce_graphics/detail/juce_SimpleShapedText.cpp b/modules/juce_graphics/detail/juce_SimpleShapedText.cpp index b5ceea7b84..5aadd377e9 100644 --- a/modules/juce_graphics/detail/juce_SimpleShapedText.cpp +++ b/modules/juce_graphics/detail/juce_SimpleShapedText.cpp @@ -887,8 +887,8 @@ struct Shaper }); const BidiAlgorithm bidiAlgorithm { string32 }; - const auto bidiParagraph = bidiAlgorithm.createParagraph (0, options.getReadingDirection()); - const auto bidiLine = bidiParagraph.createLine (0, bidiParagraph.getLength()); + const auto bidiParagraph = bidiAlgorithm.createParagraph (options.getReadingDirection()); + const auto bidiLine = bidiParagraph.createLine (bidiParagraph.getLength()); bidiLine.computeVisualOrder (visualOrder); const auto bidiLevels = bidiParagraph.getResolvedLevels(); @@ -1020,6 +1020,14 @@ struct Shaper if (! result.empty()) result.back().setTextRange (result.back().getTextRange().withEnd (startingCluster)); + if ((int64) visualOrder.size() <= start->cluster) + { + // If this assertion is hit, the input string is probably invalid according to the + // Unicode parsing rules. If you know your string is a valid one, please reach out to us. + jassertfalse; + return result; + } + result.push_back ({ glyphsIt->value, Span { start, (size_t) std::distance (start, end) }, { startingCluster, nextSoftBreakBefore }, diff --git a/modules/juce_graphics/unicode/juce_UnicodeBidi.cpp b/modules/juce_graphics/unicode/juce_UnicodeBidi.cpp index a3d5e65c39..eddcbacbe1 100644 --- a/modules/juce_graphics/unicode/juce_UnicodeBidi.cpp +++ b/modules/juce_graphics/unicode/juce_UnicodeBidi.cpp @@ -135,11 +135,6 @@ public: { } - size_t getOffset() const - { - return SBParagraphGetOffset (paragraph.get()); - } - size_t getLength() const { return SBParagraphGetLength (paragraph.get()); @@ -150,12 +145,12 @@ public: return { SBParagraphGetLevelsPtr (paragraph.get()), getLength() }; } - BidiLine createLine (size_t offset, size_t length) const + BidiLine createLine (size_t length) const { - jassert (getOffset() <= offset); + jassert (SBParagraphGetOffset (paragraph.get()) == 0); jassert (length <= getLength()); return BidiLine { ParagraphPtr { SBParagraphRetain (paragraph.get()) }, - BidiLine::LinePtr { SBParagraphCreateLine (paragraph.get(), offset, length) } }; + BidiLine::LinePtr { SBParagraphCreateLine (paragraph.get(), 0, length) } }; } private: @@ -177,9 +172,9 @@ public: return text.size(); } - BidiParagraph createParagraph (size_t offset, std::optional d = {}) const + BidiParagraph createParagraph (std::optional d = {}) const { - BidiParagraph::ParagraphPtr result { SBAlgorithmCreateParagraph (algorithm.get(), offset, text.size() - offset, [&]() -> SBLevel + BidiParagraph::ParagraphPtr result { SBAlgorithmCreateParagraph (algorithm.get(), 0, text.size(), [&]() -> SBLevel { if (! d.has_value()) return SBLevelDefaultLTR; @@ -191,17 +186,6 @@ public: return BidiParagraph { std::move (result) }; } - template - void forEachParagraph (Fn&& callback, std::optional dir = {}) const - { - for (size_t i = 0; i < text.size();) - { - const auto paragraph = createParagraph (i, dir); - callback (paragraph); - i += paragraph.getLength(); - } - } - private: std::vector text; AlgorithmPtr algorithm { [&] @@ -269,8 +253,8 @@ public: chars.push_back (t); BidiAlgorithm algorithm { chars }; - auto paragraph = algorithm.createParagraph (0); - auto line = paragraph.createLine (0, paragraph.getLength()); + auto paragraph = algorithm.createParagraph(); + auto line = paragraph.createLine (paragraph.getLength()); std::vector order; line.computeVisualOrder (order);