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