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