Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

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:https://invent.kde.org/kde/krita/merge_requests/128
parent b46a3e6d
...@@ -651,7 +651,7 @@ bool KoSvgTextChunkShape::loadSvg(const KoXmlElement &e, SvgLoadingContext &cont ...@@ -651,7 +651,7 @@ bool KoSvgTextChunkShape::loadSvg(const KoXmlElement &e, SvgLoadingContext &cont
namespace { namespace {
QString cleanUpString(QString text) { QString cleanUpString(QString text) {
text.replace(QRegExp("[\\r\\n]"), ""); text.replace(QRegExp("[\\r\\n\u2028]"), "");
text.replace(QRegExp(" {2,}"), " "); text.replace(QRegExp(" {2,}"), " ");
return text; return text;
} }
......
...@@ -330,6 +330,8 @@ struct LayoutChunkWrapper ...@@ -330,6 +330,8 @@ struct LayoutChunkWrapper
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(startPos == m_addedChars, currentTextPos); KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(startPos == m_addedChars, currentTextPos);
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(lastPos < m_layout->text().size(), currentTextPos); KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(lastPos < m_layout->text().size(), currentTextPos);
// qDebug() << m_layout->text();
QTextLine line; QTextLine line;
std::swap(line, m_danglingLine); std::swap(line, m_danglingLine);
...@@ -351,8 +353,17 @@ struct LayoutChunkWrapper ...@@ -351,8 +353,17 @@ struct LayoutChunkWrapper
// grow to avoid missing glyphs // grow to avoid missing glyphs
int charOffset = 0; int charOffset = 0;
int noChangeCount = 0;
while (line.textLength() < numChars) { while (line.textLength() < numChars) {
int tl = line.textLength();
line.setNumColumns(numChars + charOffset); 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++; 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