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
24#include <list>
25
27
28class QSvgDocument;
29class QSvgNode;
30class QPainter;
31class QSvgDefs;
32
33class Q_SVG_EXPORT QSvgStructureNode : public QSvgNode
34{
35public:
36 QSvgStructureNode(QSvgNode *parent);
37 ~QSvgStructureNode() override;
38
39 QSvgNode *scopeNode(const QString &id) const;
40 void addChild(std::unique_ptr<QSvgNode> child, const QString &id);
41 QRectF internalBounds(QPainter *p, QSvgExtraStates &states) const override;
42 QRectF decoratedInternalBounds(QPainter *p, QSvgExtraStates &states) const override;
43 QSvgNode *previousSiblingNode(QSvgNode *n) const;
44 const std::list<std::unique_ptr<QSvgNode>> &renderers() const { return m_renderers; }
45
46protected:
47 void releaseDescendants();
48
49protected:
50 std::list<std::unique_ptr<QSvgNode>> m_renderers;
51 mutable bool m_recursing = false;
52};
53
54class Q_SVG_EXPORT QSvgG : public QSvgStructureNode
55{
56public:
57 QSvgG(QSvgNode *parent);
58 ~QSvgG() override;
59
60 void drawCommand(QPainter *, QSvgExtraStates &) override;
61 bool shouldDrawNode(QPainter *p, QSvgExtraStates &states) const override;
62 Type type() const override;
63 bool requiresGroupRendering() const override;
64};
65
66class Q_SVG_EXPORT QSvgDefs : public QSvgStructureNode
67{
68public:
69 QSvgDefs(QSvgNode *parent);
70 ~QSvgDefs() override;
71
72 void drawCommand(QPainter *, QSvgExtraStates &) override {};
73 bool shouldDrawNode(QPainter *p, QSvgExtraStates &states) const override;
74 Type type() const override;
75};
76
77class Q_SVG_EXPORT QSvgSymbolLike : public QSvgStructureNode
78{
79 // Marker, Symbol and potentially other elements share a lot of common
80 // attributes and functionality. By making a common base class we can
81 // avoid repetition.
82public:
83 enum class Overflow : quint8 {
84 Visible,
85 Hidden,
86 Scroll = Visible, //Will not support scrolling
87 Auto = Visible
88 };
89
90 enum class PreserveAspectRatio : quint8 {
91 None = 0b000000,
92 xMin = 0b000001,
93 xMid = 0b000010,
94 xMax = 0b000011,
95 yMin = 0b000100,
96 yMid = 0b001000,
97 yMax = 0b001100,
98 meet = 0b010000,
99 slice = 0b100000,
100 xMask = xMin | xMid | xMax,
101 yMask = yMin | yMid | yMax,
102 xyMask = xMask | yMask,
103 meetSliceMask = meet | slice
104 };
105 Q_DECLARE_FLAGS(PreserveAspectRatios, PreserveAspectRatio)
106
107 QSvgSymbolLike(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP,
108 QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow);
109 ~QSvgSymbolLike() override;
110
111 void drawCommand(QPainter *, QSvgExtraStates &) override {};
112 QRectF decoratedInternalBounds(QPainter *p, QSvgExtraStates &states) const override;
113 bool requiresGroupRendering() const override;
114
115 QRectF viewBox() const
116 {
117 return m_viewBox;
118 }
119
120 QRectF rect() const
121 {
122 return m_rect;
123 }
124
125 QPointF refP() const
126 {
127 return m_refP;
128 }
129
130 QTransform aspectRatioTransform() const;
131 QRectF clipRect() const;
132
133 Overflow overflow() const
134 {
135 return m_overflow;
136 }
137
138 PreserveAspectRatios preserveAspectRatios() const
139 {
140 return m_pAspectRatios;
141 }
142
143protected:
144 void setPainterToRectAndAdjustment(QPainter *p) const;
145protected:
146 QRectF m_rect;
147 QRectF m_viewBox;
148 QPointF m_refP;
149 PreserveAspectRatios m_pAspectRatios;
150 Overflow m_overflow;
151};
152
153Q_DECLARE_OPERATORS_FOR_FLAGS(QSvgSymbolLike::PreserveAspectRatios)
154
155class Q_SVG_EXPORT QSvgSymbol : public QSvgSymbolLike
156{
157public:
158 QSvgSymbol(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP,
159 QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow);
160 ~QSvgSymbol() override;
161
162 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
163 Type type() const override;
164};
165
166class Q_SVG_EXPORT QSvgMarker : public QSvgSymbolLike
167{
168public:
169 enum class Orientation : quint8 {
170 Auto,
171 AutoStartReverse,
172 Value
173 };
174 enum class MarkerUnits : quint8 {
175 StrokeWidth,
176 UserSpaceOnUse
177 };
178
179 QSvgMarker(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP,
180 QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow,
181 Orientation orientation, qreal orientationAngle, MarkerUnits markerUnits);
182 ~QSvgMarker() override;
183
184 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
185 static void drawMarkersForNode(QSvgNode *node, QPainter *p, QSvgExtraStates &states);
186 static QRectF markersBoundsForNode(const QSvgNode *node, QPainter *p, QSvgExtraStates &states);
187
188 Orientation orientation() const {
189 return m_orientation;
190 }
191 qreal orientationAngle() const {
192 return m_orientationAngle;
193 }
194 MarkerUnits markerUnits() const {
195 return m_markerUnits;
196 }
197 Type type() const override;
198
199private:
200 static void drawHelper(const QSvgNode *node, QPainter *p,
201 QSvgExtraStates &states, QRectF *boundingRect = nullptr);
202
203 Orientation m_orientation;
204 qreal m_orientationAngle;
205 MarkerUnits m_markerUnits;
206};
207
208class Q_SVG_EXPORT QSvgFilterContainer : public QSvgStructureNode
209{
210public:
211 QSvgFilterContainer(QSvgNode *parent, const QSvgRectF &bounds, QtSvg::UnitTypes filterUnits, QtSvg::UnitTypes primitiveUnits);
212 ~QSvgFilterContainer() override;
213
214 void drawCommand(QPainter *, QSvgExtraStates &) override {};
215 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
216 Type type() const override;
217 QImage applyFilter(const QImage &buffer, QPainter *p, const QRectF &bounds) const;
218 void setSupported(bool supported);
219 bool supported() const;
220 QRectF filterRegion(const QRectF &itemBounds) const;
221
222 QSvgRectF rect() const { return m_rect; }
223 QtSvg::UnitTypes filterUnits() const { return m_filterUnits; }
224 QtSvg::UnitTypes primitiveUnits() const { return m_primitiveUnits; }
225
226private:
227 QSvgRectF m_rect;
228 QtSvg::UnitTypes m_filterUnits;
229 QtSvg::UnitTypes m_primitiveUnits;
230 bool m_supported;
231};
232
233
234class Q_SVG_EXPORT QSvgSwitch : public QSvgStructureNode
235{
236public:
237 QSvgSwitch(QSvgNode *parent);
238 ~QSvgSwitch() override;
239
240 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
241 Type type() const override;
242
243 QSvgNode *childToRender() const;
244private:
245 void init();
246private:
247 QString m_systemLanguage;
248 QString m_systemLanguagePrefix;
249};
250
251class Q_SVG_EXPORT QSvgMask : public QSvgStructureNode
252{
253public:
254 QSvgMask(QSvgNode *parent, QSvgRectF bounds,
255 QtSvg::UnitTypes contentsUnits);
256 ~QSvgMask() override;
257
258 void drawCommand(QPainter *, QSvgExtraStates &) override {};
259 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
260 Type type() const override;
261 QImage createMask(QPainter *p, QSvgExtraStates &states, QSvgNode *targetNode, QRectF *globalRect) const;
262 QImage createMask(QPainter *p, QSvgExtraStates &states, const QRectF &localRect, QRectF *globalRect) const;
263
264 QSvgRectF rect() const
265 {
266 return m_rect;
267 }
268
269 QtSvg::UnitTypes contentUnits() const
270 {
271 return m_contentUnits;
272 }
273
274private:
275 QSvgRectF m_rect;
276 QtSvg::UnitTypes m_contentUnits;
277};
278
279class Q_SVG_EXPORT QSvgPattern : public QSvgStructureNode
280{
281public:
282 QSvgPattern(QSvgNode *parent, QSvgRectF bounds, QRectF viewBox,
283 QtSvg::UnitTypes contentUnits, QTransform transform);
284 ~QSvgPattern() override;
285
286 void drawCommand(QPainter *, QSvgExtraStates &) override {};
287 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
288 QImage patternImage(QPainter *p, QSvgExtraStates &states, const QSvgNode *patternElement);
289 Type type() const override;
290 const QTransform& appliedTransform() const { return m_appliedTransform; }
291 const QTransform &transform() const { return m_transform; }
292 const QSvgRectF &rect() const { return m_rect; }
293 const QRectF &viewBox() const { return m_viewBox; }
294 QtSvg::UnitTypes contentUnits() const { return m_contentUnits; }
295
296private:
297 QImage renderPattern(QSize size, qreal contentScaleX, qreal contentScaleY);
298 void calculateAppliedTransform(QTransform& worldTransform, QRectF peLocalBB, QSize imageSize);
299
300private:
301 QTransform m_appliedTransform;
302 QSvgRectF m_rect;
303 QRectF m_viewBox;
304 QtSvg::UnitTypes m_contentUnits;
305 mutable bool m_isRendering;
306 QTransform m_transform;
307};
308
309QT_END_NAMESPACE
310
311#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)