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 QSVGGRAPHICS_P_H |
5 | #define QSVGGRAPHICS_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 | #include "qtsvgglobal_p.h" |
20 | |
21 | #include "QtGui/qpainterpath.h" |
22 | #include "QtGui/qimage.h" |
23 | #include "QtGui/qtextlayout.h" |
24 | #include "QtGui/qtextoption.h" |
25 | #include "QtCore/qstack.h" |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QTextCharFormat; |
30 | |
31 | class Q_SVG_PRIVATE_EXPORT QSvgAnimation : public QSvgNode |
32 | { |
33 | public: |
34 | void (QPainter *p, QSvgExtraStates &states) override; |
35 | Type type() const override; |
36 | }; |
37 | |
38 | class Q_SVG_PRIVATE_EXPORT QSvgArc : public QSvgNode |
39 | { |
40 | public: |
41 | QSvgArc(QSvgNode *parent, const QPainterPath &path); |
42 | void (QPainter *p, QSvgExtraStates &states) override; |
43 | Type type() const override; |
44 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
45 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
46 | private: |
47 | QPainterPath m_path; |
48 | }; |
49 | |
50 | class Q_SVG_PRIVATE_EXPORT QSvgEllipse : public QSvgNode |
51 | { |
52 | public: |
53 | QSvgEllipse(QSvgNode *parent, const QRectF &rect); |
54 | void (QPainter *p, QSvgExtraStates &states) override; |
55 | Type type() const override; |
56 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
57 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
58 | private: |
59 | QRectF m_bounds; |
60 | }; |
61 | |
62 | class Q_SVG_PRIVATE_EXPORT QSvgCircle : public QSvgEllipse |
63 | { |
64 | public: |
65 | QSvgCircle(QSvgNode *parent, const QRectF &rect) : QSvgEllipse(parent, rect) { } |
66 | Type type() const override; |
67 | }; |
68 | |
69 | class Q_SVG_PRIVATE_EXPORT QSvgImage : public QSvgNode |
70 | { |
71 | public: |
72 | QSvgImage(QSvgNode *parent, const QImage &image, |
73 | const QRectF &bounds); |
74 | void (QPainter *p, QSvgExtraStates &states) override; |
75 | Type type() const override; |
76 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
77 | private: |
78 | QImage m_image; |
79 | QRectF m_bounds; |
80 | }; |
81 | |
82 | class Q_SVG_PRIVATE_EXPORT QSvgLine : public QSvgNode |
83 | { |
84 | public: |
85 | QSvgLine(QSvgNode *parent, const QLineF &line); |
86 | void (QPainter *p, QSvgExtraStates &states) override; |
87 | Type type() const override; |
88 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
89 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
90 | private: |
91 | QLineF m_line; |
92 | }; |
93 | |
94 | class Q_SVG_PRIVATE_EXPORT QSvgPath : public QSvgNode |
95 | { |
96 | public: |
97 | QSvgPath(QSvgNode *parent, const QPainterPath &qpath); |
98 | void (QPainter *p, QSvgExtraStates &states) override; |
99 | Type type() const override; |
100 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
101 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
102 | |
103 | QPainterPath *qpath() { |
104 | return &m_path; |
105 | } |
106 | private: |
107 | QPainterPath m_path; |
108 | }; |
109 | |
110 | class Q_SVG_PRIVATE_EXPORT QSvgPolygon : public QSvgNode |
111 | { |
112 | public: |
113 | QSvgPolygon(QSvgNode *parent, const QPolygonF &poly); |
114 | void (QPainter *p, QSvgExtraStates &states) override; |
115 | Type type() const override; |
116 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
117 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
118 | private: |
119 | QPolygonF m_poly; |
120 | }; |
121 | |
122 | class Q_SVG_PRIVATE_EXPORT QSvgPolyline : public QSvgNode |
123 | { |
124 | public: |
125 | QSvgPolyline(QSvgNode *parent, const QPolygonF &poly); |
126 | void (QPainter *p, QSvgExtraStates &states) override; |
127 | Type type() const override; |
128 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
129 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
130 | private: |
131 | QPolygonF m_poly; |
132 | }; |
133 | |
134 | class Q_SVG_PRIVATE_EXPORT QSvgRect : public QSvgNode |
135 | { |
136 | public: |
137 | QSvgRect(QSvgNode *paren, const QRectF &rect, int rx=0, int ry=0); |
138 | Type type() const override; |
139 | void (QPainter *p, QSvgExtraStates &states) override; |
140 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
141 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
142 | private: |
143 | QRectF m_rect; |
144 | int m_rx, m_ry; |
145 | }; |
146 | |
147 | class QSvgTspan; |
148 | |
149 | class Q_SVG_PRIVATE_EXPORT QSvgText : public QSvgNode |
150 | { |
151 | public: |
152 | enum WhitespaceMode |
153 | { |
154 | Default, |
155 | Preserve |
156 | }; |
157 | |
158 | QSvgText(QSvgNode *parent, const QPointF &coord); |
159 | ~QSvgText(); |
160 | void setTextArea(const QSizeF &size); |
161 | |
162 | void (QPainter *p, QSvgExtraStates &states) override; |
163 | Type type() const override; |
164 | |
165 | void addTspan(QSvgTspan *tspan) {m_tspans.append(t: tspan);} |
166 | void addText(const QString &text); |
167 | void addLineBreak() {m_tspans.append(t: LINEBREAK);} |
168 | void setWhitespaceMode(WhitespaceMode mode) {m_mode = mode;} |
169 | |
170 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
171 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
172 | |
173 | private: |
174 | bool precheck(QPainter *p) const; |
175 | void (QPainter *p, QSvgExtraStates &states, QRectF *boundingRect = nullptr) const; |
176 | |
177 | static QSvgTspan * const LINEBREAK; |
178 | |
179 | QPointF m_coord; |
180 | |
181 | // 'm_tspans' is also used to store characters outside tspans and line breaks. |
182 | // If a 'm_tspan' item is null, it indicates a line break. |
183 | QList<QSvgTspan *> m_tspans; |
184 | |
185 | Type m_type; |
186 | QSizeF m_size; |
187 | WhitespaceMode m_mode; |
188 | }; |
189 | |
190 | class Q_SVG_PRIVATE_EXPORT QSvgTspan : public QSvgNode |
191 | { |
192 | public: |
193 | // tspans are also used to store normal text, so the 'isProperTspan' is used to separate text from tspan. |
194 | QSvgTspan(QSvgNode *parent, bool isProperTspan = true) |
195 | : QSvgNode(parent), m_mode(QSvgText::Default), m_isTspan(isProperTspan) |
196 | { |
197 | } |
198 | ~QSvgTspan() { }; |
199 | Type type() const override { return TSPAN; } |
200 | void (QPainter *, QSvgExtraStates &) override { Q_ASSERT(!"Tspans should be drawn through QSvgText::draw()." ); } |
201 | void addText(const QString &text) {m_text += text;} |
202 | const QString &text() const {return m_text;} |
203 | bool isTspan() const {return m_isTspan;} |
204 | void setWhitespaceMode(QSvgText::WhitespaceMode mode) {m_mode = mode;} |
205 | QSvgText::WhitespaceMode whitespaceMode() const {return m_mode;} |
206 | private: |
207 | QString m_text; |
208 | QSvgText::WhitespaceMode m_mode; |
209 | bool m_isTspan; |
210 | }; |
211 | |
212 | class QSvgUse : public QSvgNode |
213 | { |
214 | public: |
215 | QSvgUse(const QPointF &start, QSvgNode *parent, QSvgNode *link); |
216 | QSvgUse(const QPointF &start, QSvgNode *parent, const QString &linkId) |
217 | : QSvgUse(start, parent, nullptr) |
218 | { m_linkId = linkId; } |
219 | void (QPainter *p, QSvgExtraStates &states) override; |
220 | Type type() const override; |
221 | QRectF (QPainter *p, QSvgExtraStates &states) const override; |
222 | bool isResolved() const { return m_link != nullptr; } |
223 | QString linkId() const { return m_linkId; } |
224 | void setLink(QSvgNode *link) { m_link = link; } |
225 | QSvgNode *link() const { return m_link; } |
226 | |
227 | private: |
228 | QSvgNode *m_link; |
229 | QPointF m_start; |
230 | QString m_linkId; |
231 | mutable bool m_recursing; |
232 | }; |
233 | |
234 | class QSvgVideo : public QSvgNode |
235 | { |
236 | public: |
237 | void (QPainter *p, QSvgExtraStates &states) override; |
238 | Type type() const override; |
239 | }; |
240 | |
241 | QT_END_NAMESPACE |
242 | |
243 | #endif // QSVGGRAPHICS_P_H |
244 | |