From e38aaf9f7c91efb6197f7f579e3064e0e6dcce1e Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Wed, 25 May 2011 10:55:52 +0200 Subject: Fix cursor position test on CursorOnCharacter case Reviewed-by: TrustMe --- src/gui/text/qtextengine.cpp | 5 ++++- src/gui/text/qtextengine_p.h | 2 +- src/gui/text/qtextlayout.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 62de1fe..69598cf 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2716,7 +2716,8 @@ int QTextEngine::getClusterLength(unsigned short *logClusters, } int QTextEngine::positionInLigature(const QScriptItem *si, int end, - QFixed x, QFixed edge, int glyph_pos) + QFixed x, QFixed edge, int glyph_pos, + bool cursorOnCharacter) { unsigned short *logClusters = this->logClusters(si); int clusterStart = -1; @@ -2754,6 +2755,8 @@ int QTextEngine::positionInLigature(const QScriptItem *si, int end, int n = ((x - left) / perItemWidth).floor().toInt(); QFixed dist = x - left - n * perItemWidth; int closestItem = dist > (perItemWidth / 2) ? n + 1 : n; + if (cursorOnCharacter && closestItem > 0) + closestItem--; int pos = si->position + clusterStart + closestItem; // Jump to the next charStop while (!attrs[pos].charStop && pos < end) diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index f8939e3..09610ff 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -594,7 +594,7 @@ public: void shapeLine(const QScriptLine &line); QFixed leadingSpaceWidth(const QScriptLine &line); - int positionInLigature(const QScriptItem *si, int end, QFixed x, QFixed edge, int glyph_pos); + int positionInLigature(const QScriptItem *si, int end, QFixed x, QFixed edge, int glyph_pos, bool cursorOnCharacter); private: void setBoundary(int strPos) const; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index a9179ed..4b3c9e7 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2677,10 +2677,12 @@ int QTextLine::xToCursor(qreal _x, CursorPosition cpos) const } } if (qAbs(x-pos) < dist) - return eng->positionInLigature(&si, end, x, pos, -1); + return eng->positionInLigature(&si, end, x, pos, -1, + cpos == QTextLine::CursorOnCharacter); } Q_ASSERT(glyph_pos != -1); - return eng->positionInLigature(&si, end, x, edge, glyph_pos); + return eng->positionInLigature(&si, end, x, edge, glyph_pos, + cpos == QTextLine::CursorOnCharacter); } } // right of last item -- cgit v0.12