summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextengine.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-09-04 11:34:01 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-09-04 11:34:01 (GMT)
commit0b8062f5fbd7622a528ce61b767d00fbcdfc74a0 (patch)
treeb6451ec70b23a4d7d6dcdb1c51a7efb5e22719d0 /src/gui/text/qtextengine.cpp
parent1618cbf79921cbeffd99cf5667aa9e3e19d81212 (diff)
downloadQt-0b8062f5fbd7622a528ce61b767d00fbcdfc74a0.zip
Qt-0b8062f5fbd7622a528ce61b767d00fbcdfc74a0.tar.gz
Qt-0b8062f5fbd7622a528ce61b767d00fbcdfc74a0.tar.bz2
Made eliding of arabic text work without chaning the look of the glyphs
Done by Lars
Diffstat (limited to 'src/gui/text/qtextengine.cpp')
-rw-r--r--src/gui/text/qtextengine.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 2b84c6c..ba9145e 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -2245,6 +2245,28 @@ void QTextEngine::indexAdditionalFormats()
}
}
+/* These two helper functions are used to determine whether we need to insert a ZWJ character
+ between the text that gets truncated and the ellipsis. This is important to get
+ correctly shaped results for arabic text.
+*/
+static bool nextCharJoins(const QString &string, int pos)
+{
+ while (pos < string.length() && string.at(pos).category() == QChar::Mark_NonSpacing)
+ ++pos;
+ if (pos == string.length())
+ return false;
+ return string.at(pos).joining() != QChar::OtherJoining;
+}
+
+static bool prevCharJoins(const QString &string, int pos)
+{
+ while (pos > 0 && string.at(pos - 1).category() == QChar::Mark_NonSpacing)
+ --pos;
+ if (pos == 0)
+ return false;
+ return (string.at(pos - 1).joining() == QChar::Dual || string.at(pos - 1).joining() == QChar::Center);
+}
+
QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int flags) const
{
// qDebug() << "elidedText; available width" << width.toReal() << "text width:" << this->width(0, layoutData->string.length()).toReal();
@@ -2345,6 +2367,9 @@ QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int
} while (nextBreak < layoutData->string.length()
&& currentWidth < availableWidth);
+ if (nextCharJoins(layoutData->string, pos))
+ ellipsisText.prepend(QChar(0x200d) /* ZWJ */);
+
return layoutData->string.left(pos) + ellipsisText;
} else if (mode == Qt::ElideLeft) {
QFixed currentWidth;
@@ -2362,6 +2387,9 @@ QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int
} while (nextBreak > 0
&& currentWidth < availableWidth);
+ if (prevCharJoins(layoutData->string, pos))
+ ellipsisText.append(QChar(0x200d) /* ZWJ */);
+
return ellipsisText + layoutData->string.mid(pos);
} else if (mode == Qt::ElideMiddle) {
QFixed leftWidth;
@@ -2391,6 +2419,11 @@ QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int
&& nextRightBreak > 0
&& leftWidth + rightWidth < availableWidth);
+ if (nextCharJoins(layoutData->string, leftPos))
+ ellipsisText.prepend(QChar(0x200d) /* ZWJ */);
+ if (prevCharJoins(layoutData->string, rightPos))
+ ellipsisText.append(QChar(0x200d) /* ZWJ */);
+
return layoutData->string.left(leftPos) + ellipsisText + layoutData->string.mid(rightPos);
}