Minor optimizations for QTextEngine
Optimize script assignment, skip calls to QUnicodeTables::script() for the codepoints handled explicitly. Make the helper functions of QTextEngine::elidedText() inlined Merge-request: 1298 Reviewed-by: yoann (cherry picked from commit 857202824e7d6083eeb87fc52d3770f8fd82b559) Change-Id: I1afc6405a800dbc2b5f63a2f98c63e607e3ee255 Reviewed-on: http://codereview.qt.nokia.com/2998 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
This commit is contained in:
parent
3cea6b22a6
commit
4b6fe1bdc8
@ -1532,33 +1532,40 @@ void QTextEngine::itemize() const
|
||||
const ushort *e = uc + length;
|
||||
int lastScript = QUnicodeTables::Common;
|
||||
while (uc < e) {
|
||||
int script = QUnicodeTables::script(*uc);
|
||||
if (script == QUnicodeTables::Inherited)
|
||||
script = lastScript;
|
||||
analysis->flags = QScriptAnalysis::None;
|
||||
if (*uc == QChar::ObjectReplacementCharacter) {
|
||||
switch (*uc) {
|
||||
case QChar::ObjectReplacementCharacter:
|
||||
if (analysis->bidiLevel % 2)
|
||||
--analysis->bidiLevel;
|
||||
analysis->script = QUnicodeTables::Common;
|
||||
analysis->flags = QScriptAnalysis::Object;
|
||||
} else if (*uc == QChar::LineSeparator) {
|
||||
break;
|
||||
case QChar::LineSeparator:
|
||||
if (analysis->bidiLevel % 2)
|
||||
--analysis->bidiLevel;
|
||||
analysis->script = QUnicodeTables::Common;
|
||||
analysis->flags = QScriptAnalysis::LineOrParagraphSeparator;
|
||||
if (option.flags() & QTextOption::ShowLineAndParagraphSeparators)
|
||||
*const_cast<ushort*>(uc) = 0x21B5; // visual line separator
|
||||
} else if (*uc == 9) {
|
||||
break;
|
||||
case 9: // Tab
|
||||
analysis->script = QUnicodeTables::Common;
|
||||
analysis->flags = QScriptAnalysis::Tab;
|
||||
analysis->bidiLevel = control.baseLevel();
|
||||
} else if ((*uc == 32 || *uc == QChar::Nbsp)
|
||||
&& (option.flags() & QTextOption::ShowTabsAndSpaces)) {
|
||||
analysis->script = QUnicodeTables::Common;
|
||||
analysis->flags = QScriptAnalysis::Space;
|
||||
analysis->bidiLevel = control.baseLevel();
|
||||
} else {
|
||||
analysis->script = script;
|
||||
break;
|
||||
case 32: // Space
|
||||
case QChar::Nbsp:
|
||||
if (option.flags() & QTextOption::ShowTabsAndSpaces) {
|
||||
analysis->script = QUnicodeTables::Common;
|
||||
analysis->flags = QScriptAnalysis::Space;
|
||||
analysis->bidiLevel = control.baseLevel();
|
||||
break;
|
||||
}
|
||||
// fall through
|
||||
default:
|
||||
int script = QUnicodeTables::script(*uc);
|
||||
analysis->script = script == QUnicodeTables::Inherited ? lastScript : script;
|
||||
analysis->flags = QScriptAnalysis::None;
|
||||
break;
|
||||
}
|
||||
lastScript = analysis->script;
|
||||
++uc;
|
||||
@ -2432,7 +2439,7 @@ void QTextEngine::indexAdditionalFormats()
|
||||
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)
|
||||
static inline bool nextCharJoins(const QString &string, int pos)
|
||||
{
|
||||
while (pos < string.length() && string.at(pos).category() == QChar::Mark_NonSpacing)
|
||||
++pos;
|
||||
@ -2441,13 +2448,14 @@ static bool nextCharJoins(const QString &string, int pos)
|
||||
return string.at(pos).joining() != QChar::OtherJoining;
|
||||
}
|
||||
|
||||
static bool prevCharJoins(const QString &string, int pos)
|
||||
static inline 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);
|
||||
QChar::Joining joining = string.at(pos - 1).joining();
|
||||
return (joining == QChar::Dual || joining == QChar::Center);
|
||||
}
|
||||
|
||||
QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int flags) const
|
||||
|
Loading…
Reference in New Issue
Block a user