diff --git a/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp b/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp index d75fff66d7..1953703277 100644 --- a/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp +++ b/modules/juce_graphics/fonts/juce_SimpleShapedText.cpp @@ -1032,6 +1032,8 @@ void SimpleShapedText::shape (const String& data, std::optional bestMatch; + static constexpr auto floatMax = std::numeric_limits::max(); + for (auto breakBefore = softBreakIterator.next(); breakBefore.has_value() && (lineNumbers.size() == 0 || (int64) lineNumbers.size() < options.getMaxNumLines() - 1); @@ -1040,8 +1042,8 @@ void SimpleShapedText::shape (const String& data, if (auto safeAdvance = glyphsToConsume.getAdvanceXUpToBreakPointIfSafe (*breakBefore, options.getTrailingWhitespacesShouldFit())) { - if (safeAdvance->maybeIgnoringWhitespace < remainingWidth || ! bestMatch.has_value()) - bestMatch = BestMatch { *breakBefore, *safeAdvance, false, std::vector {} }; + if (safeAdvance->maybeIgnoringWhitespace < remainingWidth.value_or (floatMax) || ! bestMatch.has_value()) + bestMatch = BestMatch { *breakBefore, *safeAdvance, false, std::vector{} }; else break; // We found a safe break that is too large to fit. Anything beyond // this point would be too large to fit. @@ -1076,7 +1078,7 @@ void SimpleShapedText::shape (const String& data, float {}, [] (auto acc, const auto& elem) { return acc + elem.advance.getX(); }); - if (advance < remainingWidth || ! bestMatch.has_value()) + if (advance < remainingWidth.value_or (floatMax) || ! bestMatch.has_value()) bestMatch = BestMatch { *breakBefore, { advance, advance }, true, std::move (glyphs) }; } } @@ -1120,7 +1122,7 @@ void SimpleShapedText::shape (const String& data, glyphsToConsume.breakBeforeAndConsume (bestMatch->breakBefore); }; - if (bestMatch->advance.maybeIgnoringWhitespace >= remainingWidth) + if (bestMatch->advance.maybeIgnoringWhitespace >= remainingWidth.value_or (floatMax)) { // Even an empty line is too short to fit any of the text if (numGlyphsInLine == 0 && exactlyEqual (remainingWidth, options.getMaxWidth())) diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index 8c27dfd981..5421e7194c 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -417,12 +417,16 @@ void TextLayout::createStandardLayout (const AttributedString& text) colours.set (range, attribute.colour); } - ShapedText shapedText { text.getText(), ShapedTextOptions{}.withFontsForRange (getFontsForRange (fonts)) - .withMaxWidth (width) - .withLanguage (SystemStats::getUserLanguage()) - .withTrailingWhitespacesShouldFit (false) - .withJustification (justification) - .withReadingDirection (getTextDirection (text)) }; + auto shapedTextOptions = ShapedTextOptions{}.withFontsForRange (getFontsForRange (fonts)) + .withLanguage (SystemStats::getUserLanguage()) + .withTrailingWhitespacesShouldFit (false) + .withJustification (justification) + .withReadingDirection (getTextDirection (text)); + + if (text.getWordWrap() != AttributedString::none) + shapedTextOptions = shapedTextOptions.withMaxWidth (width); + + ShapedText shapedText { text.getText(), shapedTextOptions }; std::optional lastLineNumber; std::unique_ptr line;