mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Fix SimpleShapedText::getTextRange() when the input text contains hard breaks
The issue prior to this commit would be observable when using the
GlyphArrangement functions e.g. addFittedText.
This is a fix for a regression introduced in
9223805b9c.
This commit is contained in:
parent
633777e005
commit
9dd8a2af13
1 changed files with 63 additions and 1 deletions
|
|
@ -1398,7 +1398,10 @@ void SimpleShapedText::shape (const String& data,
|
|||
|
||||
const auto end = (int64) glyphsInVisualOrder.size();
|
||||
|
||||
glyphLookup.set<MergeEqualItems::no> (s.textRange, { { start, end }, ltr });
|
||||
for (auto i = start; i < end; ++i)
|
||||
glyphsInVisualOrder[(size_t) i].cluster += lineRange.getStart();
|
||||
|
||||
glyphLookup.set<MergeEqualItems::no> (s.textRange + lineRange.getStart(), { { start, end }, ltr });
|
||||
resolvedFonts.set ({ start, end }, s.font);
|
||||
}
|
||||
|
||||
|
|
@ -1471,4 +1474,63 @@ Range<int64> SimpleShapedText::getTextRange (int64 glyphIndex) const
|
|||
return Range<int64>::withStartAndLength (cluster, std::max ((int64) 1, nextAdjacentCluster - cluster));
|
||||
}
|
||||
|
||||
#if JUCE_UNIT_TESTS
|
||||
|
||||
struct SimpleShapedTextTests : public UnitTest
|
||||
{
|
||||
SimpleShapedTextTests()
|
||||
: UnitTest ("SimpleShapedText", UnitTestCategories::text)
|
||||
{
|
||||
}
|
||||
|
||||
static constexpr const char* testStrings[]
|
||||
{
|
||||
"Some trivial text",
|
||||
"Text with \r\n\r\n line feed and new line characters",
|
||||
"\nPrepending new line character",
|
||||
"\n\nMultiple prepending new line characters",
|
||||
"\n\nMultiple prepending and trailing line feed or new line characters\n\r\n",
|
||||
"Try right-clicking on a slider for an options menu. \n\nAlso, holding down CTRL while dragging will turn on a slider's velocity-sensitive mode",
|
||||
};
|
||||
|
||||
void runTest (const char* text, float maxWidth)
|
||||
{
|
||||
String testString { text };
|
||||
|
||||
SimpleShapedText st { &testString, ShapedTextOptions{}.withMaxWidth (maxWidth) };
|
||||
|
||||
auto success = true;
|
||||
|
||||
for (int64 glyphIndex = 0; glyphIndex < st.getNumGlyphs(); ++glyphIndex)
|
||||
{
|
||||
const auto textRange = st.getTextRange (glyphIndex);
|
||||
|
||||
// This assumption holds for LTR text if no ligatures are used
|
||||
success &= textRange.getStart() == glyphIndex && textRange.getLength() == 1;
|
||||
}
|
||||
|
||||
expect (success, String { "Failed for test string: " } + testString.replace ("\r", "<CR>")
|
||||
.replace ("\n", "<LF>"));
|
||||
}
|
||||
|
||||
void runTest() override
|
||||
{
|
||||
beginTest ("getTextRange: LTR Latin text without ligatures - no soft breaks");
|
||||
{
|
||||
for (auto* testString : testStrings)
|
||||
runTest (testString, 100'000.0f);
|
||||
}
|
||||
|
||||
beginTest ("getTextRange: LTR Latin text without ligatures - with soft breaks");
|
||||
{
|
||||
for (auto* testString : testStrings)
|
||||
runTest (testString, 60.0f);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static SimpleShapedTextTests simpleShapedTextTests;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace juce
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue