aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextnodeengine_p.h
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2014-08-25 12:46:11 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>2014-09-02 09:49:42 +0200
commitb0783c21fb54b939f07ddf5658cc51113b8014e6 (patch)
treeb23ead89a4ab0dab88727b5f3086840f1511bb74 /src/quick/items/qquicktextnodeengine_p.h
parent64d844ff6e5c007f44747a5a7a3c3646ca95a632 (diff)
Fix selection of text with negative right bearing
Selecting text with a negative right bearing (like italic text) would cause clipping to occur at the edges of the characters. The algorithm for drawing text and text selection tried to divide the text into two: 1. Selected text, and 2. Unselected text. However, the selected text might be drawn outside the selection rect when it has a negative right bearing. Similarly, unselected text before the selection might overlap with the selection rect when it has a negative right bearing, or unselected text after the selection might overlap if it has a negative left bearing. See added test textinput_italic_selected.qml for an example. To rectify this, we do drawing of selected text like this: 1. Draw all text with unselected color 2. Draw selection rects 3. Draw the following in the selection text color and clipped to the selection rect: A. The selected text B. The unselected text right before the selection C. The unselected text right after the selection To avoid drawing the same text twice for extra boldness, we check if 3B or 3C actually contain 3A, in which case we skip 3A. [ChangeLog][Text] Fixed clipping when selecting text with negative right bearing. Task-number: QTBUG-34233 Change-Id: I3506b3a72a2d963c5f24c5b819bbb92769b9aee1 Reviewed-by: Samuel Nevala <samuel.nevala@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/quick/items/qquicktextnodeengine_p.h')
-rw-r--r--src/quick/items/qquicktextnodeengine_p.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/quick/items/qquicktextnodeengine_p.h b/src/quick/items/qquicktextnodeengine_p.h
index 9a64853dd3..142375b5a3 100644
--- a/src/quick/items/qquicktextnodeengine_p.h
+++ b/src/quick/items/qquicktextnodeengine_p.h
@@ -75,10 +75,11 @@ public:
BinaryTreeNode(const QGlyphRun &g, SelectionState selState, const QRectF &brect,
const QQuickTextNode::Decorations &decs, const QColor &c, const QColor &bc,
- const QPointF &pos, qreal a)
+ const QPointF &pos, qreal a, int rangeStart, int rangeEnd)
: glyphRun(g), boundingRect(brect), selectionState(selState), clipNode(0), decorations(decs)
, color(c), backgroundColor(bc), position(pos), ascent(a), leftChildIndex(-1), rightChildIndex(-1)
{
+ ranges.append(qMakePair(rangeStart, rangeEnd));
}
QGlyphRun glyphRun;
@@ -95,11 +96,14 @@ public:
int leftChildIndex;
int rightChildIndex;
+ QList<QPair<int, int> > ranges;
+
static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QRectF &rect, const QImage &image, qreal ascent, SelectionState selectionState)
{ insert(binaryTree, BinaryTreeNode(rect, image, selectionState, ascent)); }
static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
- QQuickTextNode::Decorations decorations, const QColor &textColor, const QColor &backgroundColor, const QPointF &position);
+ QQuickTextNode::Decorations decorations, const QColor &textColor, const QColor &backgroundColor, const QPointF &position,
+ int rangeStart, int rangeEnd);
static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode);
static void inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0);
};
@@ -134,8 +138,8 @@ public:
SelectionState selectionState,
QTextDocument *textDocument, int pos,
QTextFrameFormat::Position layoutPosition = QTextFrameFormat::InFlow);
- void addSelectedGlyphs(const QGlyphRun &glyphRun);
- void addUnselectedGlyphs(const QGlyphRun &glyphRun);
+ void addSelectedGlyphs(const QGlyphRun &glyphRun, int rangeStart, int rangeEnd);
+ void addUnselectedGlyphs(const QGlyphRun &glyphRun, int rangeStart, int rangeEnd);
void addGlyphsInRange(int rangeStart, int rangeEnd,
const QColor &color, const QColor &backgroundColor,
int selectionStart, int selectionEnd);