46void QSGDefaultGlyphNode::update()
51 const auto *fontEngine = QRawFontPrivate::get(font)->fontEngine;
52 const bool isColorFont = fontEngine->glyphFormat == QFontEngine::Format_ARGB;
54 if (m_style == QQuickText::Normal || isColorFont) {
55 QFontEngine::GlyphFormat glyphFormat;
59 glyphFormat = QFontEngine::Format_None;
61 switch (m_preferredAntialiasingMode) {
62 case GrayAntialiasing:
63 glyphFormat = QFontEngine::Format_A8;
65 case HighQualitySubPixelAntialiasing:
66 case LowQualitySubPixelAntialiasing:
67 glyphFormat = QFontEngine::Format_A32;
70 glyphFormat = QFontEngine::Format_None;
75 const auto rgbColor = m_color.toRgb();
76 m_material =
new QSGTextMaskMaterial(m_context, QVector4D(rgbColor.redF(), rgbColor.greenF(), rgbColor.blueF(), rgbColor.alphaF()), font, glyphFormat);
77 }
else if (m_style == QQuickText::Outline) {
80 m_material = material;
84 if (m_style == QQuickText::Sunken) {
85 material->setStyleShift(QVector2D(0, -1));
87 }
else if (m_style == QQuickText::Raised) {
88 material->setStyleShift(QVector2D(0, 1));
92 m_material = material;
99 textMaskMaterial->populate(m_position, m_glyphs.glyphIndexes(), m_glyphs.positions(), geometry(),
100 &boundingRect, &m_baseLine, margins);
101 setBoundingRect(boundingRect);
103 setMaterial(m_material);
104 markDirty(DirtyGeometry);
116void QSGDefaultGlyphNode::updateGeometry()
120 QSGNode *subnode = firstChild();
124 m_nodesToDelete.append(subnode);
125 subnode = subnode->nextSibling();
127 removeAllChildNodes();
131 const QList<quint32> indexes = m_glyphs.glyphIndexes();
132 const QList<QPointF> positions = m_glyphs.positions();
134 const int maxGlyphs = (USHRT_MAX + 1) / 4;
135 const int maxVertices = maxGlyphs * 4;
136 const int maxIndexes = maxGlyphs * 6;
138 for (
int i = 0; i < indexes.size(); ++i) {
139 const int glyphIndex = indexes.at(i);
140 const QPointF position = positions.at(i);
147 if (i >= maxGlyphs) {
148 glyphInfo.indexes.append(glyphIndex);
149 glyphInfo.positions.append(position);
154 if (!glyphInfo.indexes.isEmpty()) {
155 QGlyphRun subNodeGlyphRun(m_glyphs);
156 subNodeGlyphRun.setGlyphIndexes(glyphInfo.indexes);
157 subNodeGlyphRun.setPositions(glyphInfo.positions);
159 QSGDefaultGlyphNode *subNode =
new QSGDefaultGlyphNode(m_context);
160 subNode->setGlyphNodeType(SubGlyphNode);
161 subNode->setColor(m_color);
162 subNode->setStyle(m_style);
163 subNode->setStyleColor(m_styleColor);
164 subNode->setGlyphs(m_position, subNodeGlyphRun);
166 subNode->updateGeometry();
167 appendChildNode(subNode);
169 QSGGeometry *g = geometry();
171 QSGGeometry::TexturedPoint2D *vertexData = g->vertexDataAsTexturedPoint2D();
172 quint16 *indexData = g->indexDataAsUShort();
174 QList<QSGGeometry::TexturedPoint2D> tempVertexData(maxVertices);
175 QList<quint16> tempIndexData(maxIndexes);
177 for (
int i = 0; i < maxGlyphs; i++) {
178 tempVertexData[i * 4 + 0] = vertexData[i * 4 + 0];
179 tempVertexData[i * 4 + 1] = vertexData[i * 4 + 1];
180 tempVertexData[i * 4 + 2] = vertexData[i * 4 + 2];
181 tempVertexData[i * 4 + 3] = vertexData[i * 4 + 3];
183 tempIndexData[i * 6 + 0] = indexData[i * 6 + 0];
184 tempIndexData[i * 6 + 1] = indexData[i * 6 + 1];
185 tempIndexData[i * 6 + 2] = indexData[i * 6 + 2];
186 tempIndexData[i * 6 + 3] = indexData[i * 6 + 3];
187 tempIndexData[i * 6 + 4] = indexData[i * 6 + 4];
188 tempIndexData[i * 6 + 5] = indexData[i * 6 + 5];
191 g->allocate(maxVertices, maxIndexes);
192 vertexData = g->vertexDataAsTexturedPoint2D();
193 indexData = g->indexDataAsUShort();
195 for (
int i = 0; i < maxGlyphs; i++) {
196 vertexData[i * 4 + 0] = tempVertexData[i * 4 + 0];
197 vertexData[i * 4 + 1] = tempVertexData[i * 4 + 1];
198 vertexData[i * 4 + 2] = tempVertexData[i * 4 + 2];
199 vertexData[i * 4 + 3] = tempVertexData[i * 4 + 3];
201 indexData[i * 6 + 0] = tempIndexData[i * 6 + 0];
202 indexData[i * 6 + 1] = tempIndexData[i * 6 + 1];
203 indexData[i * 6 + 2] = tempIndexData[i * 6 + 2];
204 indexData[i * 6 + 3] = tempIndexData[i * 6 + 3];
205 indexData[i * 6 + 4] = tempIndexData[i * 6 + 4];
206 indexData[i * 6 + 5] = tempIndexData[i * 6 + 5];
210 m_dirtyGeometry =
false;