1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

GlyphArrangement: Use portable string trimming

This commit is contained in:
reuk 2025-06-02 21:01:36 +01:00
parent 08f449d2b0
commit 5208b3ffc0
No known key found for this signature in database
3 changed files with 80 additions and 47 deletions

View file

@ -35,12 +35,26 @@
namespace juce
{
static constexpr bool isNonBreakingSpace (const juce_wchar c)
static String portableTrim (String toTrim)
{
return c == 0x00a0
|| c == 0x2007
|| c == 0x202f
|| c == 0x2060;
if (toTrim.isEmpty())
return toTrim;
const auto b = toTrim.begin();
const auto e = toTrim.end();
const auto shouldTrim = [] (auto ptr)
{
return SBCodepointGetBidiType ((SBCodepoint) *ptr) == SBBidiTypeWS;
};
const auto trimmedBegin = CharacterFunctions::trimBegin (b, e, shouldTrim);
const auto trimmedEnd = CharacterFunctions::trimEnd (trimmedBegin, e, shouldTrim);
if (trimmedBegin == b && trimmedEnd == e)
return toTrim;
return String (trimmedBegin, trimmedEnd);
}
static bool areAllRequiredWidthsSmallerThanMax (const detail::ShapedText& shapedText, float width)
@ -268,7 +282,7 @@ static auto createFittedText (const Font& f,
return st;
}
const auto trimmed = text.trim();
const auto trimmed = portableTrim (text);
constexpr auto widthFittingTolerance = 0.01f;