32QSGInternalTextNode::QSGInternalTextNode(QSGRenderContext *renderContext)
33 : m_renderContext(renderContext)
35#ifdef QSG_RUNTIME_DESCRIPTION
36 qsgnode_set_description(
this, QLatin1String(
"text"));
39 static_assert(
int(QSGTextNode::Normal) ==
int(QQuickText::Normal));
40 static_assert(
int(QSGTextNode::Outline) ==
int(QQuickText::Outline));
41 static_assert(
int(QSGTextNode::Raised) ==
int(QQuickText::Raised));
42 static_assert(
int(QSGTextNode::Sunken) ==
int(QQuickText::Sunken));
44 static_assert(
int(QSGTextNode::QtRendering) ==
int(QQuickText::QtRendering));
45 static_assert(
int(QSGTextNode::NativeRendering) ==
int(QQuickText::NativeRendering));
46 static_assert(
int(QSGTextNode::CurveRendering) ==
int(QQuickText::CurveRendering));
54QSGGlyphNode *QSGInternalTextNode::addGlyphs(
const QPointF &position,
const QGlyphRun &glyphs,
const QColor &color,
55 QQuickText::TextStyle style,
const QColor &styleColor,
58 QRawFont font = glyphs.rawFont();
60 QSGTextNode::RenderType preferredRenderType = m_renderType;
61 if (m_renderType != NativeRendering) {
62 if (
const QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine)
63 if (fe->hasUnreliableGlyphOutline() || !fe->isSmoothlyScalable)
64 preferredRenderType = QSGTextNode::NativeRendering;
67 if (preferredRenderType == NativeRendering)
68 m_containsUnscalableGlyphs =
true;
70 QSGGlyphNode *node = m_renderContext->sceneGraphContext()->createGlyphNode(m_renderContext,
73 node->setGlyphs(position + QPointF(0, glyphs.rawFont().ascent()), glyphs);
74 node->setStyle(style);
75 node->setStyleColor(styleColor);
76 node->setColor(color);
80
81
82
83
84
85 node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
86 node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
88 if (parentNode ==
nullptr)
90 parentNode->appendChildNode(node);
92 if (style == QQuickText::Outline && color.alpha() > 0 && styleColor != color) {
93 QSGGlyphNode *fillNode = m_renderContext->sceneGraphContext()->createGlyphNode(m_renderContext,
96 fillNode->setGlyphs(position + QPointF(0, glyphs.rawFont().ascent()), glyphs);
97 fillNode->setStyle(QQuickText::Normal);
98 fillNode->setPreferredAntialiasingMode(QSGGlyphNode::GrayAntialiasing);
99 fillNode->setColor(color);
102 fillNode->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
103 fillNode->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
105 parentNode->appendChildNode(fillNode);
106 fillNode->setRenderOrder(node->renderOrder() + 1);
139void QSGInternalTextNode::addImage(
const QRectF &rect,
const QImage &image)
141 QSGInternalImageNode *node = m_renderContext->sceneGraphContext()->createInternalImageNode(m_renderContext);
142 QSGTexture *texture = m_renderContext->createTexture(image);
143 texture->setFiltering(m_filtering);
144 m_textures.append(texture);
145 node->setTargetRect(rect);
146 node->setInnerTargetRect(rect);
147 node->setTexture(texture);
148 node->setFiltering(m_filtering);
149 appendChildNode(node);
153void QSGInternalTextNode::doAddTextDocument(QPointF position, QTextDocument *textDocument,
154 int selectionStart,
int selectionEnd)
156 QQuickTextNodeEngine engine;
157 engine.setTextColor(m_color);
158 engine.setSelectedTextColor(m_selectionTextColor);
159 engine.setSelectionColor(m_selectionColor);
160 engine.setAnchorColor(m_linkColor);
161 engine.setPosition(position);
162 engine.setDevicePixelRatio(m_devicePixelRatio);
164 QList<QTextFrame *> frames;
165 frames.append(textDocument->rootFrame());
166 while (!frames.isEmpty()) {
167 QTextFrame *textFrame = frames.takeFirst();
168 frames.append(textFrame->childFrames());
170 engine.addFrameDecorations(textDocument, textFrame);
172 if (textFrame->firstPosition() > textFrame->lastPosition()
173 && textFrame->frameFormat().position() != QTextFrameFormat::InFlow) {
174 const int pos = textFrame->firstPosition() - 1;
175 auto *a =
static_cast<QtPrivate::ProtectedLayoutAccessor *>(textDocument->documentLayout());
176 QTextCharFormat format = a->formatAccessor(pos);
177 QRectF rect = a->frameBoundingRect(textFrame);
179 QTextBlock block = textFrame->firstCursorPosition().block();
180 engine.setCurrentLine(block.layout()->lineForTextPosition(pos - block.position()));
181 engine.addTextObject(block, rect.topLeft(), format, QQuickTextNodeEngine::Unselected, textDocument,
182 pos, textFrame->frameFormat().position());
184 QTextFrame::iterator it = textFrame->begin();
186 while (!it.atEnd()) {
187 Q_ASSERT(!engine.currentLine().isValid());
189 QTextBlock block = it.currentBlock();
190 engine.addTextBlock(textDocument, block, position, m_color, m_linkColor, selectionStart, selectionEnd,
191 (textDocument->characterCount() > QQuickTextPrivate::largeTextSizeThreshold ?
192 m_viewport : QRectF()));
198 engine.addToSceneGraph(
this, QQuickText::TextStyle(m_textStyle), m_styleColor);
201void QSGInternalTextNode::doAddTextLayout(QPointF position, QTextLayout *textLayout,
202 int selectionStart,
int selectionEnd,
203 int lineStart,
int lineCount)
205 QQuickTextNodeEngine engine;
206 engine.setTextColor(m_color);
207 engine.setSelectedTextColor(m_selectionTextColor);
208 engine.setSelectionColor(m_selectionColor);
209 engine.setAnchorColor(m_linkColor);
210 engine.setPosition(position);
211 engine.setDevicePixelRatio(m_devicePixelRatio);
214 int preeditLength = textLayout->preeditAreaText().size();
215 int preeditPosition = textLayout->preeditAreaPosition();
218 QVarLengthArray<QTextLayout::FormatRange> colorChanges;
219 engine.mergeFormats(textLayout, &colorChanges);
221 lineCount = lineCount >= 0
222 ? qMin(lineStart + lineCount, textLayout->lineCount())
223 : textLayout->lineCount();
225 bool inViewport =
false;
226 for (
int i=lineStart; i<lineCount; ++i) {
227 QTextLine line = textLayout->lineAt(i);
229 int start = line.textStart();
230 int length = line.textLength();
231 int end = start + length;
234 if (preeditPosition >= 0
235 && preeditPosition >= start
236 && preeditPosition < end) {
237 end += preeditLength;
241 if (m_viewport.isNull() || (line.y() + line.height() > m_viewport.top() && line.y() < m_viewport.bottom())) {
242 if (!inViewport && !m_viewport.isNull()) {
243 m_firstLineInViewport = i;
244 qCDebug(lcVP) <<
"first line in viewport" << i <<
"@" << line.y();
247 engine.setCurrentLine(line);
248 engine.addGlyphsForRanges(colorChanges, start, end, selectionStart, selectionEnd);
249 }
else if (inViewport) {
250 Q_ASSERT(!m_viewport.isNull());
251 m_firstLinePastViewport = i;
252 qCDebug(lcVP) <<
"first omitted line past bottom of viewport" << i <<
"@" << line.y();
257 engine.addToSceneGraph(
this, QQuickText::TextStyle(m_textStyle), m_styleColor);