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