Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsgcurveglyphnode.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
8
9#include <private/qsgcurveabstractnode_p.h>
10#include <private/qsgcontext_p.h>
11#include <private/qsgtexturematerial_p.h>
12
13#include <private/qrawfont_p.h>
14#include <QtGui/qcolor.h>
15
17
19 : m_context(context)
20 , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
21 , m_dirtyGeometry(false)
22{
25
26 // #### To avoid asserts: we should probably merge this with QSGCurveFillNode
27 setGeometry(&m_geometry);
29}
30
34
39
41{
42 m_color = color;
43 if (m_glyphNode != nullptr)
44 m_glyphNode->setColor(color);
45}
46
48{
49 m_styleColor = styleColor;
50 if (m_styleNode != nullptr)
51 m_styleNode->setColor(styleColor);
52}
53
55{
56 if (m_style != style) {
57 m_style = style;
58 m_dirtyGeometry = true;
59 update();
60 }
61}
62
64{
65 m_glyphs = glyphs;
66
67 QRawFont font = glyphs.rawFont();
68 m_fontSize = font.pixelSize();
69 m_position = QPointF(position.x(), position.y() - font.ascent());
70
71
72 m_dirtyGeometry = true;
73
74#ifdef QSG_RUNTIME_DESCRIPTION
76 + QStringLiteral(" curve glyphs: ")
77 + m_glyphs.rawFont().familyName()
78 + QStringLiteral(" ")
79 + QString::number(m_glyphs.rawFont().pixelSize()));
80#endif
81}
82
87
89{
90 if (m_dirtyGeometry)
92}
93
95{
96 delete m_glyphNode;
97 m_glyphNode = nullptr;
98
99 delete m_styleNode;
100 m_styleNode = nullptr;
101
102 QSGCurveGlyphAtlas *curveGlyphAtlas = m_context->curveGlyphAtlas(m_glyphs.rawFont());
103 curveGlyphAtlas->populate(m_glyphs.glyphIndexes());
104
105 m_glyphNode = new QSGCurveFillNode;
106 m_glyphNode->setColor(m_color);
107
109
110 float fontScale = float(m_fontSize / curveGlyphAtlas->fontSize());
111 QSGCurveFillNode *raisedSunkenStyleNode = nullptr;
112 QSGCurveStrokeNode *outlineNode = nullptr;
113 if (m_style == QQuickText::Raised || m_style == QQuickText::Sunken) {
114 raisedSunkenStyleNode = new QSGCurveFillNode;
115 raisedSunkenStyleNode ->setColor(m_styleColor);
116
117 offset = m_style == QQuickText::Raised ? QPointF(0.0f, 1.0f) : QPointF(0.0f, -1.0f);
118 m_styleNode = raisedSunkenStyleNode;
119 } else if (m_style == QQuickText::Outline) {
120 outlineNode = new QSGCurveStrokeNode;
121 outlineNode->setColor(m_styleColor);
122 outlineNode->setStrokeWidth(2 / fontScale);
123 outlineNode->setLocalScale(fontScale);
124
125 m_styleNode = outlineNode;
126 }
127
128 const QVector<quint32> indexes = m_glyphs.glyphIndexes();
129 const QVector<QPointF> positions = m_glyphs.positions();
130 for (qsizetype i = 0; i < indexes.size(); ++i) {
131 if (i == 0)
132 m_baseLine = positions.at(i);
133 curveGlyphAtlas->addGlyph(m_glyphNode,
134 indexes.at(i),
135 m_position + positions.at(i),
136 m_fontSize);
137 if (raisedSunkenStyleNode != nullptr) {
138 curveGlyphAtlas->addGlyph(raisedSunkenStyleNode,
139 indexes.at(i),
140 m_position + positions.at(i) + offset,
141 m_fontSize);
142 }
143 if (outlineNode != nullptr) {
144 // Since the stroke node will scale everything by fontScale internally (the
145 // shader does not support pre-transforming the vertices), we have to also first
146 // do the inverse scale on the glyph position to get the correct position.
147 curveGlyphAtlas->addStroke(outlineNode,
148 indexes.at(i),
149 (m_position + positions.at(i)) / fontScale);
150 }
151 }
152
153 if (m_styleNode != nullptr) {
154 m_styleNode->cookGeometry();
155 appendChildNode(m_styleNode);
156 }
157
158 m_glyphNode->cookGeometry();
159 appendChildNode(m_glyphNode);
160
161 m_dirtyGeometry = false;
162}
163
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
Definition qfont.cpp:1074
The QGlyphRun class provides direct access to the internal glyphs in a font.
Definition qglyphrun.h:20
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 count() const noexcept
Definition qlist.h:398
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QRawFont class provides access to a single physical instance of a font.
Definition qrawfont.h:24
QString familyName() const
Returns the family name of this QRawFont.
Definition qrawfont.cpp:441
qreal pixelSize() const
Returns the pixel size set for this QRawFont.
Definition qrawfont.cpp:402
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
Definition qsgnode.cpp:764
virtual void setColor(QColor col)=0
virtual void cookGeometry()=0
void setColor(QColor col) override
void cookGeometry() override
void addStroke(QSGCurveStrokeNode *node, glyph_t glyph, const QPointF &position) const
void addGlyph(QSGCurveFillNode *node, glyph_t glyph, const QPointF &position, qreal pixelSize) const
void populate(const QList< glyph_t > &glyphs)
QSGCurveGlyphNode(QSGRenderContext *context)
void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override
void setColor(const QColor &color) override
void setStyle(QQuickText::TextStyle style) override
void preprocess() override
Override this function to do processing on the node before it is rendered.
void setStyleColor(const QColor &color) override
void setPreferredAntialiasingMode(AntialiasingMode) override
void update() override
void setColor(QColor col) override
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:927
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
@ DirtyGeometry
Definition qsgnode.h:74
@ UsePreprocess
Definition qsgnode.h:52
@ OwnsMaterial
Definition qsgnode.h:58
void appendChildNode(QSGNode *node)
Appends node to this node's list of children.
Definition qsgnode.cpp:398
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
Definition qsgnode.cpp:624
void setFlag(Flag, bool=true)
Sets the flag f on this node if enabled is true; otherwise clears the flag.
Definition qsgnode.cpp:586
virtual QSGCurveGlyphAtlas * curveGlyphAtlas(const QRawFont &font)
Factory function for curve atlases that can be used to provide geometry for the curve renderer for a ...
The QSGTextureMaterial class provides a convenient way of rendering textured geometry in the scene gr...
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
Combined button and popup list for selecting options.
static void * context
static const QCssKnownValue positions[NumKnownPositionModes - 1]
GLenum mode
GLuint color
[2]
GLenum GLuint GLintptr offset
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
void qsgnode_set_description(QSGNode *node, const QString &description)
Definition qsgnode.cpp:641
#define QStringLiteral(str)
#define Q_UNUSED(x)
ptrdiff_t qsizetype
Definition qtypes.h:165