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

Provided by KDAB

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

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