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
qsvgstructure_p.h
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
5
6#ifndef QSVGSTRUCTURE_P_H
7#define QSVGSTRUCTURE_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include "qsvgnode_p.h"
21#include <QtSvg/private/qsvghelper_p.h>
22#include <QtCore/qlist.h>
23
25
26class QSvgDocument;
27class QSvgNode;
28class QPainter;
29class QSvgDefs;
30
31class Q_SVG_EXPORT QSvgStructureNode : public QSvgNode
32{
33public:
34 QSvgStructureNode(QSvgNode *parent);
35 ~QSvgStructureNode();
36 QSvgNode *scopeNode(const QString &id) const;
37 void addChild(std::unique_ptr<QSvgNode> child, const QString &id);
38 QRectF internalBounds(QPainter *p, QSvgExtraStates &states) const override;
39 QRectF decoratedInternalBounds(QPainter *p, QSvgExtraStates &states) const override;
40 QSvgNode *previousSiblingNode(QSvgNode *n) const;
41 const std::vector<std::unique_ptr<QSvgNode>> &renderers() const { return m_renderers; }
42protected:
43 std::vector<std::unique_ptr<QSvgNode>> m_renderers;
44 mutable bool m_recursing = false;
45};
46
47class Q_SVG_EXPORT QSvgG : public QSvgStructureNode
48{
49public:
50 QSvgG(QSvgNode *parent);
51 void drawCommand(QPainter *, QSvgExtraStates &) override;
52 bool shouldDrawNode(QPainter *p, QSvgExtraStates &states) const override;
53 Type type() const override;
54 bool requiresGroupRendering() const override;
55};
56
57class Q_SVG_EXPORT QSvgDefs : public QSvgStructureNode
58{
59public:
60 QSvgDefs(QSvgNode *parent);
61 void drawCommand(QPainter *, QSvgExtraStates &) override {};
62 bool shouldDrawNode(QPainter *p, QSvgExtraStates &states) const override;
63 Type type() const override;
64};
65
66class Q_SVG_EXPORT QSvgSymbolLike : public QSvgStructureNode
67{
68 // Marker, Symbol and potentially other elements share a lot of common
69 // attributes and functionality. By making a common base class we can
70 // avoid repetition.
71public:
72 enum class Overflow : quint8 {
73 Visible,
74 Hidden,
75 Scroll = Visible, //Will not support scrolling
76 Auto = Visible
77 };
78
79 enum class PreserveAspectRatio : quint8 {
80 None = 0b000000,
81 xMin = 0b000001,
82 xMid = 0b000010,
83 xMax = 0b000011,
84 yMin = 0b000100,
85 yMid = 0b001000,
86 yMax = 0b001100,
87 meet = 0b010000,
88 slice = 0b100000,
89 xMask = xMin | xMid | xMax,
90 yMask = yMin | yMid | yMax,
91 xyMask = xMask | yMask,
92 meetSliceMask = meet | slice
93 };
94 Q_DECLARE_FLAGS(PreserveAspectRatios, PreserveAspectRatio)
95
96 QSvgSymbolLike(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP,
97 QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow);
98 void drawCommand(QPainter *, QSvgExtraStates &) override {};
99 QRectF decoratedInternalBounds(QPainter *p, QSvgExtraStates &states) const override;
100 bool requiresGroupRendering() const override;
101
102 QRectF viewBox() const
103 {
104 return m_viewBox;
105 }
106
107 QRectF rect() const
108 {
109 return m_rect;
110 }
111
112 QPointF refP() const
113 {
114 return m_refP;
115 }
116
117 QTransform aspectRatioTransform() const;
118 QRectF clipRect() const;
119
120 Overflow overflow() const
121 {
122 return m_overflow;
123 }
124
125 PreserveAspectRatios preserveAspectRatios() const
126 {
127 return m_pAspectRatios;
128 }
129
130protected:
131 void setPainterToRectAndAdjustment(QPainter *p) const;
132protected:
133 QRectF m_rect;
134 QRectF m_viewBox;
135 QPointF m_refP;
136 PreserveAspectRatios m_pAspectRatios;
137 Overflow m_overflow;
138};
139
140Q_DECLARE_OPERATORS_FOR_FLAGS(QSvgSymbolLike::PreserveAspectRatios)
141
142class Q_SVG_EXPORT QSvgSymbol : public QSvgSymbolLike
143{
144public:
145 QSvgSymbol(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP,
146 QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow);
147 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
148 Type type() const override;
149};
150
151class Q_SVG_EXPORT QSvgMarker : public QSvgSymbolLike
152{
153public:
154 enum class Orientation : quint8 {
155 Auto,
156 AutoStartReverse,
157 Value
158 };
159 enum class MarkerUnits : quint8 {
160 StrokeWidth,
161 UserSpaceOnUse
162 };
163
164 QSvgMarker(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP,
165 QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow,
166 Orientation orientation, qreal orientationAngle, MarkerUnits markerUnits);
167 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
168 static void drawMarkersForNode(QSvgNode *node, QPainter *p, QSvgExtraStates &states);
169 static QRectF markersBoundsForNode(const QSvgNode *node, QPainter *p, QSvgExtraStates &states);
170
171 Orientation orientation() const {
172 return m_orientation;
173 }
174 qreal orientationAngle() const {
175 return m_orientationAngle;
176 }
177 MarkerUnits markerUnits() const {
178 return m_markerUnits;
179 }
180 Type type() const override;
181
182private:
183 static void drawHelper(const QSvgNode *node, QPainter *p,
184 QSvgExtraStates &states, QRectF *boundingRect = nullptr);
185
186 Orientation m_orientation;
187 qreal m_orientationAngle;
188 MarkerUnits m_markerUnits;
189};
190
191class Q_SVG_EXPORT QSvgFilterContainer : public QSvgStructureNode
192{
193public:
194
195 QSvgFilterContainer(QSvgNode *parent, const QSvgRectF &bounds, QtSvg::UnitTypes filterUnits, QtSvg::UnitTypes primitiveUnits);
196 void drawCommand(QPainter *, QSvgExtraStates &) override {};
197 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
198 Type type() const override;
199 QImage applyFilter(const QImage &buffer, QPainter *p, const QRectF &bounds) const;
200 void setSupported(bool supported);
201 bool supported() const;
202 QRectF filterRegion(const QRectF &itemBounds) const;
203
204 QSvgRectF rect() const { return m_rect; }
205 QtSvg::UnitTypes filterUnits() const { return m_filterUnits; }
206 QtSvg::UnitTypes primitiveUnits() const { return m_primitiveUnits; }
207
208private:
209 QSvgRectF m_rect;
210 QtSvg::UnitTypes m_filterUnits;
211 QtSvg::UnitTypes m_primitiveUnits;
212 bool m_supported;
213};
214
215
216class Q_SVG_EXPORT QSvgSwitch : public QSvgStructureNode
217{
218public:
219 QSvgSwitch(QSvgNode *parent);
220 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
221 Type type() const override;
222
223 QSvgNode *childToRender() const;
224private:
225 void init();
226private:
227 QString m_systemLanguage;
228 QString m_systemLanguagePrefix;
229};
230
231class Q_SVG_EXPORT QSvgMask : public QSvgStructureNode
232{
233public:
234 QSvgMask(QSvgNode *parent, QSvgRectF bounds,
235 QtSvg::UnitTypes contentsUnits);
236 void drawCommand(QPainter *, QSvgExtraStates &) override {};
237 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
238 Type type() const override;
239 QImage createMask(QPainter *p, QSvgExtraStates &states, QSvgNode *targetNode, QRectF *globalRect) const;
240 QImage createMask(QPainter *p, QSvgExtraStates &states, const QRectF &localRect, QRectF *globalRect) const;
241
242 QSvgRectF rect() const
243 {
244 return m_rect;
245 }
246
247 QtSvg::UnitTypes contentUnits() const
248 {
249 return m_contentUnits;
250 }
251
252private:
253 QSvgRectF m_rect;
254 QtSvg::UnitTypes m_contentUnits;
255};
256
257class Q_SVG_EXPORT QSvgPattern : public QSvgStructureNode
258{
259public:
260 QSvgPattern(QSvgNode *parent, QSvgRectF bounds, QRectF viewBox,
261 QtSvg::UnitTypes contentUnits, QTransform transform);
262 void drawCommand(QPainter *, QSvgExtraStates &) override {};
263 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
264 QImage patternImage(QPainter *p, QSvgExtraStates &states, const QSvgNode *patternElement);
265 Type type() const override;
266 const QTransform& appliedTransform() const { return m_appliedTransform; }
267 const QTransform &transform() const { return m_transform; }
268 const QSvgRectF &rect() const { return m_rect; }
269 const QRectF &viewBox() const { return m_viewBox; }
270 QtSvg::UnitTypes contentUnits() const { return m_contentUnits; }
271
272private:
273 QImage renderPattern(QSize size, qreal contentScaleX, qreal contentScaleY);
274 void calculateAppliedTransform(QTransform& worldTransform, QRectF peLocalBB, QSize imageSize);
275
276private:
277 QTransform m_appliedTransform;
278 QSvgRectF m_rect;
279 QRectF m_viewBox;
280 QtSvg::UnitTypes m_contentUnits;
281 mutable bool m_isRendering;
282 QTransform m_transform;
283};
284
285QT_END_NAMESPACE
286
287#endif // QSVGSTRUCTURE_P_H
friend class QPainter
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
#define qPrintable(string)
Definition qstring.h:1683
static QByteArray qt_inflateSvgzDataFrom(QIODevice *device, bool doCheckContent=true)
static bool isValidMatrix(const QTransform &transform)
static bool hasSvgHeader(const QByteArray &buf)
std::optional< int > calculateSizeValue(bool isPercent, int sizeValue, qreal viewBoxSizeValue)