Qt 6.x
The Qt SDK
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
35{
37}
38
40{
42 m_dirtyGeometry = true;
43}
44
46{
48 QMargins margins(0, 0, 0, 0);
49
51 QFontEngine::GlyphFormat glyphFormat;
52
53 // Don't try to override glyph format of color fonts
54 if (QRawFontPrivate::get(font)->fontEngine->glyphFormat == QFontEngine::Format_ARGB) {
55 glyphFormat = QFontEngine::Format_None;
56 } else {
57 switch (m_preferredAntialiasingMode) {
59 glyphFormat = QFontEngine::Format_A8;
60 break;
63 glyphFormat = QFontEngine::Format_A32;
64 break;
65 default:
66 glyphFormat = QFontEngine::Format_None;
67 break;
68 }
69 }
70
71 const auto rgbColor = m_color.toRgb();
72 m_material = new QSGTextMaskMaterial(m_context, QVector4D(rgbColor.redF(), rgbColor.greenF(), rgbColor.blueF(), rgbColor.alphaF()), font, glyphFormat);
73 } else if (m_style == QQuickText::Outline) {
75 material->setStyleColor(m_styleColor);
77 margins = QMargins(1, 1, 1, 1);
78 } else {
81 material->setStyleShift(QVector2D(0, -1));
82 margins.setTop(1);
83 } else if (m_style == QQuickText::Raised) {
84 material->setStyleShift(QVector2D(0, 1));
85 margins.setBottom(1);
86 }
87 material->setStyleColor(m_styleColor);
89 }
90
91 QSGTextMaskMaterial *textMaskMaterial = static_cast<QSGTextMaskMaterial *>(m_material);
92 textMaskMaterial->setColor(m_color);
93
96 &boundingRect, &m_baseLine, margins);
98
101}
102
104{
105 qDeleteAll(m_nodesToDelete);
106 m_nodesToDelete.clear();
107
108 if (m_dirtyGeometry)
110}
111
113{
114 // Remove previously created sub glyph nodes
115 // We assume all the children are sub glyph nodes
116 QSGNode *subnode = firstChild();
117 while (subnode) {
118 // We can't delete the node now as it might be in the preprocess list
119 // It will be deleted in the next preprocess
120 m_nodesToDelete.append(subnode);
121 subnode = subnode->nextSibling();
122 }
124
125 GlyphInfo glyphInfo;
126
127 const QVector<quint32> indexes = m_glyphs.glyphIndexes();
129
130 const int maxGlyphs = (USHRT_MAX + 1) / 4; // 16384
131 const int maxVertices = maxGlyphs * 4; // 65536
132 const int maxIndexes = maxGlyphs * 6; // 98304
133
134 for (int i = 0; i < indexes.size(); ++i) {
135 const int glyphIndex = indexes.at(i);
136 const QPointF position = positions.at(i);
137
138 // As we use UNSIGNED_SHORT indexing in the geometry, we overload the
139 // "glyphsInOtherNodes" concept as overflow for if there are more than
140 // 65536 (16384 * 4) vertices to render which would otherwise exceed
141 // the maximum index size. This will cause sub-nodes to be recursively
142 // created to handle any number of glyphs.
143 if (i >= maxGlyphs) {
144 glyphInfo.indexes.append(glyphIndex);
145 glyphInfo.positions.append(position);
146 continue;
147 }
148 }
149
150 if (!glyphInfo.indexes.isEmpty()) {
151 QGlyphRun subNodeGlyphRun(m_glyphs);
152 subNodeGlyphRun.setGlyphIndexes(glyphInfo.indexes);
153 subNodeGlyphRun.setPositions(glyphInfo.positions);
154
155 QSGDefaultGlyphNode *subNode = new QSGDefaultGlyphNode(m_context);
156 subNode->setGlyphNodeType(SubGlyphNode);
157 subNode->setColor(m_color);
158 subNode->setStyle(m_style);
159 subNode->setStyleColor(m_styleColor);
160 subNode->setGlyphs(m_position, subNodeGlyphRun);
161 subNode->update();
162 subNode->updateGeometry(); // we have to explicitly call this now as preprocess won't be called before it's rendered
163 appendChildNode(subNode);
164
166
167 QSGGeometry::TexturedPoint2D *vertexData = g->vertexDataAsTexturedPoint2D();
168 quint16 *indexData = g->indexDataAsUShort();
169
170 QVector<QSGGeometry::TexturedPoint2D> tempVertexData(maxVertices);
171 QVector<quint16> tempIndexData(maxIndexes);
172
173 for (int i = 0; i < maxGlyphs; i++) {
174 tempVertexData[i * 4 + 0] = vertexData[i * 4 + 0];
175 tempVertexData[i * 4 + 1] = vertexData[i * 4 + 1];
176 tempVertexData[i * 4 + 2] = vertexData[i * 4 + 2];
177 tempVertexData[i * 4 + 3] = vertexData[i * 4 + 3];
178
179 tempIndexData[i * 6 + 0] = indexData[i * 6 + 0];
180 tempIndexData[i * 6 + 1] = indexData[i * 6 + 1];
181 tempIndexData[i * 6 + 2] = indexData[i * 6 + 2];
182 tempIndexData[i * 6 + 3] = indexData[i * 6 + 3];
183 tempIndexData[i * 6 + 4] = indexData[i * 6 + 4];
184 tempIndexData[i * 6 + 5] = indexData[i * 6 + 5];
185 }
186
187 g->allocate(maxVertices, maxIndexes);
188 vertexData = g->vertexDataAsTexturedPoint2D();
189 indexData = g->indexDataAsUShort();
190
191 for (int i = 0; i < maxGlyphs; i++) {
192 vertexData[i * 4 + 0] = tempVertexData[i * 4 + 0];
193 vertexData[i * 4 + 1] = tempVertexData[i * 4 + 1];
194 vertexData[i * 4 + 2] = tempVertexData[i * 4 + 2];
195 vertexData[i * 4 + 3] = tempVertexData[i * 4 + 3];
196
197 indexData[i * 6 + 0] = tempIndexData[i * 6 + 0];
198 indexData[i * 6 + 1] = tempIndexData[i * 6 + 1];
199 indexData[i * 6 + 2] = tempIndexData[i * 6 + 2];
200 indexData[i * 6 + 3] = tempIndexData[i * 6 + 3];
201 indexData[i * 6 + 4] = tempIndexData[i * 6 + 4];
202 indexData[i * 6 + 5] = tempIndexData[i * 6 + 5];
203 }
204 }
205
206 m_dirtyGeometry = false;
207}
208
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
void setPositions(const QList< QPointF > &positions)
Sets the positions of the edge of the baseline for each glyph in this set of glyph indexes to positio...
QList< quint32 > glyphIndexes() const
Returns the glyph indexes for this QGlyphRun object.
QRawFont rawFont() const
Returns the font selected for this QGlyphRun object.
void setGlyphIndexes(const QList< quint32 > &glyphIndexes)
Set the glyph indexes for this QGlyphRun object to glyphIndexes.
QList< QPointF > positions() const
Returns the position of the edge of the baseline for each glyph in this set of glyph indexes.
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
\inmodule QtCore
Definition qmargins.h:23
constexpr void setTop(int top) noexcept
Sets the Top margin to Top.
Definition qmargins.h:126
constexpr void setBottom(int bottom) noexcept
Sets the bottom margin to bottom.
Definition qmargins.h:132
\inmodule QtCore\reentrant
Definition qpoint.h:214
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:483
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
void setStyle(QQuickText::TextStyle) override
QQuickText::TextStyle m_style
void setStyleColor(const QColor &) override
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:197
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:925
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
QSGNode * nextSibling() const
Returns the node after this in the parent's list of children.
Definition qsgnode.h:107
@ 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:396
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:622
void setFlag(Flag, bool=true)
Sets the flag f on this node if enabled is true; otherwise clears the flag.
Definition qsgnode.cpp:584
void removeAllChildNodes()
Removes all child nodes from this node's list of children.
Definition qsgnode.cpp:525
void setColor(const QColor &c)
void populate(const QPointF &position, const QVector< quint32 > &glyphIndexes, const QVector< QPointF > &glyphPositions, QSGGeometry *geometry, QRectF *boundingRect, QPointF *baseLine, const QMargins &margins=QMargins(0, 0, 0, 0))
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
GLboolean GLboolean g
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
unsigned short quint16
Definition qtypes.h:43
The QSGGeometry::TexturedPoint2D struct is a convenience struct for accessing 2D Points with texture ...
Definition qsggeometry.h:85