summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextlayout.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/gui/text/qtextlayout.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/gui/text/qtextlayout.cpp')
-rw-r--r--src/gui/text/qtextlayout.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index a49b4112d4..7591b46547 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -683,7 +683,7 @@ void QTextLayout::clearLayout()
*/
int QTextLayout::nextCursorPosition(int oldPos, CursorMode mode) const
{
- const HB_CharAttributes *attributes = d->attributes();
+ const QCharAttributes *attributes = d->attributes();
int len = d->block.isValid() ? d->block.length() - 1
: d->layoutData->string.length();
Q_ASSERT(len <= d->layoutData->string.length());
@@ -692,7 +692,7 @@ int QTextLayout::nextCursorPosition(int oldPos, CursorMode mode) const
if (mode == SkipCharacters) {
oldPos++;
- while (oldPos < len && !attributes[oldPos].charStop)
+ while (oldPos < len && !attributes[oldPos].graphemeBoundary)
oldPos++;
} else {
if (oldPos < len && d->atWordSeparator(oldPos)) {
@@ -719,13 +719,13 @@ int QTextLayout::nextCursorPosition(int oldPos, CursorMode mode) const
*/
int QTextLayout::previousCursorPosition(int oldPos, CursorMode mode) const
{
- const HB_CharAttributes *attributes = d->attributes();
+ const QCharAttributes *attributes = d->attributes();
if (!attributes || oldPos <= 0 || oldPos > d->layoutData->string.length())
return oldPos;
if (mode == SkipCharacters) {
oldPos--;
- while (oldPos && !attributes[oldPos].charStop)
+ while (oldPos && !attributes[oldPos].graphemeBoundary)
oldPos--;
} else {
while (oldPos && d->atSpace(oldPos-1))
@@ -789,10 +789,10 @@ int QTextLayout::leftCursorPosition(int oldPos) const
*/
bool QTextLayout::isValidCursorPosition(int pos) const
{
- const HB_CharAttributes *attributes = d->attributes();
+ const QCharAttributes *attributes = d->attributes();
if (!attributes || pos < 0 || pos > (int)d->layoutData->string.length())
return false;
- return attributes[pos].charStop;
+ return attributes[pos].graphemeBoundary;
}
/*!
@@ -1770,7 +1770,7 @@ void QTextLine::layout_helper(int maxGlyphs)
Qt::Alignment alignment = eng->option.alignment();
- const HB_CharAttributes *attributes = eng->attributes();
+ const QCharAttributes *attributes = eng->attributes();
if (!attributes)
return;
lbh.currentPosition = line.from;
@@ -1875,17 +1875,18 @@ void QTextLine::layout_helper(int maxGlyphs)
if (lbh.currentPosition >= eng->layoutData->string.length()
|| attributes[lbh.currentPosition].whiteSpace
- || attributes[lbh.currentPosition].lineBreakType != HB_NoBreak) {
+ || attributes[lbh.currentPosition].lineBreak) {
sb_or_ws = true;
break;
- } else if (breakany && attributes[lbh.currentPosition].charStop) {
+ } else if (breakany && attributes[lbh.currentPosition].graphemeBoundary) {
break;
}
} while (lbh.currentPosition < end);
lbh.minw = qMax(lbh.tmpData.textWidth, lbh.minw);
if (lbh.currentPosition > 0 && lbh.currentPosition < end
- && attributes[lbh.currentPosition].lineBreakType == HB_SoftHyphen) {
+ && attributes[lbh.currentPosition].lineBreak
+ && eng->layoutData->string.at(lbh.currentPosition - 1).unicode() == QChar::SoftHyphen) {
// if we are splitting up a word because of
// a soft hyphen then we ...
//
@@ -2605,12 +2606,12 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
int lineEnd = line.from + line.length + line.trailingSpaces;
int pos = *cursorPos;
int itm;
- const HB_CharAttributes *attributes = eng->attributes();
+ const QCharAttributes *attributes = eng->attributes();
if (!attributes) {
*cursorPos = 0;
return x.toReal();
}
- while (pos < lineEnd && !attributes[pos].charStop)
+ while (pos < lineEnd && !attributes[pos].graphemeBoundary)
pos++;
if (pos == lineEnd) {
// end of line ensure we have the last item on the line