6#include <QtQuick/private/qsgcontext_p.h>
15 : m_glyphNodeType(RootGlyphNode)
18 , m_glyph_cache(
nullptr)
19 , m_geometry(
QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
21 , m_antialiasingMode(GrayAntialiasing)
23 , m_renderTypeQuality(-1)
24 , m_dirtyGeometry(
false)
25 , m_dirtyMaterial(
false)
28 setGeometry(&m_geometry);
29#ifdef QSG_RUNTIME_DESCRIPTION
38 if (m_glyphNodeType == SubGlyphNode)
50 if (m_material !=
nullptr) {
54 m_dirtyMaterial =
true;
60 if (renderTypeQuality == m_renderTypeQuality)
63 m_renderTypeQuality = renderTypeQuality;
68 if (
mode == m_antialiasingMode)
70 m_antialiasingMode =
mode;
71 m_dirtyMaterial =
true;
81 m_dirtyGeometry =
true;
82 m_dirtyMaterial =
true;
88 if (m_glyphNodeType == SubGlyphNode)
91 if (m_glyph_cache != oldCache) {
93 oldCache->unregisterGlyphNode(
this);
100 const QVector<quint32> glyphIndexes = m_glyphs.
glyphIndexes();
101 for (
int i = 0;
i < glyphIndexes.size(); ++
i)
102 m_allGlyphIndexesLookup.
insert(glyphIndexes.at(
i));
105 m_allGlyphIndexesLookup.
size());
106#ifdef QSG_RUNTIME_DESCRIPTION
114 if (m_style == style)
117 m_dirtyMaterial =
true;
122 if (m_styleColor ==
color)
124 m_styleColor =
color;
125 m_dirtyMaterial =
true;
147 for (
int i = 0;
i < glyphs.size(); ++
i) {
148 if (m_allGlyphIndexesLookup.
contains(glyphs.at(
i))) {
149 m_dirtyGeometry =
true;
174 m_glyphsInOtherTextures.
clear();
176 const QVector<quint32> indexes = m_glyphs.
glyphIndexes();
182 QVarLengthArray<QSGGeometry::TexturedPoint2D, 256> vp;
183 QVarLengthArray<ushort, 384> ip;
184 const qsizetype maxIndexCount = (std::numeric_limits<quint16>::max() - 1) / 4;
185 const qsizetype maxVertexCount = maxIndexCount * 4;
186 const auto likelyGlyphCount =
qMin(indexes.size(), maxIndexCount);
187 vp.reserve(likelyGlyphCount * 4);
188 ip.reserve(likelyGlyphCount * 6);
193 qreal texMargin = margin / fontScale;
194 if (texMargin > maxTexMargin) {
195 texMargin = maxTexMargin;
196 margin = maxTexMargin * fontScale;
199 for (
int i = 0;
i < indexes.size(); ++
i) {
200 const int glyphIndex = indexes.at(
i);
209 if (
texture->texture && !m_texture)
221 if (m_texture !=
texture || vp.size() >= maxVertexCount) {
222 if (m_glyphNodeType == RootGlyphNode &&
texture->texture) {
223 GlyphInfo &glyphInfo = m_glyphsInOtherTextures[
texture];
224 glyphInfo.indexes.append(glyphIndex);
225 glyphInfo.positions.append(
position);
226 }
else if (vp.size() >= maxVertexCount && m_glyphNodeType == SubGlyphNode) {
234 if (!
metrics.isNull() && !
c.isNull()) {
239 c.xMargin -= texMargin;
240 c.yMargin -= texMargin;
241 c.width += texMargin * 2;
242 c.height += texMargin * 2;
255 float tx1 =
c.x +
c.xMargin;
256 float tx2 = tx1 +
c.width;
257 float ty1 =
c.y +
c.yMargin;
258 float ty2 = ty1 +
c.height;
266 v1.set(cx1, cy1, tx1, ty1);
268 v2.
set(cx2, cy1, tx2, ty1);
270 v3.
set(cx1, cy2, tx1, ty2);
272 v4.
set(cx2, cy2, tx2, ty2);
286 if (m_glyphNodeType == SubGlyphNode) {
289 if (!m_glyphsInOtherTextures.
isEmpty())
292 while (ite != m_glyphsInOtherTextures.
constEnd()) {
294 for (
int i = 0;
i < ite->indexes.size();
i += maxIndexCount) {
295 int len =
qMin(maxIndexCount, ite->indexes.size() -
i);
296 subNodeGlyphRun.setRawData(ite->indexes.constData() +
i, ite->positions.constData() +
i,
len);
297 qCDebug(lcSgText) <<
"subNodeGlyphRun has" <<
len <<
"positions:"
298 << *(ite->positions.constData() +
i) <<
"->" << *(ite->positions.constData() +
i +
len - 1);
301 subNode->setGlyphNodeType(SubGlyphNode);
302 subNode->setColor(m_color);
303 subNode->setStyle(m_style);
304 subNode->setStyleColor(m_styleColor);
305 subNode->setPreferredAntialiasingMode(m_antialiasingMode);
306 subNode->setGlyphs(m_originalPosition, subNodeGlyphRun);
308 subNode->updateGeometry();
317 <<
"bytes;" << ip.size() <<
"idx:" << ip.size() *
sizeof(
quint16) <<
"bytes; total bytes so far" << m_totalAllocation;
318 g->allocate(vp.size(), ip.size());
320 memcpy(
g->indexDataAsUShort(), ip.constData(), ip.size() *
sizeof(
quint16));
324 m_dirtyGeometry =
false;
329void QSGDistanceFieldGlyphNode::updateMaterial()
334 switch (m_antialiasingMode) {
355 sMaterial->setShift(
QPointF(0.0, -1.0));
358 material->setStyleColor(m_styleColor);
367 m_dirtyMaterial =
false;
The QColor class provides colors based on RGB, HSV or CMYK values.
The QGlyphRun class provides direct access to the internal glyphs in a font.
QList< quint32 > glyphIndexes() const
Returns the glyph indexes for this QGlyphRun object.
QRawFont rawFont() const
Returns the font selected for this QGlyphRun object.
QList< QPointF > positions() const
Returns the position of the edge of the baseline for each glyph in this set of glyph indexes.
qsizetype size() const noexcept
Returns the number of items in the hash.
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
qsizetype count() const noexcept
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0.0 (ignoring the sign); otherwise returns fa...
The QRawFont class provides access to a single physical instance of a font.
QString familyName() const
Returns the family name of this QRawFont.
qreal pixelSize() const
Returns the pixel size set for this QRawFont.
\inmodule QtCore\reentrant
const QSGGeometry * geometry() const
Returns this node's geometry.
qreal distanceFieldRadius() const
void unregisterGlyphNode(QSGDistanceFieldGlyphConsumer *node)
Metrics glyphMetrics(glyph_t glyph, qreal pixelSize)
qreal fontScale(qreal pixelSize) const
void populate(const QVector< glyph_t > &glyphs)
const Texture * glyphTexture(glyph_t glyph)
void release(const QVector< glyph_t > &glyphs)
TexCoord glyphTexCoord(glyph_t glyph)
void registerGlyphNode(QSGDistanceFieldGlyphConsumer *node)
QSGDistanceFieldGlyphNode(QSGRenderContext *context)
void setStyleColor(const QColor &color) override
void setStyle(QQuickText::TextStyle style) override
void setRenderTypeQuality(int renderTypeQuality) override
void setColor(const QColor &color) override
void setPreferredAntialiasingMode(AntialiasingMode mode) override
~QSGDistanceFieldGlyphNode()
void preprocess() override
Override this function to do processing on the node before it is rendered.
void invalidateGlyphs(const QVector< quint32 > &glyphs) override
void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override
void setShift(const QPointF &shift)
virtual void setColor(const QColor &color)
void setGlyphCache(QSGDistanceFieldGlyphCache *a)
void setTexture(const QSGDistanceFieldGlyphCache::Texture *tex)
void setFontScale(qreal fontScale)
QSGMaterial * material() const
Returns the material of the QSGGeometryNode.
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
virtual void setBoundingRect(const QRectF &bounds)
@ HighQualitySubPixelAntialiasing
@ LowQualitySubPixelAntialiasing
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
QSGNode * nextSibling() const
Returns the node after this in the parent's list of children.
void appendChildNode(QSGNode *node)
Appends node to this node's list of children.
QSGNode * firstChild() const
Returns the first child of this node.
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
void setFlag(Flag, bool=true)
Sets the flag f on this node if enabled is true; otherwise clears the flag.
virtual QSGDistanceFieldGlyphCache * distanceFieldGlyphCache(const QRawFont &font, int renderTypeQuality)
Factory function for scene graph backends of the distance-field glyph cache.
bool contains(const T &value) const
iterator insert(const T &value)
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Combined button and popup list for selecting options.
static const QCssKnownValue positions[NumKnownPositionModes - 1]
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qMin(const T &a, const T &b)
GLint GLfloat GLfloat GLfloat v2
GLint GLint GLint GLint GLint x
[0]
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
GLint GLfloat GLfloat GLfloat GLfloat v3
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
void qsgnode_set_description(QSGNode *node, const QString &description)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
The QSGGeometry::TexturedPoint2D struct is a convenience struct for accessing 2D Points with texture ...
void set(float nx, float ny, float ntx, float nty)
Sets the position of the vertex to x and y and the texture coordinate to tx and ty.