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
qsgopenvgglyphnode.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
5#include "qopenvgcontext_p.h"
7#include "qsgopenvghelpers.h"
10#include <cmath>
11
13
15 : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
16 , m_style(QQuickText::Normal)
17 , m_glyphCache(nullptr)
18{
19 // Set Dummy material to avoid asserts
21 setGeometry(&m_geometry);
22 m_fontColorPaint = vgCreatePaint();
23 m_styleColorPaint = vgCreatePaint();
24
25 // Get handle to Glyph Cache
26 m_renderContext = static_cast<QSGOpenVGRenderContext*>(rc);
27}
28
30{
31 if (m_glyphCache)
32 m_glyphCache->release(m_glyphRun.glyphIndexes());
33
34 vgDestroyPaint(m_fontColorPaint);
35 vgDestroyPaint(m_styleColorPaint);
36}
37
39{
40 // Obtain glyph cache for font
41 auto oldGlyphCache = m_glyphCache;
42 m_glyphCache = m_renderContext->glyphCache(glyphs.rawFont());
43 if (m_glyphCache != oldGlyphCache) {
44 if (oldGlyphCache)
45 oldGlyphCache->release(m_glyphRun.glyphIndexes());
46 }
47 m_glyphCache->populate(glyphs.glyphIndexes());
48
49 m_position = position;
50 m_glyphRun = glyphs;
51 m_bounding_rect = glyphs.boundingRect().translated(m_position - QPointF(0.0, glyphs.rawFont().ascent()));
52
53 // Recreate ajustments
54 m_xAdjustments.clear();
55 m_yAdjustments.clear();
56
57 for (int i = 1; i < glyphs.positions().count(); ++i) {
58 m_xAdjustments.append(glyphs.positions().at(i).x() - glyphs.positions().at(i-1).x());
59 m_yAdjustments.append(glyphs.positions().at(i).y() - glyphs.positions().at(i-1).y());
60 }
61}
62
64{
65 m_color = color;
66 vgSetParameteri(m_fontColorPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
67 vgSetParameterfv(m_fontColorPaint, VG_PAINT_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(m_color, opacity()).constData());
68}
69
71{
72 m_style = style;
73}
74
76{
77 m_styleColor = color;
78 vgSetParameteri(m_styleColorPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
79 vgSetParameterfv(m_styleColorPaint, VG_PAINT_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(m_styleColor, opacity()).constData());
80}
81
83{
84 return QPointF();
85}
86
90
94
96{
97 if (m_glyphRun.positions().count() == 0)
98 return;
99
100 // Rendering Style
101 qreal offset = 1.0;
102
103 QOpenVGOffscreenSurface *offscreenSurface = nullptr;
104
105 // Set Transform
106 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
107 if (transform().isAffine()) {
108 vgLoadMatrix(transform().constData());
109 } else {
110 vgLoadIdentity();
111 offscreenSurface = new QOpenVGOffscreenSurface(QSize(std::ceil(m_bounding_rect.width()), std::ceil(m_bounding_rect.height())));
112 offscreenSurface->makeCurrent();
113 }
114
115 // Set Quality
116 vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);
117
118
119 switch (m_style) {
120 case QQuickText::Normal: break;
122 // Set the correct fill state
123 vgSetPaint(m_styleColorPaint, VG_FILL_PATH);
124 drawGlyphsAtOffset(QPointF(0, offset));
125 drawGlyphsAtOffset(QPointF(0, -offset));
126 drawGlyphsAtOffset(QPointF(offset, 0));
127 drawGlyphsAtOffset(QPointF(-offset, 0));
128 break;
130 vgSetPaint(m_styleColorPaint, VG_FILL_PATH);
131 drawGlyphsAtOffset(QPointF(0, offset));
132 break;
134 vgSetPaint(m_styleColorPaint, VG_FILL_PATH);
135 drawGlyphsAtOffset(QPointF(0, -offset));
136 break;
137 }
138
139 // Set the correct fill state
140 vgSetPaint(m_fontColorPaint, VG_FILL_PATH);
141 drawGlyphsAtOffset(QPointF(0.0, 0.0));
142
143 if (!transform().isAffine()) {
144 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
145 vgLoadMatrix(transform().constData());
146 offscreenSurface->doneCurrent();
147 vgDrawImage(offscreenSurface->image());
148 delete offscreenSurface;
149 }
150}
151
153{
156 // Update Colors
157 setColor(m_color);
158 setStyleColor(m_styleColor);
159 }
160}
161
162void QSGOpenVGGlyphNode::drawGlyphsAtOffset(const QPointF &offset)
163{
164 QPointF firstPosition = m_glyphRun.positions()[0] + (m_position - QPointF(0, m_glyphRun.rawFont().ascent()));
165 VGfloat origin[2];
166 origin[0] = firstPosition.x() + offset.x();
167 origin[1] = firstPosition.y() + offset.y();
168 vgSetfv(VG_GLYPH_ORIGIN, 2, origin);
169
170 vgDrawGlyphs(m_glyphCache->font(),
171 m_glyphRun.glyphIndexes().count(),
172 (VGuint*)m_glyphRun.glyphIndexes().constData(),
173 m_xAdjustments.constData(),
174 m_yAdjustments.constData(),
175 VG_FILL_PATH,
176 VG_TRUE);
177}
178
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
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.
QRectF boundingRect() const
Returns the smallest rectangle that contains all glyphs in this QGlyphRun.
QList< QPointF > positions() const
Returns the position of the edge of the baseline for each glyph in this set of glyph indexes.
const_pointer constData() const noexcept
Definition qlist.h:433
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
qsizetype count() const noexcept
Definition qlist.h:398
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
qreal ascent() const
Returns the ascent of this QRawFont in pixel units.
Definition qrawfont.cpp:314
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
constexpr QRectF translated(qreal dx, qreal dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:762
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
Definition qsgnode.cpp:764
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
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
void populate(const QVector< quint32 > &glyphs)
void release(const QVector< quint32 > &glyphs)
void setColor(const QColor &color) override
void setStyle(QQuickText::TextStyle style) override
QSGOpenVGGlyphNode(QSGRenderContext *rc)
void setStyleColor(const QColor &color) override
void setPreferredAntialiasingMode(AntialiasingMode) override
QPointF baseLine() const override
void setOpacity(float opacity) override
void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override
QSGOpenVGFontGlyphCache * glyphCache(const QRawFont &rawFont)
const QOpenVGMatrix & transform() const
virtual void setOpacity(float opacity)
\inmodule QtCore
Definition qsize.h:25
const QVector< VGfloat > qColorToVGColor(const QColor &color, float opacity)
Combined button and popup list for selecting options.
GLenum GLenum GLsizei count
GLuint color
[2]
GLenum GLuint GLintptr offset
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
double qreal
Definition qtypes.h:187
QObject::connect nullptr