| 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 QSVGSTYLE_P_H | 
| 41 | #define QSVGSTYLE_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 "QtGui/qpainter.h" | 
| 55 | #include "QtGui/qpen.h" | 
| 56 | #include "QtGui/qbrush.h" | 
| 57 | #include "QtGui/qtransform.h" | 
| 58 | #include "QtGui/qcolor.h" | 
| 59 | #include "QtGui/qfont.h" | 
| 60 | #include <qdebug.h> | 
| 61 | #include "qtsvgglobal_p.h" | 
| 62 |  | 
| 63 | QT_BEGIN_NAMESPACE | 
| 64 |  | 
| 65 | class QPainter; | 
| 66 | class QSvgNode; | 
| 67 | class QSvgFont; | 
| 68 | class QSvgTinyDocument; | 
| 69 |  | 
| 70 | template <class T> class QSvgRefCounter | 
| 71 | { | 
| 72 | public: | 
| 73 |     QSvgRefCounter() { t = 0; } | 
| 74 |     QSvgRefCounter(T *_t) | 
| 75 |     { | 
| 76 |         t = _t; | 
| 77 |         if (t) | 
| 78 |             t->ref(); | 
| 79 |     } | 
| 80 |     QSvgRefCounter(const QSvgRefCounter &other) | 
| 81 |     { | 
| 82 |         t = other.t; | 
| 83 |         if (t) | 
| 84 |             t->ref(); | 
| 85 |     } | 
| 86 |     QSvgRefCounter &operator =(T *_t) | 
| 87 |     { | 
| 88 |         if(_t) | 
| 89 |             _t->ref(); | 
| 90 |         if (t) | 
| 91 |             t->deref(); | 
| 92 |         t = _t; | 
| 93 |         return *this; | 
| 94 |     } | 
| 95 |     QSvgRefCounter &operator =(const QSvgRefCounter &other) | 
| 96 |     { | 
| 97 |         if(other.t) | 
| 98 |             other.t->ref(); | 
| 99 |         if (t) | 
| 100 |             t->deref(); | 
| 101 |         t = other.t; | 
| 102 |         return *this; | 
| 103 |     } | 
| 104 |     ~QSvgRefCounter() | 
| 105 |     { | 
| 106 |         if (t) | 
| 107 |             t->deref(); | 
| 108 |     } | 
| 109 |  | 
| 110 |     inline T *operator->() const { return t; } | 
| 111 |     inline operator T*() const { return t; } | 
| 112 |  | 
| 113 | private: | 
| 114 |     T *t; | 
| 115 | }; | 
| 116 |  | 
| 117 | class Q_SVG_PRIVATE_EXPORT QSvgRefCounted | 
| 118 | { | 
| 119 | public: | 
| 120 |     QSvgRefCounted() { _ref = 0; } | 
| 121 |     virtual ~QSvgRefCounted() {} | 
| 122 |     void ref() { | 
| 123 |         ++_ref; | 
| 124 | //        qDebug() << this << ": adding ref, now " << _ref; | 
| 125 |     } | 
| 126 |     void deref() { | 
| 127 | //        qDebug() << this << ": removing ref, now " << _ref; | 
| 128 |         if(!--_ref) { | 
| 129 | //            qDebug("     deleting"); | 
| 130 |             delete this; | 
| 131 |         } | 
| 132 |     } | 
| 133 | private: | 
| 134 |     int _ref; | 
| 135 | }; | 
| 136 |  | 
| 137 | struct Q_SVG_PRIVATE_EXPORT  | 
| 138 | { | 
| 139 |     (); | 
| 140 |  | 
| 141 |     qreal ; | 
| 142 |     qreal ; | 
| 143 |     QSvgFont *; | 
| 144 |     Qt::Alignment ; | 
| 145 |     int ; | 
| 146 |     Qt::FillRule ; | 
| 147 |     qreal ; | 
| 148 |     int  = 0; | 
| 149 |     int  = 0; | 
| 150 |     bool ; // true if pen is cosmetic | 
| 151 | }; | 
| 152 |  | 
| 153 | class Q_SVG_PRIVATE_EXPORT QSvgStyleProperty : public QSvgRefCounted | 
| 154 | { | 
| 155 | public: | 
| 156 |     enum Type | 
| 157 |     { | 
| 158 |         QUALITY, | 
| 159 |         FILL, | 
| 160 |         VIEWPORT_FILL, | 
| 161 |         FONT, | 
| 162 |         STROKE, | 
| 163 |         SOLID_COLOR, | 
| 164 |         GRADIENT, | 
| 165 |         TRANSFORM, | 
| 166 |         ANIMATE_TRANSFORM, | 
| 167 |         ANIMATE_COLOR, | 
| 168 |         OPACITY, | 
| 169 |         COMP_OP | 
| 170 |     }; | 
| 171 | public: | 
| 172 |     virtual ~QSvgStyleProperty(); | 
| 173 |     virtual void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) = 0; | 
| 174 |     virtual void (QPainter *p, QSvgExtraStates &states) =0; | 
| 175 |     virtual Type type() const=0; | 
| 176 | }; | 
| 177 |  | 
| 178 | class Q_SVG_PRIVATE_EXPORT QSvgFillStyleProperty : public QSvgStyleProperty | 
| 179 | { | 
| 180 | public: | 
| 181 |     virtual QBrush (QPainter *p, QSvgExtraStates &states) = 0; | 
| 182 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 183 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 184 | }; | 
| 185 |  | 
| 186 | class Q_SVG_PRIVATE_EXPORT QSvgQualityStyle : public QSvgStyleProperty | 
| 187 | { | 
| 188 | public: | 
| 189 |     QSvgQualityStyle(int color); | 
| 190 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 191 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 192 |     Type type() const override; | 
| 193 | private: | 
| 194 |     // color-render ing v 	v 	'auto' | 'optimizeSpeed' | | 
| 195 |     //                                  'optimizeQuality' | 'inherit' | 
| 196 |     //int m_colorRendering; | 
| 197 |  | 
| 198 |     // shape-rendering v 	v 	'auto' | 'optimizeSpeed' | 'crispEdges' | | 
| 199 |     //                                  'geometricPrecision' | 'inherit' | 
| 200 |     //QSvgShapeRendering m_shapeRendering; | 
| 201 |  | 
| 202 |  | 
| 203 |     // text-rendering    v 	v 	'auto' | 'optimizeSpeed' | 'optimizeLegibility' | 
| 204 |     //                                | 'geometricPrecision' | 'inherit' | 
| 205 |     //QSvgTextRendering m_textRendering; | 
| 206 |  | 
| 207 |  | 
| 208 |     // vector-effect         v 	x 	'default' | 'non-scaling-stroke' | 'inherit' | 
| 209 |     //QSvgVectorEffect m_vectorEffect; | 
| 210 |  | 
| 211 |     // image-rendering v 	v 	'auto' | 'optimizeSpeed' | 'optimizeQuality' | | 
| 212 |     //                                      'inherit' | 
| 213 |     //QSvgImageRendering m_imageRendering; | 
| 214 | }; | 
| 215 |  | 
| 216 |  | 
| 217 |  | 
| 218 | class Q_SVG_PRIVATE_EXPORT QSvgOpacityStyle : public QSvgStyleProperty | 
| 219 | { | 
| 220 | public: | 
| 221 |     QSvgOpacityStyle(qreal opacity); | 
| 222 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 223 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 224 |     Type type() const override; | 
| 225 | private: | 
| 226 |     qreal m_opacity; | 
| 227 |     qreal m_oldOpacity; | 
| 228 | }; | 
| 229 |  | 
| 230 | class Q_SVG_PRIVATE_EXPORT QSvgFillStyle : public QSvgStyleProperty | 
| 231 | { | 
| 232 | public: | 
| 233 |     QSvgFillStyle(); | 
| 234 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 235 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 236 |     Type type() const override; | 
| 237 |  | 
| 238 |     void setFillRule(Qt::FillRule f); | 
| 239 |     void setFillOpacity(qreal opacity); | 
| 240 |     void setFillStyle(QSvgFillStyleProperty* style); | 
| 241 |     void setBrush(QBrush brush); | 
| 242 |  | 
| 243 |     const QBrush & qbrush() const | 
| 244 |     { | 
| 245 |         return m_fill; | 
| 246 |     } | 
| 247 |  | 
| 248 |     qreal fillOpacity() const | 
| 249 |     { | 
| 250 |         return m_fillOpacity; | 
| 251 |     } | 
| 252 |  | 
| 253 |     Qt::FillRule fillRule() const | 
| 254 |     { | 
| 255 |         return m_fillRule; | 
| 256 |     } | 
| 257 |  | 
| 258 |     QSvgFillStyleProperty* style() const | 
| 259 |     { | 
| 260 |         return m_style; | 
| 261 |     } | 
| 262 |  | 
| 263 |     void setGradientId(const QString &Id) | 
| 264 |     { | 
| 265 |         m_gradientId = Id; | 
| 266 |     } | 
| 267 |  | 
| 268 |     QString gradientId() const | 
| 269 |     { | 
| 270 |         return m_gradientId; | 
| 271 |     } | 
| 272 |  | 
| 273 |     void setGradientResolved(bool resolved) | 
| 274 |     { | 
| 275 |         m_gradientResolved = resolved; | 
| 276 |     } | 
| 277 |  | 
| 278 |     bool isGradientResolved() const | 
| 279 |     { | 
| 280 |         return m_gradientResolved; | 
| 281 |     } | 
| 282 |  | 
| 283 | private: | 
| 284 |     // fill            v 	v 	'inherit' | <Paint.datatype> | 
| 285 |     // fill-opacity    v 	v 	'inherit' | <OpacityValue.datatype> | 
| 286 |     QBrush m_fill; | 
| 287 |     QBrush m_oldFill; | 
| 288 |     QSvgFillStyleProperty *m_style; | 
| 289 |  | 
| 290 |     Qt::FillRule m_fillRule; | 
| 291 |     Qt::FillRule m_oldFillRule; | 
| 292 |     qreal m_fillOpacity; | 
| 293 |     qreal m_oldFillOpacity; | 
| 294 |  | 
| 295 |     QString m_gradientId; | 
| 296 |     uint m_gradientResolved : 1; | 
| 297 |  | 
| 298 |     uint m_fillRuleSet : 1; | 
| 299 |     uint m_fillOpacitySet : 1; | 
| 300 |     uint m_fillSet : 1; | 
| 301 | }; | 
| 302 |  | 
| 303 | class Q_SVG_PRIVATE_EXPORT QSvgViewportFillStyle : public QSvgStyleProperty | 
| 304 | { | 
| 305 | public: | 
| 306 |     QSvgViewportFillStyle(const QBrush &brush); | 
| 307 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 308 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 309 |     Type type() const override; | 
| 310 |  | 
| 311 |     const QBrush & qbrush() const | 
| 312 |     { | 
| 313 |         return m_viewportFill; | 
| 314 |     } | 
| 315 | private: | 
| 316 |     // viewport-fill         v 	x 	'inherit' | <Paint.datatype> | 
| 317 |     // viewport-fill-opacity 	v 	x 	'inherit' | <OpacityValue.datatype> | 
| 318 |     QBrush m_viewportFill; | 
| 319 |  | 
| 320 |     QBrush m_oldFill; | 
| 321 | }; | 
| 322 |  | 
| 323 | class Q_SVG_PRIVATE_EXPORT QSvgFontStyle : public QSvgStyleProperty | 
| 324 | { | 
| 325 | public: | 
| 326 |     static const int LIGHTER = -1; | 
| 327 |     static const int BOLDER = 1; | 
| 328 |  | 
| 329 |     QSvgFontStyle(QSvgFont *font, QSvgTinyDocument *doc); | 
| 330 |     QSvgFontStyle(); | 
| 331 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 332 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 333 |     Type type() const override; | 
| 334 |  | 
| 335 |     void setSize(qreal size) | 
| 336 |     { | 
| 337 |         // Store the _pixel_ size in the font. Since QFont::setPixelSize() only takes an int, call | 
| 338 |         // QFont::SetPointSize() instead. Set proper font size just before rendering. | 
| 339 |         m_qfont.setPointSizeF(size); | 
| 340 |         m_sizeSet = 1; | 
| 341 |     } | 
| 342 |  | 
| 343 |     void setTextAnchor(Qt::Alignment anchor) | 
| 344 |     { | 
| 345 |         m_textAnchor = anchor; | 
| 346 |         m_textAnchorSet = 1; | 
| 347 |     } | 
| 348 |  | 
| 349 |     void setFamily(const QString &family) | 
| 350 |     { | 
| 351 |         m_qfont.setFamilies({family}); | 
| 352 |         m_familySet = 1; | 
| 353 |     } | 
| 354 |  | 
| 355 |     void setStyle(QFont::Style fontStyle) { | 
| 356 |         m_qfont.setStyle(fontStyle); | 
| 357 |         m_styleSet = 1; | 
| 358 |     } | 
| 359 |  | 
| 360 |     void setVariant(QFont::Capitalization fontVariant) | 
| 361 |     { | 
| 362 |         m_qfont.setCapitalization(fontVariant); | 
| 363 |         m_variantSet = 1; | 
| 364 |     } | 
| 365 |  | 
| 366 |     static int SVGToQtWeight(int weight); | 
| 367 |  | 
| 368 |     void setWeight(int weight) | 
| 369 |     { | 
| 370 |         m_weight = weight; | 
| 371 |         m_weightSet = 1; | 
| 372 |     } | 
| 373 |  | 
| 374 |     QSvgFont * svgFont() const | 
| 375 |     { | 
| 376 |         return m_svgFont; | 
| 377 |     } | 
| 378 |  | 
| 379 |     const QFont &qfont() const | 
| 380 |     { | 
| 381 |         return m_qfont; | 
| 382 |     } | 
| 383 |  | 
| 384 |     QSvgTinyDocument *doc() const {return m_doc;} | 
| 385 |  | 
| 386 | private: | 
| 387 |     QSvgFont *m_svgFont; | 
| 388 |     QSvgTinyDocument *m_doc; | 
| 389 |     QFont m_qfont; | 
| 390 |  | 
| 391 |     int m_weight; | 
| 392 |     Qt::Alignment m_textAnchor; | 
| 393 |  | 
| 394 |     QSvgFont *m_oldSvgFont; | 
| 395 |     QFont m_oldQFont; | 
| 396 |     Qt::Alignment m_oldTextAnchor; | 
| 397 |     int m_oldWeight; | 
| 398 |  | 
| 399 |     uint m_familySet : 1; | 
| 400 |     uint m_sizeSet : 1; | 
| 401 |     uint m_styleSet : 1; | 
| 402 |     uint m_variantSet : 1; | 
| 403 |     uint m_weightSet : 1; | 
| 404 |     uint m_textAnchorSet : 1; | 
| 405 | }; | 
| 406 |  | 
| 407 | class Q_SVG_PRIVATE_EXPORT QSvgStrokeStyle : public QSvgStyleProperty | 
| 408 | { | 
| 409 | public: | 
| 410 |     QSvgStrokeStyle(); | 
| 411 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 412 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 413 |     Type type() const override; | 
| 414 |  | 
| 415 |     void setStroke(QBrush brush) | 
| 416 |     { | 
| 417 |         m_stroke.setBrush(brush); | 
| 418 |         m_style = 0; | 
| 419 |         m_strokeSet = 1; | 
| 420 |     } | 
| 421 |  | 
| 422 |     void setStyle(QSvgFillStyleProperty *style) | 
| 423 |     { | 
| 424 |         m_style = style; | 
| 425 |         m_strokeSet = 1; | 
| 426 |     } | 
| 427 |  | 
| 428 |     void setDashArray(const QVector<qreal> &dashes); | 
| 429 |  | 
| 430 |     void setDashArrayNone() | 
| 431 |     { | 
| 432 |         m_stroke.setStyle(Qt::SolidLine); | 
| 433 |         m_strokeDashArraySet = 1; | 
| 434 |     } | 
| 435 |  | 
| 436 |     void setDashOffset(qreal offset) | 
| 437 |     { | 
| 438 |         m_strokeDashOffset = offset; | 
| 439 |         m_strokeDashOffsetSet = 1; | 
| 440 |     } | 
| 441 |  | 
| 442 |     void setLineCap(Qt::PenCapStyle cap) | 
| 443 |     { | 
| 444 |         m_stroke.setCapStyle(cap); | 
| 445 |         m_strokeLineCapSet = 1; | 
| 446 |     } | 
| 447 |  | 
| 448 |     void setLineJoin(Qt::PenJoinStyle join) | 
| 449 |     { | 
| 450 |         m_stroke.setJoinStyle(join); | 
| 451 |         m_strokeLineJoinSet = 1; | 
| 452 |     } | 
| 453 |  | 
| 454 |     void setMiterLimit(qreal limit) | 
| 455 |     { | 
| 456 |         m_stroke.setMiterLimit(limit); | 
| 457 |         m_strokeMiterLimitSet = 1; | 
| 458 |     } | 
| 459 |  | 
| 460 |     void setOpacity(qreal opacity) | 
| 461 |     { | 
| 462 |         m_strokeOpacity = opacity; | 
| 463 |         m_strokeOpacitySet = 1; | 
| 464 |     } | 
| 465 |  | 
| 466 |     void setWidth(qreal width) | 
| 467 |     { | 
| 468 |         m_stroke.setWidthF(width); | 
| 469 |         m_strokeWidthSet = 1; | 
| 470 |         Q_ASSERT(!m_strokeDashArraySet); // set width before dash array. | 
| 471 |     } | 
| 472 |  | 
| 473 |     qreal width() | 
| 474 |     { | 
| 475 |         return m_stroke.widthF(); | 
| 476 |     } | 
| 477 |  | 
| 478 |     void setVectorEffect(bool nonScalingStroke) | 
| 479 |     { | 
| 480 |         m_vectorEffect = nonScalingStroke; | 
| 481 |         m_vectorEffectSet = 1; | 
| 482 |     } | 
| 483 |  | 
| 484 |     QSvgFillStyleProperty* style() const | 
| 485 |     { | 
| 486 |         return m_style; | 
| 487 |     } | 
| 488 |  | 
| 489 |     void setGradientId(const QString &Id) | 
| 490 |     { | 
| 491 |         m_gradientId = Id; | 
| 492 |     } | 
| 493 |  | 
| 494 |     QString gradientId() const | 
| 495 |     { | 
| 496 |         return m_gradientId; | 
| 497 |     } | 
| 498 |  | 
| 499 |     void setGradientResolved(bool resolved) | 
| 500 |     { | 
| 501 |         m_gradientResolved = resolved; | 
| 502 |     } | 
| 503 |  | 
| 504 |     bool isGradientResolved() const | 
| 505 |     { | 
| 506 |         return m_gradientResolved; | 
| 507 |     } | 
| 508 |  | 
| 509 |     QPen stroke() const | 
| 510 |     { | 
| 511 |         return m_stroke; | 
| 512 |     } | 
| 513 |  | 
| 514 | private: | 
| 515 |     // stroke            v 	v 	'inherit' | <Paint.datatype> | 
| 516 |     // stroke-dasharray  v 	v 	'inherit' | <StrokeDashArrayValue.datatype> | 
| 517 |     // stroke-dashoffset v 	v 	'inherit' | <StrokeDashOffsetValue.datatype> | 
| 518 |     // stroke-linecap    v 	v 	'butt' | 'round' | 'square' | 'inherit' | 
| 519 |     // stroke-linejoin   v 	v 	'miter' | 'round' | 'bevel' | 'inherit' | 
| 520 |     // stroke-miterlimit v 	v 	'inherit' | <StrokeMiterLimitValue.datatype> | 
| 521 |     // stroke-opacity    v 	v 	'inherit' | <OpacityValue.datatype> | 
| 522 |     // stroke-width      v 	v 	'inherit' | <StrokeWidthValue.datatype> | 
| 523 |     QPen m_stroke; | 
| 524 |     QPen m_oldStroke; | 
| 525 |     qreal m_strokeOpacity; | 
| 526 |     qreal m_oldStrokeOpacity; | 
| 527 |     qreal m_strokeDashOffset; | 
| 528 |     qreal m_oldStrokeDashOffset; | 
| 529 |  | 
| 530 |     QSvgFillStyleProperty *m_style; | 
| 531 |     QString m_gradientId; | 
| 532 |     uint m_gradientResolved : 1; | 
| 533 |     uint m_vectorEffect : 1; | 
| 534 |     uint m_oldVectorEffect : 1; | 
| 535 |  | 
| 536 |     uint m_strokeSet : 1; | 
| 537 |     uint m_strokeDashArraySet : 1; | 
| 538 |     uint m_strokeDashOffsetSet : 1; | 
| 539 |     uint m_strokeLineCapSet : 1; | 
| 540 |     uint m_strokeLineJoinSet : 1; | 
| 541 |     uint m_strokeMiterLimitSet : 1; | 
| 542 |     uint m_strokeOpacitySet : 1; | 
| 543 |     uint m_strokeWidthSet : 1; | 
| 544 |     uint m_vectorEffectSet : 1; | 
| 545 | }; | 
| 546 |  | 
| 547 | class Q_SVG_PRIVATE_EXPORT QSvgSolidColorStyle : public QSvgFillStyleProperty | 
| 548 | { | 
| 549 | public: | 
| 550 |     QSvgSolidColorStyle(const QColor &color); | 
| 551 |     Type type() const override; | 
| 552 |  | 
| 553 |     const QColor & qcolor() const | 
| 554 |     { | 
| 555 |         return m_solidColor; | 
| 556 |     } | 
| 557 |  | 
| 558 |     QBrush (QPainter *, QSvgExtraStates &) override | 
| 559 |     { | 
| 560 |         return m_solidColor; | 
| 561 |     } | 
| 562 |  | 
| 563 | private: | 
| 564 |     // solid-color       v 	x 	'inherit' | <SVGColor.datatype> | 
| 565 |     // solid-opacity     v 	x 	'inherit' | <OpacityValue.datatype> | 
| 566 |     QColor m_solidColor; | 
| 567 |  | 
| 568 |     QBrush m_oldFill; | 
| 569 |     QPen   m_oldStroke; | 
| 570 | }; | 
| 571 |  | 
| 572 | class Q_SVG_PRIVATE_EXPORT QSvgGradientStyle : public QSvgFillStyleProperty | 
| 573 | { | 
| 574 | public: | 
| 575 |     QSvgGradientStyle(QGradient *grad); | 
| 576 |     ~QSvgGradientStyle() { delete m_gradient; } | 
| 577 |     Type type() const override; | 
| 578 |  | 
| 579 |     void setStopLink(const QString &link, QSvgTinyDocument *doc); | 
| 580 |     QString stopLink() const { return m_link; } | 
| 581 |     void resolveStops(); | 
| 582 |     void resolveStops_helper(QStringList *visited); | 
| 583 |  | 
| 584 |     void setTransform(const QTransform &transform); | 
| 585 |     QTransform qtransform() const | 
| 586 |     { | 
| 587 |         return m_transform; | 
| 588 |     } | 
| 589 |  | 
| 590 |     QGradient *qgradient() const | 
| 591 |     { | 
| 592 |         return m_gradient; | 
| 593 |     } | 
| 594 |  | 
| 595 |     bool gradientStopsSet() const | 
| 596 |     { | 
| 597 |         return m_gradientStopsSet; | 
| 598 |     } | 
| 599 |  | 
| 600 |     void setGradientStopsSet(bool set) | 
| 601 |     { | 
| 602 |         m_gradientStopsSet = set; | 
| 603 |     } | 
| 604 |  | 
| 605 |     QBrush (QPainter *, QSvgExtraStates &) override; | 
| 606 | private: | 
| 607 |     QGradient      *m_gradient; | 
| 608 |     QTransform m_transform; | 
| 609 |  | 
| 610 |     QSvgTinyDocument *m_doc; | 
| 611 |     QString           m_link; | 
| 612 |     bool m_gradientStopsSet; | 
| 613 | }; | 
| 614 |  | 
| 615 | class Q_SVG_PRIVATE_EXPORT QSvgTransformStyle : public QSvgStyleProperty | 
| 616 | { | 
| 617 | public: | 
| 618 |     QSvgTransformStyle(const QTransform &transform); | 
| 619 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 620 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 621 |     Type type() const override; | 
| 622 |  | 
| 623 |     const QTransform & qtransform() const | 
| 624 |     { | 
| 625 |         return m_transform; | 
| 626 |     } | 
| 627 | private: | 
| 628 |     //7.6 The transform  attribute | 
| 629 |     QTransform m_transform; | 
| 630 |     QTransform m_oldWorldTransform; | 
| 631 | }; | 
| 632 |  | 
| 633 |  | 
| 634 | class Q_SVG_PRIVATE_EXPORT QSvgAnimateTransform : public QSvgStyleProperty | 
| 635 | { | 
| 636 | public: | 
| 637 |     enum TransformType | 
| 638 |     { | 
| 639 |         Empty, | 
| 640 |         Translate, | 
| 641 |         Scale, | 
| 642 |         Rotate, | 
| 643 |         SkewX, | 
| 644 |         SkewY | 
| 645 |     }; | 
| 646 |     enum Additive | 
| 647 |     { | 
| 648 |         Sum, | 
| 649 |         Replace | 
| 650 |     }; | 
| 651 | public: | 
| 652 |     QSvgAnimateTransform(int startMs, int endMs, int by = 0); | 
| 653 |     void setArgs(TransformType type, Additive additive, const QVector<qreal> &args); | 
| 654 |     void setFreeze(bool freeze); | 
| 655 |     void setRepeatCount(qreal repeatCount); | 
| 656 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 657 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 658 |     Type type() const override; | 
| 659 |     QSvgAnimateTransform::Additive additiveType() const | 
| 660 |     { | 
| 661 |         return m_additive; | 
| 662 |     } | 
| 663 |  | 
| 664 |     bool animActive(qreal totalTimeElapsed) | 
| 665 |     { | 
| 666 |         if (totalTimeElapsed < m_from) | 
| 667 |             return false; | 
| 668 |         if (m_freeze || m_repeatCount < 0) // fill="freeze" or repeat="indefinite" | 
| 669 |             return true; | 
| 670 |         if (m_totalRunningTime == 0) | 
| 671 |             return false; | 
| 672 |         qreal animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime; | 
| 673 |         if (animationFrame > m_repeatCount) | 
| 674 |             return false; | 
| 675 |         return true; | 
| 676 |     } | 
| 677 |  | 
| 678 |     bool transformApplied() const | 
| 679 |     { | 
| 680 |         return m_transformApplied; | 
| 681 |     } | 
| 682 |  | 
| 683 |     // Call this instead of revert if you know that revert is unnecessary. | 
| 684 |     void clearTransformApplied() | 
| 685 |     { | 
| 686 |         m_transformApplied = false; | 
| 687 |     } | 
| 688 |  | 
| 689 | protected: | 
| 690 |     void resolveMatrix(const QSvgNode *node); | 
| 691 | private: | 
| 692 |     qreal m_from; | 
| 693 |     qreal m_totalRunningTime; | 
| 694 |     TransformType m_type; | 
| 695 |     Additive m_additive; | 
| 696 |     QVector<qreal> m_args; | 
| 697 |     int m_count; | 
| 698 |     QTransform m_transform; | 
| 699 |     QTransform m_oldWorldTransform; | 
| 700 |     bool m_finished; | 
| 701 |     bool m_freeze; | 
| 702 |     qreal m_repeatCount; | 
| 703 |     bool m_transformApplied; | 
| 704 | }; | 
| 705 |  | 
| 706 |  | 
| 707 | class Q_SVG_PRIVATE_EXPORT QSvgAnimateColor : public QSvgStyleProperty | 
| 708 | { | 
| 709 | public: | 
| 710 |     QSvgAnimateColor(int startMs, int endMs, int by = 0); | 
| 711 |     void setArgs(bool fill, const QList<QColor> &colors); | 
| 712 |     void setFreeze(bool freeze); | 
| 713 |     void setRepeatCount(qreal repeatCount); | 
| 714 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 715 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 716 |     Type type() const override; | 
| 717 | private: | 
| 718 |     qreal m_from; | 
| 719 |     qreal m_totalRunningTime; | 
| 720 |     QList<QColor> m_colors; | 
| 721 |     QBrush m_oldBrush; | 
| 722 |     QPen   m_oldPen; | 
| 723 |     bool m_fill; | 
| 724 |     bool m_finished; | 
| 725 |     bool m_freeze; | 
| 726 |     qreal m_repeatCount; | 
| 727 | }; | 
| 728 |  | 
| 729 |  | 
| 730 | class Q_SVG_PRIVATE_EXPORT QSvgCompOpStyle : public QSvgStyleProperty | 
| 731 | { | 
| 732 | public: | 
| 733 |     QSvgCompOpStyle(QPainter::CompositionMode mode); | 
| 734 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states) override; | 
| 735 |     void (QPainter *p, QSvgExtraStates &states) override; | 
| 736 |     Type type() const override; | 
| 737 |  | 
| 738 |     const QPainter::CompositionMode & compOp() const | 
| 739 |     { | 
| 740 |         return m_mode; | 
| 741 |     } | 
| 742 | private: | 
| 743 |     //comp-op attribute | 
| 744 |     QPainter::CompositionMode m_mode; | 
| 745 |  | 
| 746 |     QPainter::CompositionMode m_oldMode; | 
| 747 | }; | 
| 748 |  | 
| 749 |  | 
| 750 | class Q_SVG_PRIVATE_EXPORT QSvgStyle | 
| 751 | { | 
| 752 | public: | 
| 753 |     QSvgStyle() | 
| 754 |         : quality(0), | 
| 755 |           fill(0), | 
| 756 |           viewportFill(0), | 
| 757 |           font(0), | 
| 758 |           stroke(0), | 
| 759 |           solidColor(0), | 
| 760 |           gradient(0), | 
| 761 |           transform(0), | 
| 762 |           animateColor(0), | 
| 763 |           opacity(0), | 
| 764 |           compop(0) | 
| 765 |     {} | 
| 766 |     ~QSvgStyle(); | 
| 767 |  | 
| 768 |     void (QPainter *p, const QSvgNode *node, QSvgExtraStates &states); | 
| 769 |     void (QPainter *p, QSvgExtraStates &states); | 
| 770 |     QSvgRefCounter<QSvgQualityStyle>      quality; | 
| 771 |     QSvgRefCounter<QSvgFillStyle>         fill; | 
| 772 |     QSvgRefCounter<QSvgViewportFillStyle> viewportFill; | 
| 773 |     QSvgRefCounter<QSvgFontStyle>         font; | 
| 774 |     QSvgRefCounter<QSvgStrokeStyle>       stroke; | 
| 775 |     QSvgRefCounter<QSvgSolidColorStyle>   solidColor; | 
| 776 |     QSvgRefCounter<QSvgGradientStyle>     gradient; | 
| 777 |     QSvgRefCounter<QSvgTransformStyle>    transform; | 
| 778 |     QSvgRefCounter<QSvgAnimateColor>      animateColor; | 
| 779 |     QList<QSvgRefCounter<QSvgAnimateTransform> >   animateTransforms; | 
| 780 |     QSvgRefCounter<QSvgOpacityStyle>      opacity; | 
| 781 |     QSvgRefCounter<QSvgCompOpStyle>       compop; | 
| 782 | }; | 
| 783 |  | 
| 784 | /********************************************************/ | 
| 785 | // NOT implemented: | 
| 786 |  | 
| 787 | // color           v 	v 	'inherit' | <Color.datatype> | 
| 788 | //QColor m_color; | 
| 789 |  | 
| 790 | // display         v 	x 	'inline' | 'block' | 'list-item' | 
| 791 | //                                 | 'run-in' | 'compact' | 'marker' | | 
| 792 | //                                 'table' | 'inline-table' | | 
| 793 | //                                 'table-row-group' | 'table-header-group' | | 
| 794 | //                                 'table-footer-group' | 'table-row' | | 
| 795 | //                                 'table-column-group' | 'table-column' | | 
| 796 | //                                 'table-cell' | 'table-caption' | | 
| 797 | //                                 'none' | 'inherit' | 
| 798 | //QSvgDisplayStyle m_display; | 
| 799 |  | 
| 800 | // display-align   v 	v 	'auto' | 'before' | 'center' | 'after' | 'inherit' | 
| 801 | //QSvgDisplayAlign m_displayAlign; | 
| 802 |  | 
| 803 | // line-increment  v 	v 	'auto' | 'inherit' | <Number.datatype> | 
| 804 | //int m_lineIncrement; | 
| 805 |  | 
| 806 | // text-anchor       v 	v 	'start' | 'middle' | 'end' | 'inherit' | 
| 807 | //QSvgTextAnchor m_textAnchor; | 
| 808 |  | 
| 809 | // visibility 	v 	v 	'visible' | 'hidden' | 'inherit' | 
| 810 | //QSvgVisibility m_visibility; | 
| 811 |  | 
| 812 | /******************************************************/ | 
| 813 | // the following do not make sense for us | 
| 814 |  | 
| 815 | // pointer-events  v 	v 	'visiblePainted' | 'visibleFill' | 'visibleStroke' | | 
| 816 | //                              'visible' | 'painted' | 'fill' | 'stroke' | 'all' | | 
| 817 | //                              'none' | 'inherit' | 
| 818 | //QSvgPointEvents m_pointerEvents; | 
| 819 |  | 
| 820 | // audio-level     v  	x  	'inherit' | <Number.datatype> | 
| 821 |  | 
| 822 | QT_END_NAMESPACE | 
| 823 |  | 
| 824 | #endif // QSVGSTYLE_P_H | 
| 825 |  |