36QSGInternalTextNode::QSGInternalTextNode(QSGRenderContext *renderContext)
37 : m_renderContext(renderContext)
39#ifdef QSG_RUNTIME_DESCRIPTION
40 qsgnode_set_description(
this, QLatin1String(
"text"));
43 static_assert(
int(QSGTextNode::Normal) ==
int(QQuickText::Normal));
44 static_assert(
int(QSGTextNode::Outline) ==
int(QQuickText::Outline));
45 static_assert(
int(QSGTextNode::Raised) ==
int(QQuickText::Raised));
46 static_assert(
int(QSGTextNode::Sunken) ==
int(QQuickText::Sunken));
48 static_assert(
int(QSGTextNode::QtRendering) ==
int(QQuickText::QtRendering));
49 static_assert(
int(QSGTextNode::NativeRendering) ==
int(QQuickText::NativeRendering));
50 static_assert(
int(QSGTextNode::CurveRendering) ==
int(QQuickText::CurveRendering));
58QSGGlyphNode *QSGInternalTextNode::addGlyphs(
const QPointF &position,
const QGlyphRun &glyphs,
const QColor &color,
59 QQuickText::TextStyle style,
const QColor &styleColor,
62 QRawFont font = glyphs.rawFont();
64 QSGTextNode::RenderType preferredRenderType = m_renderType;
65 if (m_renderType != NativeRendering) {
66 if (
const QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine)
67 if (fe->hasUnreliableGlyphOutline() || !fe->isSmoothlyScalable)
68 preferredRenderType = QSGTextNode::NativeRendering;
71 if (preferredRenderType == NativeRendering)
72 m_containsUnscalableGlyphs =
true;
74 QSGGlyphNode *node = m_renderContext->sceneGraphContext()->createGlyphNode(m_renderContext,
77 node->setGlyphs(position + QPointF(0, glyphs.rawFont().ascent()), glyphs);
78 node->setStyle(style);
79 node->setStyleColor(styleColor);
80 node->setColor(color);
84
85
86
87
88
89 node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
90 node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
92 if (parentNode ==
nullptr)
94 parentNode->appendChildNode(node);
96 if (style == QQuickText::Outline && color.alpha() > 0 && styleColor != color) {
97 QSGGlyphNode *fillNode = m_renderContext->sceneGraphContext()->createGlyphNode(m_renderContext,
100 fillNode->setGlyphs(position + QPointF(0, glyphs.rawFont().ascent()), glyphs);
101 fillNode->setStyle(QQuickText::Normal);
102 fillNode->setPreferredAntialiasingMode(QSGGlyphNode::GrayAntialiasing);
103 fillNode->setColor(color);
106 fillNode->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
107 fillNode->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
109 parentNode->appendChildNode(fillNode);
110 fillNode->setRenderOrder(node->renderOrder() + 1);
145void QSGInternalTextNode::addImage(
const QRectF &rect,
const QImage &image)
147 QSGInternalImageNode *node = m_renderContext->sceneGraphContext()->createInternalImageNode(m_renderContext);
148 QSGTexture *texture = m_renderContext->createTexture(image);
149 texture->setFiltering(m_filtering);
150 m_textures.append(texture);
151 node->setTargetRect(rect);
152 node->setInnerTargetRect(rect);
153 node->setTexture(texture);
154 node->setFiltering(m_filtering);
155 appendChildNode(node);
159void QSGInternalTextNode::doAddTextDocument(QPointF position, QTextDocument *textDocument,
160 int selectionStart,
int selectionEnd)
162 QQuickTextNodeEngine engine;
163 engine.setTextColor(m_color);
164 engine.setSelectedTextColor(m_selectionTextColor);
165 engine.setSelectionColor(m_selectionColor);
166 engine.setAnchorColor(m_linkColor);
167 engine.setPosition(position);
168 engine.setDevicePixelRatio(m_devicePixelRatio);
170 QList<QTextFrame *> frames;
171 frames.append(textDocument->rootFrame());
172 while (!frames.isEmpty()) {
173 QTextFrame *textFrame = frames.takeFirst();
174 frames.append(textFrame->childFrames());
176 engine.addFrameDecorations(textDocument, textFrame);
178 if (textFrame->firstPosition() > textFrame->lastPosition()
179 && textFrame->frameFormat().position() != QTextFrameFormat::InFlow) {
180 const int pos = textFrame->firstPosition() - 1;
181 auto *a =
static_cast<QtPrivate::ProtectedLayoutAccessor *>(textDocument->documentLayout());
182 QTextCharFormat format = a->formatAccessor(pos);
183 QRectF rect = a->frameBoundingRect(textFrame);
185 QTextBlock block = textFrame->firstCursorPosition().block();
186 engine.setCurrentLine(block.layout()->lineForTextPosition(pos - block.position()));
187 engine.addTextObject(block, rect.topLeft(), format, QQuickTextNodeEngine::Unselected, textDocument,
188 pos, textFrame->frameFormat().position());
190 QTextFrame::iterator it = textFrame->begin();
192 while (!it.atEnd()) {
193 Q_ASSERT(!engine.currentLine().isValid());
195 QTextBlock block = it.currentBlock();
196 engine.addTextBlock(textDocument, block, position, m_color, m_linkColor, selectionStart, selectionEnd,
197 (textDocument->characterCount() > QQuickTextPrivate::largeTextSizeThreshold ?
198 m_viewport : QRectF()));
204 engine.addToSceneGraph(
this, QQuickText::TextStyle(m_textStyle), m_styleColor);
207void QSGInternalTextNode::doAddTextLayout(QPointF position, QTextLayout *textLayout,
208 int selectionStart,
int selectionEnd,
209 int lineStart,
int lineCount)
211 QQuickTextNodeEngine engine;
212 engine.setTextColor(m_color);
213 engine.setSelectedTextColor(m_selectionTextColor);
214 engine.setSelectionColor(m_selectionColor);
215 engine.setAnchorColor(m_linkColor);
216 engine.setPosition(position);
217 engine.setDevicePixelRatio(m_devicePixelRatio);
220 int preeditLength = textLayout->preeditAreaText().size();
221 int preeditPosition = textLayout->preeditAreaPosition();
224 QVarLengthArray<QTextLayout::FormatRange> colorChanges;
225 engine.mergeFormats(textLayout, &colorChanges);
227 lineCount = lineCount >= 0
228 ? qMin(lineStart + lineCount, textLayout->lineCount())
229 : textLayout->lineCount();
231 bool inViewport =
false;
232 for (
int i=lineStart; i<lineCount; ++i) {
233 QTextLine line = textLayout->lineAt(i);
235 int start = line.textStart();
236 int length = line.textLength();
237 int end = start + length;
240 if (preeditPosition >= 0
241 && preeditPosition >= start
242 && preeditPosition < end) {
243 end += preeditLength;
247 if (m_viewport.isNull() || (line.y() + line.height() > m_viewport.top() && line.y() < m_viewport.bottom())) {
248 if (!inViewport && !m_viewport.isNull()) {
249 m_firstLineInViewport = i;
250 qCDebug(lcVP) <<
"first line in viewport" << i <<
"@" << line.y();
253 engine.setCurrentLine(line);
254 engine.addGlyphsForRanges(colorChanges, start, end, selectionStart, selectionEnd);
255 }
else if (inViewport) {
256 Q_ASSERT(!m_viewport.isNull());
257 m_firstLinePastViewport = i;
258 qCDebug(lcVP) <<
"first omitted line past bottom of viewport" << i <<
"@" << line.y();
263 engine.addToSceneGraph(
this, QQuickText::TextStyle(m_textStyle), m_styleColor);