| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquicktextnode.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 24 | ** | - | ||||||
| 25 | ** GNU General Public License Usage | - | ||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 35 | ** | - | ||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||
| 37 | ** | - | ||||||
| 38 | ****************************************************************************/ | - | ||||||
| 39 | - | |||||||
| 40 | #include "qquicktextnode_p.h" | - | ||||||
| 41 | - | |||||||
| 42 | #include "qquicktextnodeengine_p.h" | - | ||||||
| 43 | - | |||||||
| 44 | #include <private/qsgadaptationlayer_p.h> | - | ||||||
| 45 | #include <private/qsgdistancefieldglyphnode_p.h> | - | ||||||
| 46 | #include <private/qquickclipnode_p.h> | - | ||||||
| 47 | #include <private/qquickitem_p.h> | - | ||||||
| 48 | #include <QtQuick/private/qsgcontext_p.h> | - | ||||||
| 49 | - | |||||||
| 50 | #include <QtCore/qpoint.h> | - | ||||||
| 51 | #include <qtextdocument.h> | - | ||||||
| 52 | #include <qtextlayout.h> | - | ||||||
| 53 | #include <qabstracttextdocumentlayout.h> | - | ||||||
| 54 | #include <qxmlstream.h> | - | ||||||
| 55 | #include <private/qquickstyledtext_p.h> | - | ||||||
| 56 | #include <private/qfont_p.h> | - | ||||||
| 57 | #include <private/qfontengine_p.h> | - | ||||||
| 58 | - | |||||||
| 59 | #include <private/qtextdocumentlayout_p.h> | - | ||||||
| 60 | #include <qhash.h> | - | ||||||
| 61 | - | |||||||
| 62 | QT_BEGIN_NAMESPACE | - | ||||||
| 63 | - | |||||||
| 64 | namespace { | - | ||||||
| 65 | - | |||||||
| 66 | class ProtectedLayoutAccessor: public QAbstractTextDocumentLayout | - | ||||||
| 67 | { | - | ||||||
| 68 | public: | - | ||||||
| 69 | inline QTextCharFormat formatAccessor(int pos) | - | ||||||
| 70 | { | - | ||||||
| 71 | return format(pos); never executed: return format(pos); | 0 | ||||||
| 72 | } | - | ||||||
| 73 | }; | - | ||||||
| 74 | - | |||||||
| 75 | } | - | ||||||
| 76 | - | |||||||
| 77 | /*! | - | ||||||
| 78 | Creates an empty QQuickTextNode | - | ||||||
| 79 | */ | - | ||||||
| 80 | QQuickTextNode::QQuickTextNode(QQuickItem *ownerElement) | - | ||||||
| 81 | : m_cursorNode(nullptr), m_ownerElement(ownerElement), m_useNativeRenderer(false) | - | ||||||
| 82 | { | - | ||||||
| 83 | #ifdef QSG_RUNTIME_DESCRIPTION | - | ||||||
| 84 | qsgnode_set_description(this, QLatin1String("text")); | - | ||||||
| 85 | #endif | - | ||||||
| 86 | } executed 175001 times by 24 tests: end of blockExecuted by:
| 175001 | ||||||
| 87 | - | |||||||
| 88 | QQuickTextNode::~QQuickTextNode() | - | ||||||
| 89 | { | - | ||||||
| 90 | qDeleteAll(m_textures); | - | ||||||
| 91 | } executed 175001 times by 24 tests: end of blockExecuted by:
| 175001 | ||||||
| 92 | - | |||||||
| 93 | QSGGlyphNode *QQuickTextNode::addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color, | - | ||||||
| 94 | QQuickText::TextStyle style, const QColor &styleColor, | - | ||||||
| 95 | QSGNode *parentNode) | - | ||||||
| 96 | { | - | ||||||
| 97 | QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext(); | - | ||||||
| 98 | QRawFont font = glyphs.rawFont(); | - | ||||||
| 99 | bool preferNativeGlyphNode = m_useNativeRenderer; | - | ||||||
| 100 | if (!preferNativeGlyphNode) {
| 72-249131 | ||||||
| 101 | QRawFontPrivate *fontPriv = QRawFontPrivate::get(font); | - | ||||||
| 102 | if (fontPriv->fontEngine->hasUnreliableGlyphOutline()) {
| 0-249131 | ||||||
| 103 | preferNativeGlyphNode = true; | - | ||||||
| 104 | } else { never executed: end of block | 0 | ||||||
| 105 | QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine; | - | ||||||
| 106 | preferNativeGlyphNode = !fe->isSmoothlyScalable; | - | ||||||
| 107 | } executed 249131 times by 24 tests: end of blockExecuted by:
| 249131 | ||||||
| 108 | } | - | ||||||
| 109 | - | |||||||
| 110 | QSGGlyphNode *node = sg->sceneGraphContext()->createGlyphNode(sg, preferNativeGlyphNode); | - | ||||||
| 111 | - | |||||||
| 112 | node->setOwnerElement(m_ownerElement); | - | ||||||
| 113 | node->setGlyphs(position + QPointF(0, glyphs.rawFont().ascent()), glyphs); | - | ||||||
| 114 | node->setStyle(style); | - | ||||||
| 115 | node->setStyleColor(styleColor); | - | ||||||
| 116 | node->setColor(color); | - | ||||||
| 117 | node->update(); | - | ||||||
| 118 | - | |||||||
| 119 | /* We flag the geometry as static, but we never call markVertexDataDirty | - | ||||||
| 120 | or markIndexDataDirty on them. This is because all text nodes are | - | ||||||
| 121 | discarded when a change occurs. If we start appending/removing from | - | ||||||
| 122 | existing geometry, then we also need to start marking the geometry as | - | ||||||
| 123 | dirty. | - | ||||||
| 124 | */ | - | ||||||
| 125 | node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern); | - | ||||||
| 126 | node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern); | - | ||||||
| 127 | - | |||||||
| 128 | if (parentNode == nullptr)
| 108-249095 | ||||||
| 129 | parentNode = this; executed 249095 times by 24 tests: parentNode = this;Executed by:
| 249095 | ||||||
| 130 | parentNode->appendChildNode(node); | - | ||||||
| 131 | - | |||||||
| 132 | return node; executed 249203 times by 24 tests: return node;Executed by:
| 249203 | ||||||
| 133 | } | - | ||||||
| 134 | - | |||||||
| 135 | void QQuickTextNode::setCursor(const QRectF &rect, const QColor &color) | - | ||||||
| 136 | { | - | ||||||
| 137 | if (m_cursorNode != nullptr)
| 0-66 | ||||||
| 138 | delete m_cursorNode; never executed: delete m_cursorNode; | 0 | ||||||
| 139 | - | |||||||
| 140 | QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext(); | - | ||||||
| 141 | m_cursorNode = sg->sceneGraphContext()->createInternalRectangleNode(rect, color); | - | ||||||
| 142 | appendChildNode(m_cursorNode); | - | ||||||
| 143 | } executed 66 times by 4 tests: end of blockExecuted by:
| 66 | ||||||
| 144 | - | |||||||
| 145 | void QQuickTextNode::clearCursor() | - | ||||||
| 146 | { | - | ||||||
| 147 | if (m_cursorNode)
| 6-54 | ||||||
| 148 | removeChildNode(m_cursorNode); executed 6 times by 2 tests: removeChildNode(m_cursorNode);Executed by:
| 6 | ||||||
| 149 | delete m_cursorNode; | - | ||||||
| 150 | m_cursorNode = nullptr; | - | ||||||
| 151 | } executed 60 times by 2 tests: end of blockExecuted by:
| 60 | ||||||
| 152 | - | |||||||
| 153 | void QQuickTextNode::addRectangleNode(const QRectF &rect, const QColor &color) | - | ||||||
| 154 | { | - | ||||||
| 155 | QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext(); | - | ||||||
| 156 | appendChildNode(sg->sceneGraphContext()->createInternalRectangleNode(rect, color)); | - | ||||||
| 157 | } executed 98 times by 4 tests: end of blockExecuted by:
| 98 | ||||||
| 158 | - | |||||||
| 159 | - | |||||||
| 160 | void QQuickTextNode::addImage(const QRectF &rect, const QImage &image) | - | ||||||
| 161 | { | - | ||||||
| 162 | QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext(); | - | ||||||
| 163 | QSGInternalImageNode *node = sg->sceneGraphContext()->createInternalImageNode(); | - | ||||||
| 164 | QSGTexture *texture = sg->createTexture(image); | - | ||||||
| 165 | if (m_ownerElement->smooth())
| 0-30 | ||||||
| 166 | texture->setFiltering(QSGTexture::Linear); executed 30 times by 2 tests: texture->setFiltering(QSGTexture::Linear);Executed by:
| 30 | ||||||
| 167 | m_textures.append(texture); | - | ||||||
| 168 | node->setTargetRect(rect); | - | ||||||
| 169 | node->setInnerTargetRect(rect); | - | ||||||
| 170 | node->setTexture(texture); | - | ||||||
| 171 | if (m_ownerElement->smooth())
| 0-30 | ||||||
| 172 | node->setFiltering(QSGTexture::Linear); executed 30 times by 2 tests: node->setFiltering(QSGTexture::Linear);Executed by:
| 30 | ||||||
| 173 | appendChildNode(node); | - | ||||||
| 174 | node->update(); | - | ||||||
| 175 | } executed 30 times by 2 tests: end of blockExecuted by:
| 30 | ||||||
| 176 | - | |||||||
| 177 | void QQuickTextNode::addTextDocument(const QPointF &position, QTextDocument *textDocument, | - | ||||||
| 178 | const QColor &textColor, | - | ||||||
| 179 | QQuickText::TextStyle style, const QColor &styleColor, | - | ||||||
| 180 | const QColor &anchorColor, | - | ||||||
| 181 | const QColor &selectionColor, const QColor &selectedTextColor, | - | ||||||
| 182 | int selectionStart, int selectionEnd) | - | ||||||
| 183 | { | - | ||||||
| 184 | QQuickTextNodeEngine engine; | - | ||||||
| 185 | engine.setTextColor(textColor); | - | ||||||
| 186 | engine.setSelectedTextColor(selectedTextColor); | - | ||||||
| 187 | engine.setSelectionColor(selectionColor); | - | ||||||
| 188 | engine.setAnchorColor(anchorColor); | - | ||||||
| 189 | engine.setPosition(position); | - | ||||||
| 190 | - | |||||||
| 191 | QList<QTextFrame *> frames; | - | ||||||
| 192 | frames.append(textDocument->rootFrame()); | - | ||||||
| 193 | while (!frames.isEmpty()) {
| 84-90 | ||||||
| 194 | QTextFrame *textFrame = frames.takeFirst(); | - | ||||||
| 195 | frames.append(textFrame->childFrames()); | - | ||||||
| 196 | - | |||||||
| 197 | engine.addFrameDecorations(textDocument, textFrame); | - | ||||||
| 198 | - | |||||||
| 199 | if (textFrame->firstPosition() > textFrame->lastPosition()
| 6-84 | ||||||
| 200 | && textFrame->frameFormat().position() != QTextFrameFormat::InFlow) {
| 0-6 | ||||||
| 201 | const int pos = textFrame->firstPosition() - 1; | - | ||||||
| 202 | ProtectedLayoutAccessor *a = static_cast<ProtectedLayoutAccessor *>(textDocument->documentLayout()); | - | ||||||
| 203 | QTextCharFormat format = a->formatAccessor(pos); | - | ||||||
| 204 | QRectF rect = a->frameBoundingRect(textFrame); | - | ||||||
| 205 | - | |||||||
| 206 | QTextBlock block = textFrame->firstCursorPosition().block(); | - | ||||||
| 207 | engine.setCurrentLine(block.layout()->lineForTextPosition(pos - block.position())); | - | ||||||
| 208 | engine.addTextObject(rect.topLeft(), format, QQuickTextNodeEngine::Unselected, textDocument, | - | ||||||
| 209 | pos, textFrame->frameFormat().position()); | - | ||||||
| 210 | } else { never executed: end of block | 0 | ||||||
| 211 | QTextFrame::iterator it = textFrame->begin(); | - | ||||||
| 212 | - | |||||||
| 213 | while (!it.atEnd()) {
| 90-108 | ||||||
| 214 | Q_ASSERT(!engine.currentLine().isValid()); | - | ||||||
| 215 | - | |||||||
| 216 | QTextBlock block = it.currentBlock(); | - | ||||||
| 217 | engine.addTextBlock(textDocument, block, position, textColor, anchorColor, selectionStart, selectionEnd); | - | ||||||
| 218 | ++it; | - | ||||||
| 219 | } executed 108 times by 2 tests: end of blockExecuted by:
| 108 | ||||||
| 220 | } executed 90 times by 2 tests: end of blockExecuted by:
| 90 | ||||||
| 221 | } | - | ||||||
| 222 | - | |||||||
| 223 | engine.addToSceneGraph(this, style, styleColor); | - | ||||||
| 224 | } executed 84 times by 2 tests: end of blockExecuted by:
| 84 | ||||||
| 225 | - | |||||||
| 226 | void QQuickTextNode::addTextLayout(const QPointF &position, QTextLayout *textLayout, const QColor &color, | - | ||||||
| 227 | QQuickText::TextStyle style, const QColor &styleColor, | - | ||||||
| 228 | const QColor &anchorColor, | - | ||||||
| 229 | const QColor &selectionColor, const QColor &selectedTextColor, | - | ||||||
| 230 | int selectionStart, int selectionEnd, | - | ||||||
| 231 | int lineStart, int lineCount) | - | ||||||
| 232 | { | - | ||||||
| 233 | QQuickTextNodeEngine engine; | - | ||||||
| 234 | engine.setTextColor(color); | - | ||||||
| 235 | engine.setSelectedTextColor(selectedTextColor); | - | ||||||
| 236 | engine.setSelectionColor(selectionColor); | - | ||||||
| 237 | engine.setAnchorColor(anchorColor); | - | ||||||
| 238 | engine.setPosition(position); | - | ||||||
| 239 | - | |||||||
| 240 | #if QT_CONFIG(im) | - | ||||||
| 241 | int preeditLength = textLayout->preeditAreaText().length(); | - | ||||||
| 242 | int preeditPosition = textLayout->preeditAreaPosition(); | - | ||||||
| 243 | #endif | - | ||||||
| 244 | - | |||||||
| 245 | QVarLengthArray<QTextLayout::FormatRange> colorChanges; | - | ||||||
| 246 | engine.mergeFormats(textLayout, &colorChanges); | - | ||||||
| 247 | - | |||||||
| 248 | lineCount = lineCount >= 0
| 171-248272 | ||||||
| 249 | ? qMin(lineStart + lineCount, textLayout->lineCount()) | - | ||||||
| 250 | : textLayout->lineCount(); | - | ||||||
| 251 | - | |||||||
| 252 | for (int i=lineStart; i<lineCount; ++i) {
| 248443-249990 | ||||||
| 253 | QTextLine line = textLayout->lineAt(i); | - | ||||||
| 254 | - | |||||||
| 255 | int start = line.textStart(); | - | ||||||
| 256 | int length = line.textLength(); | - | ||||||
| 257 | int end = start + length; | - | ||||||
| 258 | - | |||||||
| 259 | #if QT_CONFIG(im) | - | ||||||
| 260 | if (preeditPosition >= 0
| 2-249988 | ||||||
| 261 | && preeditPosition >= start
| 0-2 | ||||||
| 262 | && preeditPosition < end) {
| 0-2 | ||||||
| 263 | end += preeditLength; | - | ||||||
| 264 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 265 | #endif | - | ||||||
| 266 | - | |||||||
| 267 | engine.setCurrentLine(line); | - | ||||||
| 268 | engine.addGlyphsForRanges(colorChanges, start, end, selectionStart, selectionEnd); | - | ||||||
| 269 | } executed 249990 times by 24 tests: end of blockExecuted by:
| 249990 | ||||||
| 270 | - | |||||||
| 271 | engine.addToSceneGraph(this, style, styleColor); | - | ||||||
| 272 | } executed 248443 times by 24 tests: end of blockExecuted by:
| 248443 | ||||||
| 273 | - | |||||||
| 274 | void QQuickTextNode::deleteContent() | - | ||||||
| 275 | { | - | ||||||
| 276 | while (firstChild() != nullptr)
| 74479-248591 | ||||||
| 277 | delete firstChild(); executed 74479 times by 10 tests: delete firstChild();Executed by:
| 74479 | ||||||
| 278 | m_cursorNode = nullptr; | - | ||||||
| 279 | qDeleteAll(m_textures); | - | ||||||
| 280 | m_textures.clear(); | - | ||||||
| 281 | } executed 248591 times by 24 tests: end of blockExecuted by:
| 248591 | ||||||
| 282 | - | |||||||
| 283 | QT_END_NAMESPACE | - | ||||||
| Source code | Switch to Preprocessed file |