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
23QT_BEGIN_NAMESPACE
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;
102protected:
103 void setPainterToRectAndAdjustment(QPainter *p) const;
104protected:
105 QRectF m_rect;
106 QRectF m_viewBox;
107 QPointF m_refP;
108 PreserveAspectRatios m_pAspectRatios;
109 Overflow m_overflow;
110};
111
112Q_DECLARE_OPERATORS_FOR_FLAGS(QSvgSymbolLike::PreserveAspectRatios)
113
114class Q_SVG_EXPORT QSvgSymbol : public QSvgSymbolLike
115{
116public:
117 QSvgSymbol(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP,
118 QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow);
119 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
120 Type type() const override;
121};
122
123class Q_SVG_EXPORT QSvgMarker : public QSvgSymbolLike
124{
125public:
126 enum class Orientation : quint8 {
127 Auto,
128 AutoStartReverse,
129 Value
130 };
131 enum class MarkerUnits : quint8 {
132 StrokeWidth,
133 UserSpaceOnUse
134 };
135
136 QSvgMarker(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP,
137 QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow,
138 Orientation orientation, qreal orientationAngle, MarkerUnits markerUnits);
139 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
140 static void drawMarkersForNode(QSvgNode *node, QPainter *p, QSvgExtraStates &states);
141 static QRectF markersBoundsForNode(const QSvgNode *node, QPainter *p, QSvgExtraStates &states);
142
143 Orientation orientation() const {
144 return m_orientation;
145 }
146 qreal orientationAngle() const {
147 return m_orientationAngle;
148 }
149 MarkerUnits markerUnits() const {
150 return m_markerUnits;
151 }
152 Type type() const override;
153
154private:
155 static void drawHelper(const QSvgNode *node, QPainter *p,
156 QSvgExtraStates &states, QRectF *boundingRect = nullptr);
157
158 Orientation m_orientation;
159 qreal m_orientationAngle;
160 MarkerUnits m_markerUnits;
161};
162
163class Q_SVG_EXPORT QSvgFilterContainer : public QSvgStructureNode
164{
165public:
166
167 QSvgFilterContainer(QSvgNode *parent, const QSvgRectF &bounds, QtSvg::UnitTypes filterUnits, QtSvg::UnitTypes primitiveUnits);
168 void drawCommand(QPainter *, QSvgExtraStates &) override {};
169 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
170 Type type() const override;
171 QImage applyFilter(const QImage &buffer, QPainter *p, const QRectF &bounds) const;
172 void setSupported(bool supported);
173 bool supported() const;
174 QRectF filterRegion(const QRectF &itemBounds) const;
175private:
176 QSvgRectF m_rect;
177 QtSvg::UnitTypes m_filterUnits;
178 QtSvg::UnitTypes m_primitiveUnits;
179 bool m_supported;
180};
181
182
183class Q_SVG_EXPORT QSvgSwitch : public QSvgStructureNode
184{
185public:
186 QSvgSwitch(QSvgNode *parent);
187 void drawCommand(QPainter *p, QSvgExtraStates &states) override;
188 Type type() const override;
189
190 QSvgNode *childToRender() const;
191private:
192 void init();
193private:
194 QString m_systemLanguage;
195 QString m_systemLanguagePrefix;
196};
197
198class Q_SVG_EXPORT QSvgMask : public QSvgStructureNode
199{
200public:
201 QSvgMask(QSvgNode *parent, QSvgRectF bounds,
202 QtSvg::UnitTypes contentsUnits);
203 void drawCommand(QPainter *, QSvgExtraStates &) override {};
204 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
205 Type type() const override;
206 QImage createMask(QPainter *p, QSvgExtraStates &states, QSvgNode *targetNode, QRectF *globalRect) const;
207 QImage createMask(QPainter *p, QSvgExtraStates &states, const QRectF &localRect, QRectF *globalRect) const;
208
209 QSvgRectF rect() const
210 {
211 return m_rect;
212 }
213
214 QtSvg::UnitTypes contentUnits() const
215 {
216 return m_contentUnits;
217 }
218
219private:
220 QSvgRectF m_rect;
221 QtSvg::UnitTypes m_contentUnits;
222};
223
224class Q_SVG_EXPORT QSvgPattern : public QSvgStructureNode
225{
226public:
227 QSvgPattern(QSvgNode *parent, QSvgRectF bounds, QRectF viewBox,
228 QtSvg::UnitTypes contentUnits, QTransform transform);
229 void drawCommand(QPainter *, QSvgExtraStates &) override {};
230 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
231 QImage patternImage(QPainter *p, QSvgExtraStates &states, const QSvgNode *patternElement);
232 Type type() const override;
233 const QTransform& appliedTransform() const { return m_appliedTransform; }
234
235private:
236 QImage renderPattern(QSize size, qreal contentScaleX, qreal contentScaleY);
237 void calculateAppliedTransform(QTransform& worldTransform, QRectF peLocalBB, QSize imageSize);
238
239private:
240 QTransform m_appliedTransform;
241 QSvgRectF m_rect;
242 QRectF m_viewBox;
243 QtSvg::UnitTypes m_contentUnits;
244 QTransform m_transform;
245};
246
247QT_END_NAMESPACE
248
249#endif // QSVGSTRUCTURE_P_H
250

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtsvg/src/svg/qsvgstructure_p.h