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);
97 m_glyph_cache->registerGlyphNode(
this);
100 m_glyph_cache->populate(glyphs.glyphIndexes());
102 const QList<quint32> glyphIndexes = m_glyphs.glyphIndexes();
103 for (
int i = 0; i < glyphIndexes.size(); ++i)
104 m_allGlyphIndexesLookup.insert(glyphIndexes.at(i));
105 qCDebug(lcSgText,
"inserting %" PRIdQSIZETYPE
" glyphs, %" PRIdQSIZETYPE
" unique",
107 m_allGlyphIndexesLookup.size());
108#ifdef QSG_RUNTIME_DESCRIPTION
109 qsgnode_set_description(
this, QString::number(glyphs.glyphIndexes().count()) + QStringLiteral(
" DF glyphs: ") +
110 m_glyphs.rawFont().familyName() + QStringLiteral(
" ") + QString::number(m_glyphs.rawFont().pixelSize()));
165 QSGNode *subnode = firstChild();
166 QSGNode *nextNode =
nullptr;
168 nextNode = subnode->nextSibling();
173 QSGGeometry *g = geometry();
175 Q_ASSERT(g->indexType() == QSGGeometry::UnsignedShortType);
176 m_glyphsInOtherTextures.clear();
178 const QList<quint32> indexes = m_glyphs.glyphIndexes();
179 const QList<QPointF> positions = m_glyphs.positions();
180 qreal fontPixelSize = m_glyphs.rawFont().pixelSize();
184 QVarLengthArray<QSGGeometry::TexturedPoint2D, 256> vp;
185 QVarLengthArray<ushort, 384> ip;
186 const qsizetype maxIndexCount = (std::numeric_limits<quint16>::max() - 1) / 4;
187 const qsizetype maxVertexCount = maxIndexCount * 4;
188 const auto likelyGlyphCount = qMin(indexes.size(), maxIndexCount);
189 vp.reserve(likelyGlyphCount * 4);
190 ip.reserve(likelyGlyphCount * 6);
192 qreal maxTexMargin = m_glyph_cache->distanceFieldRadius();
193 qreal fontScale = m_glyph_cache->fontScale(fontPixelSize);
195 qreal texMargin = margin / fontScale;
196 if (texMargin > maxTexMargin) {
197 texMargin = maxTexMargin;
198 margin = maxTexMargin * fontScale;
201 for (
int i = 0; i < indexes.size(); ++i) {
202 const int glyphIndex = indexes.at(i);
203 QSGDistanceFieldGlyphCache::TexCoord c = m_glyph_cache->glyphTexCoord(glyphIndex);
208 const QPointF position = positions.at(i);
210 const QSGDistanceFieldGlyphCache::Texture *texture = m_glyph_cache->glyphTexture(glyphIndex);
211 if (texture->texture && !m_texture)
223 if (m_texture != texture || vp.size() >= maxVertexCount) {
224 if (m_glyphNodeType == RootGlyphNode && texture->texture) {
225 GlyphInfo &glyphInfo = m_glyphsInOtherTextures[texture];
226 glyphInfo.indexes.append(glyphIndex);
227 glyphInfo.positions.append(position);
228 }
else if (vp.size() >= maxVertexCount && m_glyphNodeType == SubGlyphNode) {
234 QSGDistanceFieldGlyphCache::Metrics metrics = m_glyph_cache->glyphMetrics(glyphIndex, fontPixelSize);
236 if (!metrics.isNull() && !c.isNull()) {
237 metrics.width += margin * 2;
238 metrics.height += margin * 2;
239 metrics.baselineX -= margin;
240 metrics.baselineY += margin;
241 c.xMargin -= texMargin;
242 c.yMargin -= texMargin;
243 c.width += texMargin * 2;
244 c.height += texMargin * 2;
247 qreal x = position.x() + metrics.baselineX + m_position.x();
248 qreal y = position.y() - metrics.baselineY + m_position.y();
250 m_boundingRect |= QRectF(x, y, metrics.width, metrics.height);
253 float cx2 = x + metrics.width;
255 float cy2 = y + metrics.height;
257 float tx1 = c.x + c.xMargin;
258 float tx2 = tx1 + c.width;
259 float ty1 = c.y + c.yMargin;
260 float ty2 = ty1 + c.height;
262 if (m_baseLine.isNull())
263 m_baseLine = position;
267 QSGGeometry::TexturedPoint2D v1;
268 v1.set(cx1, cy1, tx1, ty1);
269 QSGGeometry::TexturedPoint2D v2;
270 v2.set(cx2, cy1, tx2, ty1);
271 QSGGeometry::TexturedPoint2D v3;
272 v3.set(cx1, cy2, tx1, ty2);
273 QSGGeometry::TexturedPoint2D v4;
274 v4.set(cx2, cy2, tx2, ty2);
288 if (m_glyphNodeType == SubGlyphNode) {
289 Q_ASSERT(m_glyphsInOtherTextures.isEmpty());
291 if (!m_glyphsInOtherTextures.isEmpty())
292 qCDebug(lcSgText,
"%" PRIdQSIZETYPE
" 'other' textures", m_glyphsInOtherTextures.size());
293 QHash<
const QSGDistanceFieldGlyphCache::Texture *, GlyphInfo>::const_iterator ite = m_glyphsInOtherTextures.constBegin();
294 while (ite != m_glyphsInOtherTextures.constEnd()) {
295 QGlyphRun subNodeGlyphRun(m_glyphs);
296 for (
int i = 0; i < ite->indexes.size(); i += maxIndexCount) {
297 int len = qMin(maxIndexCount, ite->indexes.size() - i);
298 subNodeGlyphRun.setRawData(ite->indexes.constData() + i, ite->positions.constData() + i, len);
299 qCDebug(lcSgText) <<
"subNodeGlyphRun has" << len <<
"positions:"
300 << *(ite->positions.constData() + i) <<
"->" << *(ite->positions.constData() + i + len - 1);
303 subNode->setGlyphNodeType(SubGlyphNode);
304 subNode->setColor(m_color);
305 subNode->setStyle(m_style);
306 subNode->setStyleColor(m_styleColor);
307 subNode->setPreferredAntialiasingMode(m_antialiasingMode);
308 subNode->setGlyphs(m_originalPosition, subNodeGlyphRun);
311 appendChildNode(subNode);
317 s_totalAllocation += vp.size() *
sizeof(QSGGeometry::TexturedPoint2D) + ip.size() *
sizeof(quint16);
318 qCDebug(lcSgText) <<
"allocating for" << vp.size() <<
"vtx (reserved" << likelyGlyphCount * 4 <<
"):" << vp.size() *
sizeof(QSGGeometry::TexturedPoint2D)
319 <<
"bytes;" << ip.size() <<
"idx:" << ip.size() *
sizeof(quint16) <<
"bytes; total bytes so far" << s_totalAllocation;
320 g->allocate(vp.size(), ip.size());
321 memcpy(g->vertexDataAsTexturedPoint2D(), vp.constData(), vp.size() *
sizeof(QSGGeometry::TexturedPoint2D));
322 memcpy(g->indexDataAsUShort(), ip.constData(), ip.size() *
sizeof(quint16));
324 setBoundingRect(m_boundingRect);
325 markDirty(DirtyGeometry);
326 m_dirtyGeometry =
false;
328 m_material->setTexture(m_texture);