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