77 QRawFont font = glyphs.rawFont();
78 m_originalPosition = position;
79 m_position = QPointF(position.x(), position.y() - font.ascent());
82 m_dirtyGeometry =
true;
83 m_dirtyMaterial =
true;
84 setFlag(UsePreprocess);
86 QSGDistanceFieldGlyphCache *oldCache = m_glyph_cache;
87 m_glyph_cache = m_context->distanceFieldGlyphCache(m_glyphs.rawFont(), m_renderTypeQuality);
89 if (m_glyphNodeType == SubGlyphNode)
92 if (m_glyph_cache != oldCache) {
94 oldCache->unregisterGlyphNode(
this);
96 m_glyph_cache->registerGlyphNode(
this);
99 m_glyph_cache->populate(glyphs.glyphIndexes());
101 const QVector<quint32> glyphIndexes = m_glyphs.glyphIndexes();
102 for (
int i = 0; i < glyphIndexes.size(); ++i)
103 m_allGlyphIndexesLookup.insert(glyphIndexes.at(i));
104 qCDebug(lcSgText,
"inserting %" PRIdQSIZETYPE
" glyphs, %" PRIdQSIZETYPE
" unique",
106 m_allGlyphIndexesLookup.size());
107#ifdef QSG_RUNTIME_DESCRIPTION
108 qsgnode_set_description(
this, QString::number(glyphs.glyphIndexes().count()) + QStringLiteral(
" DF glyphs: ") +
109 m_glyphs.rawFont().familyName() + QStringLiteral(
" ") + QString::number(m_glyphs.rawFont().pixelSize()));
164 QSGNode *subnode = firstChild();
165 QSGNode *nextNode =
nullptr;
167 nextNode = subnode->nextSibling();
172 QSGGeometry *g = geometry();
174 Q_ASSERT(g->indexType() == QSGGeometry::UnsignedShortType);
175 m_glyphsInOtherTextures.clear();
177 const QVector<quint32> indexes = m_glyphs.glyphIndexes();
178 const QVector<QPointF> positions = m_glyphs.positions();
179 qreal fontPixelSize = m_glyphs.rawFont().pixelSize();
183 QVarLengthArray<QSGGeometry::TexturedPoint2D, 256> vp;
184 QVarLengthArray<ushort, 384> ip;
185 const qsizetype maxIndexCount = (std::numeric_limits<quint16>::max() - 1) / 4;
186 const qsizetype maxVertexCount = maxIndexCount * 4;
187 const auto likelyGlyphCount = qMin(indexes.size(), maxIndexCount);
188 vp.reserve(likelyGlyphCount * 4);
189 ip.reserve(likelyGlyphCount * 6);
191 qreal maxTexMargin = m_glyph_cache->distanceFieldRadius();
192 qreal fontScale = m_glyph_cache->fontScale(fontPixelSize);
194 qreal texMargin = margin / fontScale;
195 if (texMargin > maxTexMargin) {
196 texMargin = maxTexMargin;
197 margin = maxTexMargin * fontScale;
200 for (
int i = 0; i < indexes.size(); ++i) {
201 const int glyphIndex = indexes.at(i);
202 QSGDistanceFieldGlyphCache::TexCoord c = m_glyph_cache->glyphTexCoord(glyphIndex);
207 const QPointF position = positions.at(i);
209 const QSGDistanceFieldGlyphCache::Texture *texture = m_glyph_cache->glyphTexture(glyphIndex);
210 if (texture->texture && !m_texture)
222 if (m_texture != texture || vp.size() >= maxVertexCount) {
223 if (m_glyphNodeType == RootGlyphNode && texture->texture) {
224 GlyphInfo &glyphInfo = m_glyphsInOtherTextures[texture];
225 glyphInfo.indexes.append(glyphIndex);
226 glyphInfo.positions.append(position);
227 }
else if (vp.size() >= maxVertexCount && m_glyphNodeType == SubGlyphNode) {
233 QSGDistanceFieldGlyphCache::Metrics metrics = m_glyph_cache->glyphMetrics(glyphIndex, fontPixelSize);
235 if (!metrics.isNull() && !c.isNull()) {
236 metrics.width += margin * 2;
237 metrics.height += margin * 2;
238 metrics.baselineX -= margin;
239 metrics.baselineY += margin;
240 c.xMargin -= texMargin;
241 c.yMargin -= texMargin;
242 c.width += texMargin * 2;
243 c.height += texMargin * 2;
246 qreal x = position.x() + metrics.baselineX + m_position.x();
247 qreal y = position.y() - metrics.baselineY + m_position.y();
249 m_boundingRect |= QRectF(x, y, metrics.width, metrics.height);
252 float cx2 = x + metrics.width;
254 float cy2 = y + metrics.height;
256 float tx1 = c.x + c.xMargin;
257 float tx2 = tx1 + c.width;
258 float ty1 = c.y + c.yMargin;
259 float ty2 = ty1 + c.height;
261 if (m_baseLine.isNull())
262 m_baseLine = position;
266 QSGGeometry::TexturedPoint2D v1;
267 v1.set(cx1, cy1, tx1, ty1);
268 QSGGeometry::TexturedPoint2D v2;
269 v2.set(cx2, cy1, tx2, ty1);
270 QSGGeometry::TexturedPoint2D v3;
271 v3.set(cx1, cy2, tx1, ty2);
272 QSGGeometry::TexturedPoint2D v4;
273 v4.set(cx2, cy2, tx2, ty2);
287 if (m_glyphNodeType == SubGlyphNode) {
288 Q_ASSERT(m_glyphsInOtherTextures.isEmpty());
290 if (!m_glyphsInOtherTextures.isEmpty())
291 qCDebug(lcSgText,
"%" PRIdQSIZETYPE
" 'other' textures", m_glyphsInOtherTextures.size());
292 QHash<
const QSGDistanceFieldGlyphCache::Texture *, GlyphInfo>::const_iterator ite = m_glyphsInOtherTextures.constBegin();
293 while (ite != m_glyphsInOtherTextures.constEnd()) {
294 QGlyphRun subNodeGlyphRun(m_glyphs);
295 for (
int i = 0; i < ite->indexes.size(); i += maxIndexCount) {
296 int len = qMin(maxIndexCount, ite->indexes.size() - i);
297 subNodeGlyphRun.setRawData(ite->indexes.constData() + i, ite->positions.constData() + i, len);
298 qCDebug(lcSgText) <<
"subNodeGlyphRun has" << len <<
"positions:"
299 << *(ite->positions.constData() + i) <<
"->" << *(ite->positions.constData() + i + len - 1);
302 subNode->setGlyphNodeType(SubGlyphNode);
303 subNode->setColor(m_color);
304 subNode->setStyle(m_style);
305 subNode->setStyleColor(m_styleColor);
306 subNode->setPreferredAntialiasingMode(m_antialiasingMode);
307 subNode->setGlyphs(m_originalPosition, subNodeGlyphRun);
310 appendChildNode(subNode);
316 s_totalAllocation += vp.size() *
sizeof(QSGGeometry::TexturedPoint2D) + ip.size() *
sizeof(quint16);
317 qCDebug(lcSgText) <<
"allocating for" << vp.size() <<
"vtx (reserved" << likelyGlyphCount * 4 <<
"):" << vp.size() *
sizeof(QSGGeometry::TexturedPoint2D)
318 <<
"bytes;" << ip.size() <<
"idx:" << ip.size() *
sizeof(quint16) <<
"bytes; total bytes so far" << s_totalAllocation;
319 g->allocate(vp.size(), ip.size());
320 memcpy(g->vertexDataAsTexturedPoint2D(), vp.constData(), vp.size() *
sizeof(QSGGeometry::TexturedPoint2D));
321 memcpy(g->indexDataAsUShort(), ip.constData(), ip.size() *
sizeof(quint16));
323 setBoundingRect(m_boundingRect);
324 markDirty(DirtyGeometry);
325 m_dirtyGeometry =
false;
327 m_material->setTexture(m_texture);