1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt SVG module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QSVGGRAPHICS_P_H
41#define QSVGGRAPHICS_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include "qsvgnode_p.h"
55#include "qtsvgglobal_p.h"
56
57#include "QtGui/qpainterpath.h"
58#include "QtGui/qimage.h"
59#include "QtGui/qtextlayout.h"
60#include "QtGui/qtextoption.h"
61#include "QtCore/qstack.h"
62
63QT_BEGIN_NAMESPACE
64
65class QTextCharFormat;
66
67class Q_SVG_PRIVATE_EXPORT QSvgAnimation : public QSvgNode
68{
69public:
70 void draw(QPainter *p, QSvgExtraStates &states) override;
71 Type type() const override;
72};
73
74class Q_SVG_PRIVATE_EXPORT QSvgArc : public QSvgNode
75{
76public:
77 QSvgArc(QSvgNode *parent, const QPainterPath &path);
78 void draw(QPainter *p, QSvgExtraStates &states) override;
79 Type type() const override;
80 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
81private:
82 QPainterPath m_path;
83};
84
85class Q_SVG_PRIVATE_EXPORT QSvgEllipse : public QSvgNode
86{
87public:
88 QSvgEllipse(QSvgNode *parent, const QRectF &rect);
89 void draw(QPainter *p, QSvgExtraStates &states) override;
90 Type type() const override;
91 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
92private:
93 QRectF m_bounds;
94};
95
96class Q_SVG_PRIVATE_EXPORT QSvgCircle : public QSvgEllipse
97{
98public:
99 QSvgCircle(QSvgNode *parent, const QRectF &rect) : QSvgEllipse(parent, rect) { }
100 Type type() const override;
101};
102
103class Q_SVG_PRIVATE_EXPORT QSvgImage : public QSvgNode
104{
105public:
106 QSvgImage(QSvgNode *parent, const QImage &image,
107 const QRectF &bounds);
108 void draw(QPainter *p, QSvgExtraStates &states) override;
109 Type type() const override;
110 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
111private:
112 QImage m_image;
113 QRectF m_bounds;
114};
115
116class Q_SVG_PRIVATE_EXPORT QSvgLine : public QSvgNode
117{
118public:
119 QSvgLine(QSvgNode *parent, const QLineF &line);
120 void draw(QPainter *p, QSvgExtraStates &states) override;
121 Type type() const override;
122 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
123private:
124 QLineF m_line;
125};
126
127class Q_SVG_PRIVATE_EXPORT QSvgPath : public QSvgNode
128{
129public:
130 QSvgPath(QSvgNode *parent, const QPainterPath &qpath);
131 void draw(QPainter *p, QSvgExtraStates &states) override;
132 Type type() const override;
133 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
134
135 QPainterPath *qpath() {
136 return &m_path;
137 }
138private:
139 QPainterPath m_path;
140};
141
142class Q_SVG_PRIVATE_EXPORT QSvgPolygon : public QSvgNode
143{
144public:
145 QSvgPolygon(QSvgNode *parent, const QPolygonF &poly);
146 void draw(QPainter *p, QSvgExtraStates &states) override;
147 Type type() const override;
148 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
149private:
150 QPolygonF m_poly;
151};
152
153class Q_SVG_PRIVATE_EXPORT QSvgPolyline : public QSvgNode
154{
155public:
156 QSvgPolyline(QSvgNode *parent, const QPolygonF &poly);
157 void draw(QPainter *p, QSvgExtraStates &states) override;
158 Type type() const override;
159 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
160private:
161 QPolygonF m_poly;
162};
163
164class Q_SVG_PRIVATE_EXPORT QSvgRect : public QSvgNode
165{
166public:
167 QSvgRect(QSvgNode *paren, const QRectF &rect, int rx=0, int ry=0);
168 Type type() const override;
169 void draw(QPainter *p, QSvgExtraStates &states) override;
170 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
171private:
172 QRectF m_rect;
173 int m_rx, m_ry;
174};
175
176class QSvgTspan;
177
178class Q_SVG_PRIVATE_EXPORT QSvgText : public QSvgNode
179{
180public:
181 enum WhitespaceMode
182 {
183 Default,
184 Preserve
185 };
186
187 QSvgText(QSvgNode *parent, const QPointF &coord);
188 ~QSvgText();
189 void setTextArea(const QSizeF &size);
190
191 void draw(QPainter *p, QSvgExtraStates &states) override;
192 Type type() const override;
193
194 void addTspan(QSvgTspan *tspan) {m_tspans.append(t: tspan);}
195 void addText(const QString &text);
196 void addLineBreak() {m_tspans.append(t: LINEBREAK);}
197 void setWhitespaceMode(WhitespaceMode mode) {m_mode = mode;}
198
199 //QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
200private:
201 static QSvgTspan * const LINEBREAK;
202
203 QPointF m_coord;
204
205 // 'm_tspans' is also used to store characters outside tspans and line breaks.
206 // If a 'm_tspan' item is null, it indicates a line break.
207 QVector<QSvgTspan *> m_tspans;
208
209 Type m_type;
210 QSizeF m_size;
211 WhitespaceMode m_mode;
212};
213
214class Q_SVG_PRIVATE_EXPORT QSvgTspan : public QSvgNode
215{
216public:
217 // tspans are also used to store normal text, so the 'isProperTspan' is used to separate text from tspan.
218 QSvgTspan(QSvgNode *parent, bool isProperTspan = true)
219 : QSvgNode(parent), m_mode(QSvgText::Default), m_isTspan(isProperTspan)
220 {
221 }
222 ~QSvgTspan() { };
223 Type type() const override { return TSPAN; }
224 void draw(QPainter *, QSvgExtraStates &) override { Q_ASSERT(!"Tspans should be drawn through QSvgText::draw()."); }
225 void addText(const QString &text) {m_text += text;}
226 const QString &text() const {return m_text;}
227 bool isTspan() const {return m_isTspan;}
228 void setWhitespaceMode(QSvgText::WhitespaceMode mode) {m_mode = mode;}
229 QSvgText::WhitespaceMode whitespaceMode() const {return m_mode;}
230private:
231 QString m_text;
232 QSvgText::WhitespaceMode m_mode;
233 bool m_isTspan;
234};
235
236class QSvgUse : public QSvgNode
237{
238public:
239 QSvgUse(const QPointF &start, QSvgNode *parent, QSvgNode *link);
240 QSvgUse(const QPointF &start, QSvgNode *parent, const QString &linkId)
241 : QSvgUse(start, parent, nullptr)
242 { m_linkId = linkId; }
243 void draw(QPainter *p, QSvgExtraStates &states) override;
244 Type type() const override;
245 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
246 bool isResolved() const { return m_link != nullptr; }
247 QString linkId() const { return m_linkId; }
248 void setLink(QSvgNode *link) { m_link = link; }
249
250private:
251 QSvgNode *m_link;
252 QPointF m_start;
253 QString m_linkId;
254 mutable bool m_recursing;
255};
256
257class QSvgVideo : public QSvgNode
258{
259public:
260 void draw(QPainter *p, QSvgExtraStates &states) override;
261 Type type() const override;
262};
263
264QT_END_NAMESPACE
265
266#endif // QSVGGRAPHICS_P_H
267

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