summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qtextboundaryfinder.cpp
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2012-08-26 04:09:09 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-22 00:47:40 +0200
commitceb9a8232ca0fe9bc823b61ee3ca8bcdc0aa01c5 (patch)
treed088f6fa8e4025b75ddd034240c74fb987fd7ebe /src/corelib/tools/qtextboundaryfinder.cpp
parented5fe1b95e818101d00e9415d8881ac836c505eb (diff)
A step out from Harfbuzz (reduce dependency)
Introduce QCharAttributes and use it instead of HB_CharAttributes everywhere in Qt (in Harfbuzz, the HB_CharAttributes is only used in the text segmentation algorithm which has been moved from HB to Qt (well, most of it)). Rename some members to better reflect their meaning, remember to keep HB_CharAttributes in sync with QCharAttributes. Also replace HB_ScriptItem with a (temporary) QUnicodeTools::ScriptItem struct that will be replaced with a more efficient/friendly solution a bit later. The soft hyphen and the mandatory break detection has been factored out of the default text breaking algorithm to a higher level in order to refactor the QCharAttributes bitfields and to optimize the implementation for the common case. Change-Id: Ieb365623ae954430f1c8b2dfcd65c82973143eec Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/tools/qtextboundaryfinder.cpp')
-rw-r--r--src/corelib/tools/qtextboundaryfinder.cpp62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/corelib/tools/qtextboundaryfinder.cpp b/src/corelib/tools/qtextboundaryfinder.cpp
index c3d44da042..f928932548 100644
--- a/src/corelib/tools/qtextboundaryfinder.cpp
+++ b/src/corelib/tools/qtextboundaryfinder.cpp
@@ -49,12 +49,12 @@ QT_BEGIN_NAMESPACE
class QTextBoundaryFinderPrivate
{
public:
- HB_CharAttributes attributes[1];
+ QCharAttributes attributes[1];
};
-static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int length, HB_CharAttributes *attributes)
+static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int length, QCharAttributes *attributes)
{
- QVarLengthArray<HB_ScriptItem> scriptItems;
+ QVarLengthArray<QUnicodeTools::ScriptItem> scriptItems;
const ushort *string = reinterpret_cast<const ushort *>(chars);
const ushort *unicode = string;
@@ -72,11 +72,9 @@ static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int
script = QUnicodeTables::Common;
if (script != lastScript) {
if (uc != start) {
- HB_ScriptItem item;
- item.pos = start - string;
- item.length = uc - start;
- item.script = (HB_Script)lastScript;
- item.bidiLevel = 0; // ### what's the proper value?
+ QUnicodeTools::ScriptItem item;
+ item.position = start - string;
+ item.script = lastScript;
scriptItems.append(item);
start = uc;
}
@@ -85,11 +83,9 @@ static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int
++uc;
}
if (uc != start) {
- HB_ScriptItem item;
- item.pos = start - string;
- item.length = uc - start;
- item.script = (HB_Script)lastScript;
- item.bidiLevel = 0; // ### what's the proper value?
+ QUnicodeTools::ScriptItem item;
+ item.position = start - string;
+ item.script = lastScript;
scriptItems.append(item);
}
@@ -193,9 +189,9 @@ QTextBoundaryFinder::QTextBoundaryFinder(const QTextBoundaryFinder &other)
, pos(other.pos)
, freePrivate(true)
{
- d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(HB_CharAttributes));
+ d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(QCharAttributes));
Q_CHECK_PTR(d);
- memcpy(d, other.d, length*sizeof(HB_CharAttributes));
+ memcpy(d, other.d, length*sizeof(QCharAttributes));
}
/*!
@@ -213,11 +209,11 @@ QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &o
pos = other.pos;
QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *)
- realloc(freePrivate ? d : 0, length*sizeof(HB_CharAttributes));
+ realloc(freePrivate ? d : 0, length*sizeof(QCharAttributes));
Q_CHECK_PTR(newD);
freePrivate = true;
d = newD;
- memcpy(d, other.d, length*sizeof(HB_CharAttributes));
+ memcpy(d, other.d, length*sizeof(QCharAttributes));
return *this;
}
@@ -242,7 +238,7 @@ QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QString &strin
, pos(0)
, freePrivate(true)
{
- d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(HB_CharAttributes));
+ d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(QCharAttributes));
Q_CHECK_PTR(d);
init(t, chars, length, d->attributes);
}
@@ -266,11 +262,11 @@ QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QChar *chars,
, length(length)
, pos(0)
{
- if (buffer && (uint)bufferSize >= length*sizeof(HB_CharAttributes)) {
+ if (buffer && (uint)bufferSize >= length*sizeof(QCharAttributes)) {
d = (QTextBoundaryFinderPrivate *)buffer;
freePrivate = false;
} else {
- d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(HB_CharAttributes));
+ d = (QTextBoundaryFinderPrivate *) malloc(length*sizeof(QCharAttributes));
Q_CHECK_PTR(d);
freePrivate = true;
}
@@ -368,11 +364,11 @@ int QTextBoundaryFinder::toNextBoundary()
switch(t) {
case Grapheme:
- while (pos < length && !d->attributes[pos].charStop)
+ while (pos < length && !d->attributes[pos].graphemeBoundary)
++pos;
break;
case Word:
- while (pos < length && !d->attributes[pos].wordBoundary)
+ while (pos < length && !d->attributes[pos].wordBreak)
++pos;
break;
case Sentence:
@@ -380,7 +376,7 @@ int QTextBoundaryFinder::toNextBoundary()
++pos;
break;
case Line:
- while (pos < length && d->attributes[pos].lineBreakType == HB_NoBreak)
+ while (pos < length && !d->attributes[pos].lineBreak)
++pos;
break;
}
@@ -410,11 +406,11 @@ int QTextBoundaryFinder::toPreviousBoundary()
switch(t) {
case Grapheme:
- while (pos > 0 && !d->attributes[pos].charStop)
+ while (pos > 0 && !d->attributes[pos].graphemeBoundary)
--pos;
break;
case Word:
- while (pos > 0 && !d->attributes[pos].wordBoundary)
+ while (pos > 0 && !d->attributes[pos].wordBreak)
--pos;
break;
case Sentence:
@@ -422,7 +418,7 @@ int QTextBoundaryFinder::toPreviousBoundary()
--pos;
break;
case Line:
- while (pos > 0 && d->attributes[pos].lineBreakType == HB_NoBreak)
+ while (pos > 0 && !d->attributes[pos].lineBreak)
--pos;
break;
}
@@ -443,11 +439,11 @@ bool QTextBoundaryFinder::isAtBoundary() const
switch(t) {
case Grapheme:
- return d->attributes[pos].charStop;
+ return d->attributes[pos].graphemeBoundary;
case Word:
- return d->attributes[pos].wordBoundary;
+ return d->attributes[pos].wordBreak;
case Line:
- return pos == 0 || d->attributes[pos].lineBreakType != HB_NoBreak;
+ return pos == 0 || d->attributes[pos].lineBreak;
case Sentence:
return d->attributes[pos].sentenceBoundary;
}
@@ -463,8 +459,6 @@ QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons() cons
return NotAtBoundary;
if (! isAtBoundary())
return NotAtBoundary;
- if (t == Line && pos < length && d->attributes[pos].lineBreakType == HB_SoftHyphen)
- return SoftHyphen;
if (pos == 0) {
if (d->attributes[pos].whiteSpace)
return NotAtBoundary;
@@ -476,6 +470,12 @@ QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons() cons
return EndWord;
}
+ if (t == Line && chars[pos - 1].unicode() == QChar::SoftHyphen)
+ return SoftHyphen;
+
+ if (t != Word)
+ return BoundaryReasons(StartWord | EndWord);
+
const bool nextIsSpace = d->attributes[pos].whiteSpace;
const bool prevIsSpace = d->attributes[pos - 1].whiteSpace;