src/svg/qsvgstyle.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    71 
    71 
    72 QSvgStyleProperty::~QSvgStyleProperty()
    72 QSvgStyleProperty::~QSvgStyleProperty()
    73 {
    73 {
    74 }
    74 }
    75 
    75 
    76 void QSvgFillStyleProperty::apply(QPainter *, const QRectF &, QSvgNode *, QSvgExtraStates &)
    76 void QSvgFillStyleProperty::apply(QPainter *, const QSvgNode *, QSvgExtraStates &)
    77 {
    77 {
    78     Q_ASSERT(!"This should not be called!");
    78     Q_ASSERT(!"This should not be called!");
    79 }
    79 }
    80 
    80 
    81 void QSvgFillStyleProperty::revert(QPainter *, QSvgExtraStates &)
    81 void QSvgFillStyleProperty::revert(QPainter *, QSvgExtraStates &)
    87 QSvgQualityStyle::QSvgQualityStyle(int color)
    87 QSvgQualityStyle::QSvgQualityStyle(int color)
    88     : m_colorRendering(color)
    88     : m_colorRendering(color)
    89 {
    89 {
    90 
    90 
    91 }
    91 }
    92 void QSvgQualityStyle::apply(QPainter *, const QRectF &, QSvgNode *, QSvgExtraStates &)
    92 void QSvgQualityStyle::apply(QPainter *, const QSvgNode *, QSvgExtraStates &)
    93 {
    93 {
    94 
    94 
    95 }
    95 }
    96 void QSvgQualityStyle::revert(QPainter *, QSvgExtraStates &)
    96 void QSvgQualityStyle::revert(QPainter *, QSvgExtraStates &)
    97 {
    97 {
   134     m_fill = brush;
   134     m_fill = brush;
   135     m_style = 0;
   135     m_style = 0;
   136     m_fillSet = 1;
   136     m_fillSet = 1;
   137 }
   137 }
   138 
   138 
   139 void QSvgFillStyle::apply(QPainter *p, const QRectF &, QSvgNode *, QSvgExtraStates &states)
   139 void QSvgFillStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &states)
   140 {
   140 {
   141     m_oldFill = p->brush();
   141     m_oldFill = p->brush();
   142     m_oldFillRule = states.fillRule;
   142     m_oldFillRule = states.fillRule;
   143     m_oldFillOpacity = states.fillOpacity;
   143     m_oldFillOpacity = states.fillOpacity;
   144 
   144 
   167 QSvgViewportFillStyle::QSvgViewportFillStyle(const QBrush &brush)
   167 QSvgViewportFillStyle::QSvgViewportFillStyle(const QBrush &brush)
   168     : m_viewportFill(brush)
   168     : m_viewportFill(brush)
   169 {
   169 {
   170 }
   170 }
   171 
   171 
   172 void QSvgViewportFillStyle::apply(QPainter *p, const QRectF &, QSvgNode *, QSvgExtraStates &)
   172 void QSvgViewportFillStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &)
   173 {
   173 {
   174     m_oldFill = p->brush();
   174     m_oldFill = p->brush();
   175     p->setBrush(m_viewportFill);
   175     p->setBrush(m_viewportFill);
   176 }
   176 }
   177 
   177 
   222         return QFont::Black;
   222         return QFont::Black;
   223     }
   223     }
   224     return QFont::Normal;
   224     return QFont::Normal;
   225 }
   225 }
   226 
   226 
   227 void QSvgFontStyle::apply(QPainter *p, const QRectF &, QSvgNode *, QSvgExtraStates &states)
   227 void QSvgFontStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &states)
   228 {
   228 {
   229     m_oldQFont = p->font();
   229     m_oldQFont = p->font();
   230     m_oldSvgFont = states.svgFont;
   230     m_oldSvgFont = states.svgFont;
   231     m_oldTextAnchor = states.textAnchor;
   231     m_oldTextAnchor = states.textAnchor;
   232     m_oldWeight = states.fontWeight;
   232     m_oldWeight = states.fontWeight;
   290     , m_strokeWidthSet(0)
   290     , m_strokeWidthSet(0)
   291     , m_vectorEffectSet(0)
   291     , m_vectorEffectSet(0)
   292 {
   292 {
   293 }
   293 }
   294 
   294 
   295 void QSvgStrokeStyle::apply(QPainter *p, const QRectF &, QSvgNode *, QSvgExtraStates &states)
   295 void QSvgStrokeStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &states)
   296 {
   296 {
   297     m_oldStroke = p->pen();
   297     m_oldStroke = p->pen();
   298     m_oldStrokeOpacity = states.strokeOpacity;
   298     m_oldStrokeOpacity = states.strokeOpacity;
   299     m_oldStrokeDashOffset = states.strokeDashOffset;
   299     m_oldStrokeDashOffset = states.strokeDashOffset;
   300     m_oldVectorEffect = states.vectorEffect;
   300     m_oldVectorEffect = states.vectorEffect;
   441 QSvgTransformStyle::QSvgTransformStyle(const QTransform &trans)
   441 QSvgTransformStyle::QSvgTransformStyle(const QTransform &trans)
   442     : m_transform(trans)
   442     : m_transform(trans)
   443 {
   443 {
   444 }
   444 }
   445 
   445 
   446 void QSvgTransformStyle::apply(QPainter *p, const QRectF &, QSvgNode *, QSvgExtraStates &)
   446 void QSvgTransformStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &)
   447 {
   447 {
   448     m_oldWorldTransform = p->worldTransform();
   448     m_oldWorldTransform = p->worldTransform();
   449     p->setWorldTransform(m_transform, true);
   449     p->setWorldTransform(m_transform, true);
   450 }
   450 }
   451 
   451 
   499     : m_mode(mode)
   499     : m_mode(mode)
   500 {
   500 {
   501 
   501 
   502 }
   502 }
   503 
   503 
   504 void QSvgCompOpStyle::apply(QPainter *p, const QRectF &, QSvgNode *, QSvgExtraStates &)
   504 void QSvgCompOpStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &)
   505 {
   505 {
   506     m_oldMode = p->compositionMode();
   506     m_oldMode = p->compositionMode();
   507     p->setCompositionMode(m_mode);
   507     p->setCompositionMode(m_mode);
   508 }
   508 }
   509 
   509 
   519 
   519 
   520 QSvgStyle::~QSvgStyle()
   520 QSvgStyle::~QSvgStyle()
   521 {
   521 {
   522 }
   522 }
   523 
   523 
   524 void QSvgStyle::apply(QPainter *p, const QRectF &rect, QSvgNode *node, QSvgExtraStates &states)
   524 void QSvgStyle::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &states)
   525 {
   525 {
   526     if (quality) {
   526     if (quality) {
   527         quality->apply(p, rect, node, states);
   527         quality->apply(p, node, states);
   528     }
   528     }
   529 
   529 
   530     if (fill) {
   530     if (fill) {
   531         fill->apply(p, rect, node, states);
   531         fill->apply(p, node, states);
   532     }
   532     }
   533 
   533 
   534     if (viewportFill) {
   534     if (viewportFill) {
   535         viewportFill->apply(p, rect, node, states);
   535         viewportFill->apply(p, node, states);
   536     }
   536     }
   537 
   537 
   538     if (font) {
   538     if (font) {
   539         font->apply(p, rect, node, states);
   539         font->apply(p, node, states);
   540     }
   540     }
   541 
   541 
   542     if (stroke) {
   542     if (stroke) {
   543         stroke->apply(p, rect, node, states);
   543         stroke->apply(p, node, states);
   544     }
   544     }
   545 
   545 
   546     if (transform) {
   546     if (transform) {
   547         transform->apply(p, rect, node, states);
   547         transform->apply(p, node, states);
   548     }
   548     }
   549 
   549 
   550     if (animateColor) {
   550     if (animateColor) {
   551         animateColor->apply(p, rect, node, states);
   551         animateColor->apply(p, node, states);
   552     }
   552     }
   553 
   553 
   554     //animated transforms have to be applied
   554     //animated transforms have to be applied
   555     //_after_ the original object transformations
   555     //_after_ the original object transformations
   556     if (!animateTransforms.isEmpty()) {
   556     if (!animateTransforms.isEmpty()) {
   570         } while (itr != animateTransforms.constBegin());
   570         } while (itr != animateTransforms.constBegin());
   571 
   571 
   572         // Apply the animateTransforms after and including the last one with additive="replace".
   572         // Apply the animateTransforms after and including the last one with additive="replace".
   573         for (; itr != animateTransforms.constEnd(); ++itr) {
   573         for (; itr != animateTransforms.constEnd(); ++itr) {
   574             if ((*itr)->animActive(totalTimeElapsed))
   574             if ((*itr)->animActive(totalTimeElapsed))
   575                 (*itr)->apply(p, rect, node, states);
   575                 (*itr)->apply(p, node, states);
   576         }
   576         }
   577     }
   577     }
   578 
   578 
   579     if (opacity) {
   579     if (opacity) {
   580         opacity->apply(p, rect, node, states);
   580         opacity->apply(p, node, states);
   581     }
   581     }
   582 
   582 
   583     if (compop) {
   583     if (compop) {
   584         compop->apply(p, rect, node, states);
   584         compop->apply(p, node, states);
   585     }
   585     }
   586 }
   586 }
   587 
   587 
   588 void QSvgStyle::revert(QPainter *p, QSvgExtraStates &states)
   588 void QSvgStyle::revert(QPainter *p, QSvgExtraStates &states)
   589 {
   589 {
   653     m_additive = additive;
   653     m_additive = additive;
   654     Q_ASSERT(!(args.count()%3));
   654     Q_ASSERT(!(args.count()%3));
   655     m_count = args.count() / 3;
   655     m_count = args.count() / 3;
   656 }
   656 }
   657 
   657 
   658 void QSvgAnimateTransform::apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &)
   658 void QSvgAnimateTransform::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &)
   659 {
   659 {
   660     m_oldWorldTransform = p->worldTransform();
   660     m_oldWorldTransform = p->worldTransform();
   661     resolveMatrix(node);
   661     resolveMatrix(node);
   662     p->setWorldTransform(m_transform, true);
   662     p->setWorldTransform(m_transform, true);
   663     m_transformApplied = true;
   663     m_transformApplied = true;
   667 {
   667 {
   668     p->setWorldTransform(m_oldWorldTransform, false /* don't combine */);
   668     p->setWorldTransform(m_oldWorldTransform, false /* don't combine */);
   669     m_transformApplied = false;
   669     m_transformApplied = false;
   670 }
   670 }
   671 
   671 
   672 void QSvgAnimateTransform::resolveMatrix(QSvgNode *node)
   672 void QSvgAnimateTransform::resolveMatrix(const QSvgNode *node)
   673 {
   673 {
   674     static const qreal deg2rad = qreal(0.017453292519943295769);
   674     static const qreal deg2rad = qreal(0.017453292519943295769);
   675     qreal totalTimeElapsed = node->document()->currentElapsed();
   675     qreal totalTimeElapsed = node->document()->currentElapsed();
   676     if (totalTimeElapsed < m_from || m_finished)
   676     if (totalTimeElapsed < m_from || m_finished)
   677         return;
   677         return;
   832 void QSvgAnimateColor::setRepeatCount(qreal repeatCount)
   832 void QSvgAnimateColor::setRepeatCount(qreal repeatCount)
   833 {
   833 {
   834     m_repeatCount = repeatCount;
   834     m_repeatCount = repeatCount;
   835 }
   835 }
   836 
   836 
   837 void QSvgAnimateColor::apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &)
   837 void QSvgAnimateColor::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &)
   838 {
   838 {
   839     qreal totalTimeElapsed = node->document()->currentElapsed();
   839     qreal totalTimeElapsed = node->document()->currentElapsed();
   840     if (totalTimeElapsed < m_from || m_finished)
   840     if (totalTimeElapsed < m_from || m_finished)
   841         return;
   841         return;
   842 
   842 
   910     : m_opacity(opacity), m_oldOpacity(0)
   910     : m_opacity(opacity), m_oldOpacity(0)
   911 {
   911 {
   912 
   912 
   913 }
   913 }
   914 
   914 
   915 void QSvgOpacityStyle::apply(QPainter *p, const QRectF &, QSvgNode *, QSvgExtraStates &)
   915 void QSvgOpacityStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &)
   916 {
   916 {
   917     m_oldOpacity = p->opacity();
   917     m_oldOpacity = p->opacity();
   918     p->setOpacity(m_opacity * m_oldOpacity);
   918     p->setOpacity(m_opacity * m_oldOpacity);
   919 }
   919 }
   920 
   920