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)
51 if (m_material !=
nullptr) {
55 m_dirtyMaterial =
true;
61 if (renderTypeQuality == m_renderTypeQuality)
64 m_renderTypeQuality = renderTypeQuality;
69 if (
mode == m_antialiasingMode)
71 m_antialiasingMode =
mode;
72 m_dirtyMaterial =
true;
82 m_dirtyGeometry =
true;
83 m_dirtyMaterial =
true;
89 if (m_glyphNodeType == SubGlyphNode)
92 if (m_glyph_cache != oldCache) {
104 for (
int i = 0;
i < glyphIndexes.
size(); ++
i)
105 m_allGlyphIndexesLookup.
insert(glyphIndexes.
at(
i));
108 m_allGlyphIndexesLookup.
size());
109#ifdef QSG_RUNTIME_DESCRIPTION
117 if (m_style == style)
120 m_dirtyMaterial =
true;
125 if (m_styleColor ==
color)
127 m_styleColor =
color;
128 m_dirtyMaterial =
true;
150 for (
int i = 0;
i < glyphs.
size(); ++
i) {
151 if (m_allGlyphIndexesLookup.
contains(glyphs.
at(
i))) {
152 m_dirtyGeometry =
true;
176 m_glyphsInOtherTextures.
clear();
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);
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);
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) {
236 if (!
metrics.isNull() && !
c.isNull()) {
241 c.xMargin -= texMargin;
242 c.yMargin -= texMargin;
243 c.width += texMargin * 2;
244 c.height += texMargin * 2;
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;
268 v1.set(cx1, cy1, tx1, ty1);
270 v2.set(cx2, cy1, tx2, ty1);
272 v3.set(cx1, cy2, tx1, ty2);
274 v4.
set(cx2, cy2, tx2, ty2);
288 if (m_glyphNodeType == SubGlyphNode) {
291 if (!m_glyphsInOtherTextures.
isEmpty())
294 while (ite != m_glyphsInOtherTextures.
constEnd()) {
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);
310 subNode->updateGeometry();
319 <<
"bytes;" << ip.
size() <<
"idx:" << ip.
size() *
sizeof(
quint16) <<
"bytes; total bytes so far" << m_totalAllocation;
326 m_dirtyGeometry =
false;
331void QSGDistanceFieldGlyphNode::updateMaterial()
336 switch (m_antialiasingMode) {
360 material->setStyleColor(m_styleColor);
369 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.
void setRawData(const quint32 *glyphIndexArray, const QPointF *glyphPositionArray, int size)
Sets the glyph indexes and positions of this QGlyphRun to use the first size elements in the arrays g...
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 size() const noexcept
const_reference at(qsizetype i) const noexcept
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.
virtual void registerOwnerElement(QQuickItem *ownerElement)
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)
virtual void unregisterOwnerElement(QQuickItem *ownerElement)
void registerGlyphNode(QSGDistanceFieldGlyphConsumer *node)
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...
QQuickItem * ownerElement() const
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...
constexpr size_type size() const noexcept
const T * constData() const
void reserve(qsizetype sz)
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.