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