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
27QT_BEGIN_NAMESPACE
28
29class QTextCharFormat;
30
31class Q_SVG_PRIVATE_EXPORT QSvgAnimation : public QSvgNode
32{
33public:
34 void draw(QPainter *p, QSvgExtraStates &states) override;
35 Type type() const override;
36};
37
38class Q_SVG_PRIVATE_EXPORT QSvgArc : public QSvgNode
39{
40public:
41 QSvgArc(QSvgNode *parent, const QPainterPath &path);
42 void draw(QPainter *p, QSvgExtraStates &states) override;
43 Type type() const override;
44 QRectF fastBounds(QPainter *p, QSvgExtraStates &states) const override;
45 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
46private:
47 QPainterPath m_path;
48};
49
50class Q_SVG_PRIVATE_EXPORT QSvgEllipse : public QSvgNode
51{
52public:
53 QSvgEllipse(QSvgNode *parent, const QRectF &rect);
54 void draw(QPainter *p, QSvgExtraStates &states) override;
55 Type type() const override;
56 QRectF fastBounds(QPainter *p, QSvgExtraStates &states) const override;
57 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
58private:
59 QRectF m_bounds;
60};
61
62class Q_SVG_PRIVATE_EXPORT QSvgCircle : public QSvgEllipse
63{
64public:
65 QSvgCircle(QSvgNode *parent, const QRectF &rect) : QSvgEllipse(parent, rect) { }
66 Type type() const override;
67};
68
69class Q_SVG_PRIVATE_EXPORT QSvgImage : public QSvgNode
70{
71public:
72 QSvgImage(QSvgNode *parent, const QImage &image,
73 const QRectF &bounds);
74 void draw(QPainter *p, QSvgExtraStates &states) override;
75 Type type() const override;
76 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
77private:
78 QImage m_image;
79 QRectF m_bounds;
80};
81
82class Q_SVG_PRIVATE_EXPORT QSvgLine : public QSvgNode
83{
84public:
85 QSvgLine(QSvgNode *parent, const QLineF &line);
86 void draw(QPainter *p, QSvgExtraStates &states) override;
87 Type type() const override;
88 QRectF fastBounds(QPainter *p, QSvgExtraStates &states) const override;
89 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
90private:
91 QLineF m_line;
92};
93
94class Q_SVG_PRIVATE_EXPORT QSvgPath : public QSvgNode
95{
96public:
97 QSvgPath(QSvgNode *parent, const QPainterPath &qpath);
98 void draw(QPainter *p, QSvgExtraStates &states) override;
99 Type type() const override;
100 QRectF fastBounds(QPainter *p, QSvgExtraStates &states) const override;
101 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
102
103 QPainterPath *qpath() {
104 return &m_path;
105 }
106private:
107 QPainterPath m_path;
108};
109
110class Q_SVG_PRIVATE_EXPORT QSvgPolygon : public QSvgNode
111{
112public:
113 QSvgPolygon(QSvgNode *parent, const QPolygonF &poly);
114 void draw(QPainter *p, QSvgExtraStates &states) override;
115 Type type() const override;
116 QRectF fastBounds(QPainter *p, QSvgExtraStates &states) const override;
117 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
118private:
119 QPolygonF m_poly;
120};
121
122class Q_SVG_PRIVATE_EXPORT QSvgPolyline : public QSvgNode
123{
124public:
125 QSvgPolyline(QSvgNode *parent, const QPolygonF &poly);
126 void draw(QPainter *p, QSvgExtraStates &states) override;
127 Type type() const override;
128 QRectF fastBounds(QPainter *p, QSvgExtraStates &states) const override;
129 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
130private:
131 QPolygonF m_poly;
132};
133
134class Q_SVG_PRIVATE_EXPORT QSvgRect : public QSvgNode
135{
136public:
137 QSvgRect(QSvgNode *paren, const QRectF &rect, int rx=0, int ry=0);
138 Type type() const override;
139 void draw(QPainter *p, QSvgExtraStates &states) override;
140 QRectF fastBounds(QPainter *p, QSvgExtraStates &states) const override;
141 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
142private:
143 QRectF m_rect;
144 int m_rx, m_ry;
145};
146
147class QSvgTspan;
148
149class Q_SVG_PRIVATE_EXPORT QSvgText : public QSvgNode
150{
151public:
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 draw(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 fastBounds(QPainter *p, QSvgExtraStates &states) const override;
171 QRectF bounds(QPainter *p, QSvgExtraStates &states) const override;
172
173private:
174 bool precheck(QPainter *p) const;
175 void draw_helper(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
190class Q_SVG_PRIVATE_EXPORT QSvgTspan : public QSvgNode
191{
192public:
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 draw(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;}
206private:
207 QString m_text;
208 QSvgText::WhitespaceMode m_mode;
209 bool m_isTspan;
210};
211
212class QSvgUse : public QSvgNode
213{
214public:
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 draw(QPainter *p, QSvgExtraStates &states) override;
220 Type type() const override;
221 QRectF bounds(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
227private:
228 QSvgNode *m_link;
229 QPointF m_start;
230 QString m_linkId;
231 mutable bool m_recursing;
232};
233
234class QSvgVideo : public QSvgNode
235{
236public:
237 void draw(QPainter *p, QSvgExtraStates &states) override;
238 Type type() const override;
239};
240
241QT_END_NAMESPACE
242
243#endif // QSVGGRAPHICS_P_H
244

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