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
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 // Decorations handled by text node
63 m_glyphRun.setOverline(false);
64 m_glyphRun.setStrikeOut(false);
65 m_glyphRun.setUnderline(false);
66 m_bounding_rect = calculateBoundingRect(position, glyphs);
67}
68
70{
71 m_color = color;
72}
73
75{
76 m_style = style;
77}
78
80{
81 m_styleColor = color;
82}
83
85{
86 return QPointF();
87}
88
92
96
98{
100 QPointF pos = m_position - QPointF(0, m_glyphRun.rawFont().ascent());
101
102 qreal offset = 1.0;
103 if (painter->device()->devicePixelRatio() > 0.0)
105
106 switch (m_style) {
107 case QQuickText::Normal: break;
109 painter->setPen(m_styleColor);
110 painter->drawGlyphRun(pos + QPointF(0, offset), m_glyphRun);
111 painter->drawGlyphRun(pos + QPointF(0, -offset), m_glyphRun);
112 painter->drawGlyphRun(pos + QPointF(offset, 0), m_glyphRun);
113 painter->drawGlyphRun(pos + QPointF(-offset, 0), m_glyphRun);
114 break;
116 painter->setPen(m_styleColor);
117 painter->drawGlyphRun(pos + QPointF(0, offset), m_glyphRun);
118 break;
120 painter->setPen(m_styleColor);
121 painter->drawGlyphRun(pos + QPointF(0, -offset), m_glyphRun);
122 break;
123 }
124
125 painter->setPen(m_color);
126 painter->drawGlyphRun(pos, m_glyphRun);
127}
128
\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
void setOverline(bool overline)
Indicates that this QGlyphRun should be painted with an overline decoration if overline is true.
void setUnderline(bool underline)
Indicates that this QGlyphRun should be painted with an underline decoration if underline is true.
QList< quint32 > glyphIndexes() const
Returns the glyph indexes for this QGlyphRun object.
QRawFont rawFont() const
Returns the font selected for this QGlyphRun object.
void setStrikeOut(bool strikeOut)
Indicates that this QGlyphRun should be painted with an strike out decoration if strikeOut is true.
QList< QPointF > positions() const
Returns the position of the edge of the baseline for each glyph in this set of glyph indexes.
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:217
static QRawFontPrivate * get(const QRawFont &font)
Definition qrawfont_p.h:104
qreal ascent() const
Returns the ascent of this QRawFont in pixel units.
Definition qrawfont.cpp:314
\inmodule QtCore\reentrant
Definition qrect.h:484
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 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
GLuint color
[2]
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:187
QPainter painter(this)
[7]
static constexpr QFixed fromReal(qreal r)
Definition qfixed_p.h:35
constexpr qreal toReal() const
Definition qfixed_p.h:42