Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qsgsoftwareglyphnode.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 <QtGui/private/qrawfont_p.h>
6
8
10 : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
11 , m_style(QQuickText::Normal)
12{
14 setGeometry(&m_geometry);
15}
16
17namespace {
18QRectF calculateBoundingRect(const QPointF &position, const QGlyphRun &glyphs)
19{
20 QFixed minX;
24
25 QRawFontPrivate *rawFontD = QRawFontPrivate::get(glyphs.rawFont());
26 QFontEngine *fontEngine = rawFontD->fontEngine;
27
29
30 int margin = fontEngine->glyphMargin(glyphFormat);
31
32 const QVector<uint> glyphIndexes = glyphs.glyphIndexes();
33 const QVector<QPointF> glyphPositions = glyphs.positions();
34 for (int i = 0, n = qMin(glyphIndexes.size(), glyphPositions.size()); i < n; ++i) {
35 glyph_metrics_t gm = fontEngine->alphaMapBoundingBox(glyphIndexes.at(i), QFixedPoint(), QTransform(), glyphFormat);
36
37 gm.x += QFixed::fromReal(glyphPositions.at(i).x()) - margin;
38 gm.y += QFixed::fromReal(glyphPositions.at(i).y()) - margin;
39
40 if (i == 0) {
41 minX = gm.x;
42 minY = gm.y;
43 maxX = gm.x + gm.width;
44 maxY = gm.y + gm.height;
45 } else {
46 minX = qMin(gm.x, minX);
47 minY = qMin(gm.y, minY);
48 maxX = qMax(gm.x + gm.width, maxX);
49 maxY = qMax(gm.y + gm.height, maxY);
50 }
51 }
52
53 QRectF boundingRect(QPointF(minX.toReal(), minY.toReal()), QPointF(maxX.toReal(), maxY.toReal()));
54 return boundingRect.translated(position - QPointF(0.0, glyphs.rawFont().ascent()));
55}
56}
57
59{
60 m_position = position;
61 m_glyphRun = glyphs;
62 m_bounding_rect = calculateBoundingRect(position, glyphs);
63}
64
66{
67 m_color = color;
68}
69
71{
72 m_style = style;
73}
74
76{
77 m_styleColor = color;
78}
79
81{
82 return QPointF();
83}
84
86{
87}
88
90{
91}
92
94{
96 QPointF pos = m_position - QPointF(0, m_glyphRun.rawFont().ascent());
97
98 qreal offset = 1.0;
99 if (painter->device()->devicePixelRatio() > 0.0)
101
102 switch (m_style) {
103 case QQuickText::Normal: break;
105 painter->setPen(m_styleColor);
106 painter->drawGlyphRun(pos + QPointF(0, offset), m_glyphRun);
107 painter->drawGlyphRun(pos + QPointF(0, -offset), m_glyphRun);
108 painter->drawGlyphRun(pos + QPointF(offset, 0), m_glyphRun);
109 painter->drawGlyphRun(pos + QPointF(-offset, 0), m_glyphRun);
110 break;
112 painter->setPen(m_styleColor);
113 painter->drawGlyphRun(pos + QPointF(0, offset), m_glyphRun);
114 break;
116 painter->setPen(m_styleColor);
117 painter->drawGlyphRun(pos + QPointF(0, -offset), m_glyphRun);
118 break;
119 }
120
121 painter->setPen(m_color);
122 painter->drawGlyphRun(pos, m_glyphRun);
123}
124
\inmodule QtGui
Definition qbrush.h:30
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
virtual glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, const QFixedPoint &, const QTransform &matrix, GlyphFormat)
virtual int glyphMargin(GlyphFormat format)
GlyphFormat glyphFormat
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.
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
qreal devicePixelRatio() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void drawGlyphRun(const QPointF &position, const QGlyphRun &glyphRun)
Draws the glyphs represented by glyphs at position.
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
\inmodule QtCore\reentrant
Definition qpoint.h:214
static QRawFontPrivate * get(const QRawFont &font)
Definition qrawfont_p.h:104
QFontEngine * fontEngine
Definition qrawfont_p.h:106
qreal ascent() const
Returns the ascent of this QRawFont in pixel units.
Definition qrawfont.cpp:314
\inmodule QtCore\reentrant
Definition qrect.h:483
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:748
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
Definition qsgnode.cpp:762
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:925
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 setStyleColor(const QColor &color) override
void setColor(const QColor &color) override
void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override
void setStyle(QQuickText::TextStyle style) override
void paint(QPainter *painter)
void setPreferredAntialiasingMode(AntialiasingMode) override
QPointF baseLine() const override
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
Combined button and popup list for selecting options.
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
GLfloat minY
GLenum GLuint GLintptr offset
GLfloat n
GLfloat GLfloat GLfloat GLfloat maxX
static const QRectF boundingRect(const QPointF *points, int pointCount)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
double qreal
Definition qtypes.h:92
QPainter painter(this)
[7]
static constexpr QFixed fromReal(qreal r)
Definition qfixed_p.h:35
constexpr qreal toReal() const
Definition qfixed_p.h:42