Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
6#include <QtGui/private/qrawfont_p.h>
7
9
10QSGSoftwareGlyphNode::QSGSoftwareGlyphNode()
11 : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
12 , m_style(QQuickText::Normal)
13{
14 setMaterial((QSGMaterial*)1);
15 setGeometry(&m_geometry);
16}
17
18namespace {
19QRectF calculateBoundingRect(const QPointF &position, const QGlyphRun &glyphs)
20{
21 QFixed minX;
22 QFixed minY;
23 QFixed maxX;
24 QFixed maxY;
25
26 QRawFontPrivate *rawFontD = QRawFontPrivate::get(glyphs.rawFont());
27 QFontEngine *fontEngine = rawFontD->fontEngine;
28
29 QFontEngine::GlyphFormat glyphFormat = fontEngine->glyphFormat != QFontEngine::Format_None ? fontEngine->glyphFormat : QFontEngine::Format_A32;
30
31 int margin = fontEngine->glyphMargin(glyphFormat);
32
33 const QList<uint> glyphIndexes = glyphs.glyphIndexes();
34 const QList<QPointF> glyphPositions = glyphs.positions();
35 for (int i = 0, n = qMin(glyphIndexes.size(), glyphPositions.size()); i < n; ++i) {
36 glyph_metrics_t gm = fontEngine->alphaMapBoundingBox(glyphIndexes.at(i), QFixedPoint(), QTransform(), glyphFormat);
37
38 gm.x += QFixed::fromReal(glyphPositions.at(i).x()) - margin;
39 gm.y += QFixed::fromReal(glyphPositions.at(i).y()) - margin;
40
41 if (i == 0) {
42 minX = gm.x;
43 minY = gm.y;
44 maxX = gm.x + gm.width;
45 maxY = gm.y + gm.height;
46 } else {
47 minX = qMin(gm.x, minX);
48 minY = qMin(gm.y, minY);
49 maxX = qMax(gm.x + gm.width, maxX);
50 maxY = qMax(gm.y + gm.height, maxY);
51 }
52 }
53
54 QRectF boundingRect(QPointF(minX.toReal(), minY.toReal()), QPointF(maxX.toReal(), maxY.toReal()));
55 return boundingRect.translated(position - QPointF(0.0, glyphs.rawFont().ascent()));
56}
57}
58
59void QSGSoftwareGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyphs)
60{
61 m_position = position;
62 m_glyphRun = glyphs;
63 // Decorations handled by text node
64 m_glyphRun.setOverline(false);
65 m_glyphRun.setStrikeOut(false);
66 m_glyphRun.setUnderline(false);
67
68 recalculateBoundingRect();
69}
70
71void QSGSoftwareGlyphNode::recalculateBoundingRect()
72{
73 int x1Offset = m_style == QQuickText::Outline ? -1 : 0;
74 int x2Offset = m_style == QQuickText::Outline ? 1 : 0;
75 int y1Offset = m_style == QQuickText::Outline || m_style == QQuickText::Sunken ? -1 : 0;
76 int y2Offset = m_style == QQuickText::Outline || m_style == QQuickText::Raised ? 1 : 0;
77
78 m_bounding_rect = calculateBoundingRect(m_position, m_glyphRun).adjusted(x1Offset, y1Offset, x2Offset, y2Offset);
79}
80
81void QSGSoftwareGlyphNode::setColor(const QColor &color)
82{
83 m_color = color;
84}
85
86void QSGSoftwareGlyphNode::setStyle(QQuickText::TextStyle style)
87{
88 m_style = style;
89
90 recalculateBoundingRect();
91}
92
93void QSGSoftwareGlyphNode::setStyleColor(const QColor &color)
94{
95 m_styleColor = color;
96}
97
98QPointF QSGSoftwareGlyphNode::baseLine() const
99{
100 return QPointF();
101}
102
103void QSGSoftwareGlyphNode::setPreferredAntialiasingMode(QSGGlyphNode::AntialiasingMode)
104{
105}
106
107void QSGSoftwareGlyphNode::update()
108{
109}
110
111void QSGSoftwareGlyphNode::paint(QPainter *painter)
112{
113 painter->setBrush(QBrush());
114 QPointF pos = m_position - QPointF(0, m_glyphRun.rawFont().ascent());
115
116 qreal offset = 1.0;
117 if (painter->device()->devicePixelRatio() > 0.0)
118 offset = 1.0 / painter->device()->devicePixelRatio();
119
120 switch (m_style) {
121 case QQuickText::Normal: break;
122 case QQuickText::Outline:
123 painter->setPen(m_styleColor);
124 painter->drawGlyphRun(pos + QPointF(0, offset), m_glyphRun);
125 painter->drawGlyphRun(pos + QPointF(0, -offset), m_glyphRun);
126 painter->drawGlyphRun(pos + QPointF(offset, 0), m_glyphRun);
127 painter->drawGlyphRun(pos + QPointF(-offset, 0), m_glyphRun);
128 break;
129 case QQuickText::Raised:
130 painter->setPen(m_styleColor);
131 painter->drawGlyphRun(pos + QPointF(0, offset), m_glyphRun);
132 break;
133 case QQuickText::Sunken:
134 painter->setPen(m_styleColor);
135 painter->drawGlyphRun(pos + QPointF(0, -offset), m_glyphRun);
136 break;
137 }
138
139 painter->setPen(m_color);
140 painter->drawGlyphRun(pos, m_glyphRun);
141}
142
143QT_END_NAMESPACE
Combined button and popup list for selecting options.