45void QSGDefaultGlyphNode::update()
50 const auto *fontEngine = QRawFontPrivate::get(font)->fontEngine;
51 const bool isColorFont = fontEngine->glyphFormat == QFontEngine::Format_ARGB;
53 if (m_style == QQuickText::Normal || isColorFont) {
54 QFontEngine::GlyphFormat glyphFormat;
58 glyphFormat = QFontEngine::Format_None;
60 switch (m_preferredAntialiasingMode) {
61 case GrayAntialiasing:
62 glyphFormat = QFontEngine::Format_A8;
64 case HighQualitySubPixelAntialiasing:
65 case LowQualitySubPixelAntialiasing:
66 glyphFormat = QFontEngine::Format_A32;
69 glyphFormat = QFontEngine::Format_None;
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);
79 m_material = material;
83 if (m_style == QQuickText::Sunken) {
84 material->setStyleShift(QVector2D(0, -1));
86 }
else if (m_style == QQuickText::Raised) {
87 material->setStyleShift(QVector2D(0, 1));
90 material->setStyleColor(m_styleColor);
91 m_material = material;
95 textMaskMaterial->setColor(m_color);
98 textMaskMaterial->populate(m_position, m_glyphs.glyphIndexes(), m_glyphs.positions(), geometry(),
99 &boundingRect, &m_baseLine, margins);
100 setBoundingRect(boundingRect);
102 setMaterial(m_material);
103 markDirty(DirtyGeometry);
115void QSGDefaultGlyphNode::updateGeometry()
119 QSGNode *subnode = firstChild();
123 m_nodesToDelete.append(subnode);
124 subnode = subnode->nextSibling();
126 removeAllChildNodes();
130 const QVector<quint32> indexes = m_glyphs.glyphIndexes();
131 const QVector<QPointF> positions = m_glyphs.positions();
133 const int maxGlyphs = (USHRT_MAX + 1) / 4;
134 const int maxVertices = maxGlyphs * 4;
135 const int maxIndexes = maxGlyphs * 6;
137 for (
int i = 0; i < indexes.size(); ++i) {
138 const int glyphIndex = indexes.at(i);
139 const QPointF position = positions.at(i);
146 if (i >= maxGlyphs) {
147 glyphInfo.indexes.append(glyphIndex);
148 glyphInfo.positions.append(position);
153 if (!glyphInfo.indexes.isEmpty()) {
154 QGlyphRun subNodeGlyphRun(m_glyphs);
155 subNodeGlyphRun.setGlyphIndexes(glyphInfo.indexes);
156 subNodeGlyphRun.setPositions(glyphInfo.positions);
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);
165 subNode->updateGeometry();
166 appendChildNode(subNode);
168 QSGGeometry *g = geometry();
170 QSGGeometry::TexturedPoint2D *vertexData = g->vertexDataAsTexturedPoint2D();
171 quint16 *indexData = g->indexDataAsUShort();
173 QVector<QSGGeometry::TexturedPoint2D> tempVertexData(maxVertices);
174 QVector<quint16> tempIndexData(maxIndexes);
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];
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];
190 g->allocate(maxVertices, maxIndexes);
191 vertexData = g->vertexDataAsTexturedPoint2D();
192 indexData = g->indexDataAsUShort();
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];
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];
209 m_dirtyGeometry =
false;