Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsgdefaultglyphnode.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <private/qrawfont_p.h>
8
10
12 : m_context(context)
13 , m_glyphNodeType(RootGlyphNode)
14 , m_dirtyGeometry(false)
15 , m_preferredAntialiasingMode(DefaultAntialiasing)
16{
18}
19
21{
22 if (m_glyphNodeType == SubGlyphNode)
23 return;
24
25 qDeleteAll(m_nodesToDelete);
26 m_nodesToDelete.clear();
27}
28
30{
31 m_preferredAntialiasingMode = mode;
32}
33
38
40{
42 m_dirtyGeometry = true;
43}
44
46{
48 QMargins margins(0, 0, 0, 0);
49
50 const auto *fontEngine = QRawFontPrivate::get(font)->fontEngine;
51 const bool isColorFont = fontEngine->glyphFormat == QFontEngine::Format_ARGB;
52
53 if (m_style == QQuickText::Normal || isColorFont) {
54 QFontEngine::GlyphFormat glyphFormat;
55
56 // Don't try to override glyph format of color fonts
57 if (isColorFont) {
58 glyphFormat = QFontEngine::Format_None;
59 } else {
60 switch (m_preferredAntialiasingMode) {
62 glyphFormat = QFontEngine::Format_A8;
63 break;
66 glyphFormat = QFontEngine::Format_A32;
67 break;
68 default:
69 glyphFormat = QFontEngine::Format_None;
70 break;
71 }
72 }
73
74 const auto rgbColor = m_color.toRgb();
75 m_material = new QSGTextMaskMaterial(m_context, QVector4D(rgbColor.redF(), rgbColor.greenF(), rgbColor.blueF(), rgbColor.alphaF()), font, glyphFormat);
76 } else if (m_style == QQuickText::Outline) {
78 material->setStyleColor(m_styleColor);
80 margins = QMargins(1, 1, 1, 1);
81 } else {
84 material->setStyleShift(QVector2D(0, -1));
85 margins.setTop(1);
86 } else if (m_style == QQuickText::Raised) {
87 material->setStyleShift(QVector2D(0, 1));
88 margins.setBottom(1);
89 }
90 material->setStyleColor(m_styleColor);
92 }
93
94 QSGTextMaskMaterial *textMaskMaterial = static_cast<QSGTextMaskMaterial *>(m_material);
95 textMaskMaterial->setColor(m_color);
96
98 textMaskMaterial->populate(m_position, m_glyphs.glyphIndexes(), m_glyphs.positions(), geometry(),
99 &boundingRect, &m_baseLine, margins);
101
104}
105
107{
108 qDeleteAll(m_nodesToDelete);
109 m_nodesToDelete.clear();
110
111 if (m_dirtyGeometry)
113}
114
116{
117 // Remove previously created sub glyph nodes
118 // We assume all the children are sub glyph nodes
119 QSGNode *subnode = firstChild();
120 while (subnode) {
121 // We can't delete the node now as it might be in the preprocess list
122 // It will be deleted in the next preprocess
123 m_nodesToDelete.append(subnode);
124 subnode = subnode->nextSibling();
125 }
127
128 GlyphInfo glyphInfo;
129
130 const QVector<quint32> indexes = m_glyphs.glyphIndexes();
131 const QVector<QPointF> positions = m_glyphs.positions();
132
133 const int maxGlyphs = (USHRT_MAX + 1) / 4; // 16384
134 const int maxVertices = maxGlyphs * 4; // 65536
135 const int maxIndexes = maxGlyphs * 6; // 98304
136
137 for (int i = 0; i < indexes.size(); ++i) {
138 const int glyphIndex = indexes.at(i);
139 const QPointF position = positions.at(i);
140
141 // As we use UNSIGNED_SHORT indexing in the geometry, we overload the
142 // "glyphsInOtherNodes" concept as overflow for if there are more than
143 // 65536 (16384 * 4) vertices to render which would otherwise exceed
144 // the maximum index size. This will cause sub-nodes to be recursively
145 // created to handle any number of glyphs.
146 if (i >= maxGlyphs) {
147 glyphInfo.indexes.append(glyphIndex);
148 glyphInfo.positions.append(position);
149 continue;
150 }
151 }
152
153 if (!glyphInfo.indexes.isEmpty()) {
154 QGlyphRun subNodeGlyphRun(m_glyphs);
155 subNodeGlyphRun.setGlyphIndexes(glyphInfo.indexes);
156 subNodeGlyphRun.setPositions(glyphInfo.positions);
157
158 QSGDefaultGlyphNode *subNode = new QSGDefaultGlyphNode(m_context);
159 subNode->setGlyphNodeType(SubGlyphNode);
160 subNode->setColor(m_color);
161 subNode->setStyle(m_style);
162 subNode->setStyleColor(m_styleColor);
163 subNode->setGlyphs(m_position, subNodeGlyphRun);
164 subNode->update();
165 subNode->updateGeometry(); // we have to explicitly call this now as preprocess won't be called before it's rendered
166 appendChildNode(subNode);
167
169
170 QSGGeometry::TexturedPoint2D *vertexData = g->vertexDataAsTexturedPoint2D();
171 quint16 *indexData = g->indexDataAsUShort();
172
173 QVector<QSGGeometry::TexturedPoint2D> tempVertexData(maxVertices);
174 QVector<quint16> tempIndexData(maxIndexes);
175
176 for (int i = 0; i < maxGlyphs; i++) {
177 tempVertexData[i * 4 + 0] = vertexData[i * 4 + 0];
178 tempVertexData[i * 4 + 1] = vertexData[i * 4 + 1];
179 tempVertexData[i * 4 + 2] = vertexData[i * 4 + 2];
180 tempVertexData[i * 4 + 3] = vertexData[i * 4 + 3];
181
182 tempIndexData[i * 6 + 0] = indexData[i * 6 + 0];
183 tempIndexData[i * 6 + 1] = indexData[i * 6 + 1];
184 tempIndexData[i * 6 + 2] = indexData[i * 6 + 2];
185 tempIndexData[i * 6 + 3] = indexData[i * 6 + 3];
186 tempIndexData[i * 6 + 4] = indexData[i * 6 + 4];
187 tempIndexData[i * 6 + 5] = indexData[i * 6 + 5];
188 }
189
190 g->allocate(maxVertices, maxIndexes);
191 vertexData = g->vertexDataAsTexturedPoint2D();
192 indexData = g->indexDataAsUShort();
193
194 for (int i = 0; i < maxGlyphs; i++) {
195 vertexData[i * 4 + 0] = tempVertexData[i * 4 + 0];
196 vertexData[i * 4 + 1] = tempVertexData[i * 4 + 1];
197 vertexData[i * 4 + 2] = tempVertexData[i * 4 + 2];
198 vertexData[i * 4 + 3] = tempVertexData[i * 4 + 3];
199
200 indexData[i * 6 + 0] = tempIndexData[i * 6 + 0];
201 indexData[i * 6 + 1] = tempIndexData[i * 6 + 1];
202 indexData[i * 6 + 2] = tempIndexData[i * 6 + 2];
203 indexData[i * 6 + 3] = tempIndexData[i * 6 + 3];
204 indexData[i * 6 + 4] = tempIndexData[i * 6 + 4];
205 indexData[i * 6 + 5] = tempIndexData[i * 6 + 5];
206 }
207 }
208
209 m_dirtyGeometry = false;
210}
211
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QColor toRgb() const noexcept
Create and returns an RGB QColor based on this color.
Definition qcolor.cpp:2035
The QGlyphRun class provides direct access to the internal glyphs in a font.
Definition qglyphrun.h:20
QList< quint32 > glyphIndexes() const
Returns the glyph indexes for this QGlyphRun object.
QRawFont rawFont() const
Returns the font selected for this QGlyphRun object.
QList< QPointF > positions() const
Returns the position of the edge of the baseline for each glyph in this set of glyph indexes.
\inmodule QtCore
Definition qmargins.h:24
constexpr void setTop(int top) noexcept
Sets the Top margin to Top.
Definition qmargins.h:122
constexpr void setBottom(int bottom) noexcept
Sets the bottom margin to bottom.
Definition qmargins.h:128
\inmodule QtCore\reentrant
Definition qpoint.h:217
static QRawFontPrivate * get(const QRawFont &font)
Definition qrawfont_p.h:104
The QRawFont class provides access to a single physical instance of a font.
Definition qrawfont.h:24
\inmodule QtCore\reentrant
Definition qrect.h:484
const QSGGeometry * geometry() const
Returns this node's geometry.
Definition qsgnode.h:160
void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override
void setColor(const QColor &color) override
QQuickText::TextStyle m_style
void setMaterialColor(const QColor &color) override
void setPreferredAntialiasingMode(AntialiasingMode) override
void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override
void preprocess() override
Override this function to do processing on the node before it is rendered.
QSGDefaultGlyphNode(QSGRenderContext *context)
QSGMaterial * material() const
Returns the material of the QSGGeometryNode.
Definition qsgnode.h:194
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:927
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
virtual void setBoundingRect(const QRectF &bounds)
virtual QRectF boundingRect() const
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
@ DirtyGeometry
Definition qsgnode.h:74
@ UsePreprocess
Definition qsgnode.h:52
void appendChildNode(QSGNode *node)
Appends node to this node's list of children.
Definition qsgnode.cpp:398
QSGNode * firstChild() const
Returns the first child of this node.
Definition qsgnode.h:105
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
Definition qsgnode.cpp:624
void setFlag(Flag, bool=true)
Sets the flag f on this node if enabled is true; otherwise clears the flag.
Definition qsgnode.cpp:586
void removeAllChildNodes()
Removes all child nodes from this node's list of children.
Definition qsgnode.cpp:527
void setColor(const QColor &c)
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:330
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
static void * context
static const QCssKnownValue positions[NumKnownPositionModes - 1]
GLenum mode
GLuint color
[2]
GLboolean GLboolean g
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
unsigned short quint16
Definition qtypes.h:48
float vertexData[]
The QSGGeometry::TexturedPoint2D struct is a convenience struct for accessing 2D Points with texture ...
Definition qsggeometry.h:85