diff --git a/modules/juce_graphics/detail/juce_SimpleShapedText.cpp b/modules/juce_graphics/detail/juce_SimpleShapedText.cpp index a03aecf2fb..becf4c0e1c 100644 --- a/modules/juce_graphics/detail/juce_SimpleShapedText.cpp +++ b/modules/juce_graphics/detail/juce_SimpleShapedText.cpp @@ -210,6 +210,48 @@ static std::vector getHarfbuzzFeatures (Span +static auto incrementCharPtr (CharPtr b, CharPtr e, int64 steps) +{ + while (b != e && steps > 0) + { + ++b; + --steps; + } + + return b; +} + +static std::vector sanitiseString (const String& stringIn, Range lineRange) +{ + std::vector result; + + const auto end = stringIn.end(); + const auto beginOfRange = incrementCharPtr (stringIn.begin(), end, lineRange.getStart()); + const auto endOfRange = incrementCharPtr (beginOfRange, end, lineRange.getLength()); + + result.reserve (beginOfRange.lengthUpTo (endOfRange)); + + for (auto it = beginOfRange; it != endOfRange; ++it) + { + result.push_back (std::invoke ([&] + { + const auto cc = findControlCharacter (it, end); + + if (! cc.has_value()) + return *it; + + constexpr juce_wchar wordJoiner = 0x2060; + constexpr juce_wchar nonBreakingSpace = 0x00a0; + + return cc == ControlCharacter::crFollowedByLf ? wordJoiner : nonBreakingSpace; + })); + } + + return result; +} + /* Returns glyphs in logical order as that favours wrapping. */ static std::vector lowLevelShape (Span string, Range range, @@ -839,48 +881,6 @@ static auto rangedValuesWithOffset (detail::RangedValues rv, int64 offset = 0 return rv; } -/* Increment b by the requested number of steps, or to e, whichever is reached first. */ -template -static auto incrementCharPtr (CharPtr b, CharPtr e, int64 steps) -{ - while (b != e && steps > 0) - { - ++b; - --steps; - } - - return b; -} - -static std::vector sanitiseString (const String& stringIn, Range lineRange) -{ - std::vector result; - - const auto end = stringIn.end(); - const auto beginOfRange = incrementCharPtr (stringIn.begin(), end, lineRange.getStart()); - const auto endOfRange = incrementCharPtr (beginOfRange, end, lineRange.getLength()); - - result.reserve (beginOfRange.lengthUpTo (endOfRange)); - - for (auto it = beginOfRange; it != endOfRange; ++it) - { - result.push_back (std::invoke ([&] - { - const auto cc = findControlCharacter (it, end); - - if (! cc.has_value()) - return *it; - - constexpr juce_wchar wordJoiner = 0x2060; - constexpr juce_wchar nonBreakingSpace = 0x00a0; - - return cc == ControlCharacter::crFollowedByLf ? wordJoiner : nonBreakingSpace; - })); - } - - return result; -} - struct Shaper { Shaper (const String& stringIn, Range lineRange, const ShapedTextOptions& options)