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