78 QRawFont font = glyphs.rawFont();
79 m_originalPosition = position;
80 m_position = QPointF(position.x(), position.y() - font.ascent());
83 m_dirtyGeometry =
true;
84 m_dirtyMaterial =
true;
85 setFlag(UsePreprocess);
87 QSGDistanceFieldGlyphCache *oldCache = m_glyph_cache;
88 m_glyph_cache = m_context->distanceFieldGlyphCache(m_glyphs.rawFont(), m_renderTypeQuality);
90 if (m_glyphNodeType == SubGlyphNode)
93 if (m_glyph_cache != oldCache) {
95 oldCache->unregisterGlyphNode(
this);
98 m_glyph_cache->registerGlyphNode(
this);
101 m_glyph_cache->populate(glyphs.glyphIndexes());
103 const QList<quint32> glyphIndexes = m_glyphs.glyphIndexes();
104 for (
int i = 0; i < glyphIndexes.size(); ++i)
105 m_allGlyphIndexesLookup.insert(glyphIndexes.at(i));
106 qCDebug(lcSgText,
"inserting %" PRIdQSIZETYPE
" glyphs, %" PRIdQSIZETYPE
" unique",
108 m_allGlyphIndexesLookup.size());
109#ifdef QSG_RUNTIME_DESCRIPTION
110 qsgnode_set_description(
this, QString::number(glyphs.glyphIndexes().count()) + QStringLiteral(
" DF glyphs: ") +
111 m_glyphs.rawFont().familyName() + QStringLiteral(
" ") + QString::number(m_glyphs.rawFont().pixelSize()));
166 QSGNode *subnode = firstChild();
167 QSGNode *nextNode =
nullptr;
169 nextNode = subnode->nextSibling();
174 QSGGeometry *g = geometry();
176 Q_ASSERT(g->indexType() == QSGGeometry::UnsignedShortType);
177 m_glyphsInOtherTextures.clear();
179 const QList<quint32> indexes = m_glyphs.glyphIndexes();
180 const QList<QPointF> positions = m_glyphs.positions();
181 qreal fontPixelSize = m_glyphs.rawFont().pixelSize();
185 QVarLengthArray<QSGGeometry::TexturedPoint2D, 256> vp;
186 QVarLengthArray<ushort, 384> ip;
187 const qsizetype maxIndexCount = (std::numeric_limits<quint16>::max() - 1) / 4;
188 const qsizetype maxVertexCount = maxIndexCount * 4;
189 const auto likelyGlyphCount = qMin(indexes.size(), maxIndexCount);
190 vp.reserve(likelyGlyphCount * 4);
191 ip.reserve(likelyGlyphCount * 6);
193 qreal maxTexMargin = m_glyph_cache->distanceFieldRadius();
194 qreal fontScale = m_glyph_cache->fontScale(fontPixelSize);
196 qreal texMargin = margin / fontScale;
197 if (texMargin > maxTexMargin) {
198 texMargin = maxTexMargin;
199 margin = maxTexMargin * fontScale;
202 for (
int i = 0; i < indexes.size(); ++i) {
203 const int glyphIndex = indexes.at(i);
204 QSGDistanceFieldGlyphCache::TexCoord c = m_glyph_cache->glyphTexCoord(glyphIndex);
209 const QPointF position = positions.at(i);
211 const QSGDistanceFieldGlyphCache::Texture *texture = m_glyph_cache->glyphTexture(glyphIndex);
212 if (texture->texture && !m_texture)
224 if (m_texture != texture || vp.size() >= maxVertexCount) {
225 if (m_glyphNodeType == RootGlyphNode && texture->texture) {
226 GlyphInfo &glyphInfo = m_glyphsInOtherTextures[texture];
227 glyphInfo.indexes.append(glyphIndex);
228 glyphInfo.positions.append(position);
229 }
else if (vp.size() >= maxVertexCount && m_glyphNodeType == SubGlyphNode) {
235 QSGDistanceFieldGlyphCache::Metrics metrics = m_glyph_cache->glyphMetrics(glyphIndex, fontPixelSize);
237 if (!metrics.isNull() && !c.isNull()) {
238 metrics.width += margin * 2;
239 metrics.height += margin * 2;
240 metrics.baselineX -= margin;
241 metrics.baselineY += margin;
242 c.xMargin -= texMargin;
243 c.yMargin -= texMargin;
244 c.width += texMargin * 2;
245 c.height += texMargin * 2;
248 qreal x = position.x() + metrics.baselineX + m_position.x();
249 qreal y = position.y() - metrics.baselineY + m_position.y();
251 m_boundingRect |= QRectF(x, y, metrics.width, metrics.height);
254 float cx2 = x + metrics.width;
256 float cy2 = y + metrics.height;
258 float tx1 = c.x + c.xMargin;
259 float tx2 = tx1 + c.width;
260 float ty1 = c.y + c.yMargin;
261 float ty2 = ty1 + c.height;
263 if (m_baseLine.isNull())
264 m_baseLine = position;
268 QSGGeometry::TexturedPoint2D v1;
269 v1.set(cx1, cy1, tx1, ty1);
270 QSGGeometry::TexturedPoint2D v2;
271 v2.set(cx2, cy1, tx2, ty1);
272 QSGGeometry::TexturedPoint2D v3;
273 v3.set(cx1, cy2, tx1, ty2);
274 QSGGeometry::TexturedPoint2D v4;
275 v4.set(cx2, cy2, tx2, ty2);
289 if (m_glyphNodeType == SubGlyphNode) {
290 Q_ASSERT(m_glyphsInOtherTextures.isEmpty());
292 if (!m_glyphsInOtherTextures.isEmpty())
293 qCDebug(lcSgText,
"%" PRIdQSIZETYPE
" 'other' textures", m_glyphsInOtherTextures.size());
294 QHash<
const QSGDistanceFieldGlyphCache::Texture *, GlyphInfo>::const_iterator ite = m_glyphsInOtherTextures.constBegin();
295 while (ite != m_glyphsInOtherTextures.constEnd()) {
296 QGlyphRun subNodeGlyphRun(m_glyphs);
297 for (
int i = 0; i < ite->indexes.size(); i += maxIndexCount) {
298 int len = qMin(maxIndexCount, ite->indexes.size() - i);
299 subNodeGlyphRun.setRawData(ite->indexes.constData() + i, ite->positions.constData() + i, len);
300 qCDebug(lcSgText) <<
"subNodeGlyphRun has" << len <<
"positions:"
301 << *(ite->positions.constData() + i) <<
"->" << *(ite->positions.constData() + i + len - 1);
304 subNode->setGlyphNodeType(SubGlyphNode);
305 subNode->setColor(m_color);
306 subNode->setStyle(m_style);
307 subNode->setStyleColor(m_styleColor);
308 subNode->setPreferredAntialiasingMode(m_antialiasingMode);
309 subNode->setGlyphs(m_originalPosition, subNodeGlyphRun);
312 appendChildNode(subNode);
318 s_totalAllocation += vp.size() *
sizeof(QSGGeometry::TexturedPoint2D) + ip.size() *
sizeof(quint16);
319 qCDebug(lcSgText) <<
"allocating for" << vp.size() <<
"vtx (reserved" << likelyGlyphCount * 4 <<
"):" << vp.size() *
sizeof(QSGGeometry::TexturedPoint2D)
320 <<
"bytes;" << ip.size() <<
"idx:" << ip.size() *
sizeof(quint16) <<
"bytes; total bytes so far" << s_totalAllocation;
321 g->allocate(vp.size(), ip.size());
322 memcpy(g->vertexDataAsTexturedPoint2D(), vp.constData(), vp.size() *
sizeof(QSGGeometry::TexturedPoint2D));
323 memcpy(g->indexDataAsUShort(), ip.constData(), ip.size() *
sizeof(quint16));
325 setBoundingRect(m_boundingRect);
326 markDirty(DirtyGeometry);
327 m_dirtyGeometry =
false;
329 m_material->setTexture(m_texture);