Commit 535ca1fc authored by Ivan Yossi's avatar Ivan Yossi 👌

Fix hang when utf line break is used

Break the loop: if adding an offset to the number of columns doesn't
increase the line length, we break out of the loop to avoid an
infinite loop on loading some files.

Shift + Enter creates an utf break character which breaks
the lenght calculation. Also added a reptition flag to avoid
any other hang if there is a strange symbol.

BUG:410402

ref:kde/krita!128
parent b46a3e6d
......@@ -651,7 +651,7 @@ bool KoSvgTextChunkShape::loadSvg(const KoXmlElement &e, SvgLoadingContext &cont
namespace {
QString cleanUpString(QString text) {
text.replace(QRegExp("[\\r\\n]"), "");
text.replace(QRegExp("[\\r\\n\u2028]"), "");
text.replace(QRegExp(" {2,}"), " ");
return text;
}
......
......@@ -330,6 +330,8 @@ struct LayoutChunkWrapper
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(startPos == m_addedChars, currentTextPos);
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(lastPos < m_layout->text().size(), currentTextPos);
// qDebug() << m_layout->text();
QTextLine line;
std::swap(line, m_danglingLine);
......@@ -351,8 +353,17 @@ struct LayoutChunkWrapper
// grow to avoid missing glyphs
int charOffset = 0;
int noChangeCount = 0;
while (line.textLength() < numChars) {
int tl = line.textLength();
line.setNumColumns(numChars + charOffset);
if (tl == line.textLength()) {
noChangeCount++;
// 5 columns max are needed to discover tab char. Set to 10 to be safe.
if (noChangeCount > 10) break;
} else {
noChangeCount = 0;
}
charOffset++;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment