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:
parent
08f449d2b0
commit
5208b3ffc0
3 changed files with 80 additions and 47 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue