From d38f7d6f12dd82ebdfe6f3787084141b4529f513 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 3 Apr 2022 00:26:03 +0300 Subject: [PATCH] drop support for video and animation elements in svg component Signed-off-by: Ivailo Monev --- src/svg/qsvggraphics.cpp | 23 ---- src/svg/qsvggraphics_p.h | 14 -- src/svg/qsvghandler.cpp | 241 +-------------------------------- src/svg/qsvghandler_p.h | 5 - src/svg/qsvgnode.cpp | 17 --- src/svg/qsvgnode_p.h | 4 +- src/svg/qsvgrenderer.cpp | 129 ++---------------- src/svg/qsvgrenderer.h | 9 -- src/svg/qsvgstyle.cpp | 316 ------------------------------------------- src/svg/qsvgstyle_p.h | 101 -------------- src/svg/qsvgtinydocument.cpp | 50 ------- src/svg/qsvgtinydocument_p.h | 23 ---- 12 files changed, 13 insertions(+), 919 deletions(-) diff --git a/src/svg/qsvggraphics.cpp b/src/svg/qsvggraphics.cpp index 9073f5ab0..306c56f18 100644 --- a/src/svg/qsvggraphics.cpp +++ b/src/svg/qsvggraphics.cpp @@ -48,12 +48,6 @@ QT_BEGIN_NAMESPACE } \ p->setOpacity(oldOpacity); - -void QSvgAnimation::draw(QPainter *, QSvgExtraStates &) -{ - qWarning(" no implemented"); -} - static inline QRectF boundsOnStroke(QPainter *p, const QPainterPath &path, qreal width) { QPainterPathStroker stroker; @@ -459,18 +453,6 @@ void QSvgUse::draw(QPainter *p, QSvgExtraStates &states) revertStyle(p, states); } -void QSvgVideo::draw(QPainter *p, QSvgExtraStates &states) -{ - applyStyle(p, states); - - revertStyle(p, states); -} - -QSvgNode::Type QSvgAnimation::type() const -{ - return ANIMATION; -} - QSvgNode::Type QSvgArc::type() const { return ARC; @@ -526,11 +508,6 @@ QSvgNode::Type QSvgUse::type() const return USE; } -QSvgNode::Type QSvgVideo::type() const -{ - return VIDEO; -} - QRectF QSvgUse::bounds(QPainter *p, QSvgExtraStates &states) const { QRectF bounds; diff --git a/src/svg/qsvggraphics_p.h b/src/svg/qsvggraphics_p.h index 8df7130a3..2ec9ae403 100644 --- a/src/svg/qsvggraphics_p.h +++ b/src/svg/qsvggraphics_p.h @@ -42,13 +42,6 @@ QT_BEGIN_NAMESPACE -class QSvgAnimation : public QSvgNode -{ -public: - virtual void draw(QPainter *p, QSvgExtraStates &states); - virtual Type type() const; -}; - class QSvgArc : public QSvgNode { public: @@ -220,13 +213,6 @@ private: const QPointF m_start; }; -class QSvgVideo : public QSvgNode -{ -public: - virtual void draw(QPainter *p, QSvgExtraStates &states); - virtual Type type() const; -}; - QT_END_NAMESPACE #endif // QSVGGRAPHICS_P_H diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 49f764f3a..96781fb90 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -296,7 +296,6 @@ static const char * QSvgStyleSelector_nodeString[] = { "g", "defs", "switch", - "animation", "arc", "circle", "ellipse", @@ -309,8 +308,7 @@ static const char * QSvgStyleSelector_nodeString[] = { "text", "textarea", "tspan", - "use", - "video" + "use" }; class QSvgStyleSelector : public QCss::StyleSelector @@ -2105,87 +2103,6 @@ static bool parseAnchorNode(QSvgNode *parent, return true; } -static bool parseAnimateNode(QSvgNode *parent, - const QXmlStreamAttributes &attributes, - QSvgHandler *) -{ - Q_UNUSED(parent); Q_UNUSED(attributes); - return true; -} - -static bool parseAnimateColorNode(QSvgNode *parent, - const QXmlStreamAttributes &attributes, - QSvgHandler *handler) -{ - QString typeStr = attributes.value(QLatin1String("type")).toString(); - QStringRef fromStr = attributes.value(QLatin1String("from")); - QStringRef toStr = attributes.value(QLatin1String("to")); - QString valuesStr = attributes.value(QLatin1String("values")).toString(); - QString beginStr = attributes.value(QLatin1String("begin")).toString(); - QString durStr = attributes.value(QLatin1String("dur")).toString(); - QString targetStr = attributes.value(QLatin1String("attributeName")).toString(); - QString repeatStr = attributes.value(QLatin1String("repeatCount")).toString(); - QString fillStr = attributes.value(QLatin1String("fill")).toString(); - - QList colors; - if (valuesStr.isEmpty()) { - QColor startColor, endColor; - resolveColor(fromStr, startColor, handler); - resolveColor(toStr, endColor, handler); - colors.reserve(2); - colors.append(startColor); - colors.append(endColor); - } else { - QStringList str = valuesStr.split(QLatin1Char(';')); - colors.reserve(str.count()); - QStringList::const_iterator itr; - for (itr = str.constBegin(); itr != str.constEnd(); ++itr) { - QColor color; - QString str = *itr; - resolveColor(QStringRef(&str), color, handler); - colors.append(color); - } - } - - int ms = 1000; - beginStr = beginStr.trimmed(); - if (beginStr.endsWith(QLatin1String("ms"))) { - beginStr.chop(2); - ms = 1; - } else if (beginStr.endsWith(QLatin1String("s"))) { - beginStr.chop(1); - } - durStr = durStr.trimmed(); - if (durStr.endsWith(QLatin1String("ms"))) { - durStr.chop(2); - ms = 1; - } else if (durStr.endsWith(QLatin1String("s"))) { - durStr.chop(1); - } - int begin = static_cast(toDouble(beginStr) * ms); - int end = static_cast((toDouble(durStr) + begin) * ms); - - QSvgAnimateColor *anim = new QSvgAnimateColor(begin, end, 0); - anim->setArgs((targetStr == QLatin1String("fill")), colors); - anim->setFreeze(fillStr == QLatin1String("freeze")); - anim->setRepeatCount( - (repeatStr == QLatin1String("indefinite")) ? -1 : - (repeatStr == QLatin1String("")) ? 1 : toDouble(repeatStr)); - - parent->appendStyleProperty(anim, someId(attributes)); - parent->document()->setAnimated(true); - handler->setAnimPeriod(begin, end); - return true; -} - -static bool parseAimateMotionNode(QSvgNode *parent, - const QXmlStreamAttributes &attributes, - QSvgHandler *) -{ - Q_UNUSED(parent); Q_UNUSED(attributes); - return true; -} - static void parseNumberTriplet(QVector &values, const QChar *&s) { QVector list = parseNumbersList(s); @@ -2194,129 +2111,6 @@ static void parseNumberTriplet(QVector &values, const QChar *&s) values.append(0.0); } -static bool parseAnimateTransformNode(QSvgNode *parent, - const QXmlStreamAttributes &attributes, - QSvgHandler *handler) -{ - QString typeStr = attributes.value(QLatin1String("type")).toString(); - QString values = attributes.value(QLatin1String("values")).toString(); - QString beginStr = attributes.value(QLatin1String("begin")).toString(); - QString durStr = attributes.value(QLatin1String("dur")).toString(); - QString targetStr = attributes.value(QLatin1String("attributeName")).toString(); - QString repeatStr = attributes.value(QLatin1String("repeatCount")).toString(); - QString fillStr = attributes.value(QLatin1String("fill")).toString(); - QString fromStr = attributes.value(QLatin1String("from")).toString(); - QString toStr = attributes.value(QLatin1String("to")).toString(); - QString byStr = attributes.value(QLatin1String("by")).toString(); - QString addtv = attributes.value(QLatin1String("additive")).toString(); - - QSvgAnimateTransform::Additive additive = QSvgAnimateTransform::Replace; - if (addtv == QLatin1String("sum")) - additive = QSvgAnimateTransform::Sum; - - QVector vals; - if (values.isEmpty()) { - const QChar *s; - if (fromStr.isEmpty()) { - if (!byStr.isEmpty()) { - // By-animation. - additive = QSvgAnimateTransform::Sum; - vals.append(0.0); - vals.append(0.0); - vals.append(0.0); - parseNumberTriplet(vals, s = byStr.constData()); - } else { - // To-animation not defined. - return false; - } - } else { - if (!toStr.isEmpty()) { - // From-to-animation. - parseNumberTriplet(vals, s = fromStr.constData()); - parseNumberTriplet(vals, s = toStr.constData()); - } else if (!byStr.isEmpty()) { - // From-by-animation. - parseNumberTriplet(vals, s = fromStr.constData()); - parseNumberTriplet(vals, s = byStr.constData()); - for (int i = vals.size() - 3; i < vals.size(); ++i) - vals[i] += vals[i - 3]; - } else { - return false; - } - } - } else { - const QChar *s = values.constData(); - while (s && *s != QLatin1Char(0)) { - parseNumberTriplet(vals, s); - if (*s == QLatin1Char(0)) - break; - ++s; - } - } - - int ms = 1000; - beginStr = beginStr.trimmed(); - if (beginStr.endsWith(QLatin1String("ms"))) { - beginStr.chop(2); - ms = 1; - } else if (beginStr.endsWith(QLatin1String("s"))) { - beginStr.chop(1); - } - int begin = static_cast(toDouble(beginStr) * ms); - durStr = durStr.trimmed(); - if (durStr.endsWith(QLatin1String("ms"))) { - durStr.chop(2); - ms = 1; - } else if (durStr.endsWith(QLatin1String("s"))) { - durStr.chop(1); - ms = 1000; - } - int end = static_cast(toDouble(durStr)*ms) + begin; - - QSvgAnimateTransform::TransformType type = QSvgAnimateTransform::Empty; - if (typeStr == QLatin1String("translate")) { - type = QSvgAnimateTransform::Translate; - } else if (typeStr == QLatin1String("scale")) { - type = QSvgAnimateTransform::Scale; - } else if (typeStr == QLatin1String("rotate")) { - type = QSvgAnimateTransform::Rotate; - } else if (typeStr == QLatin1String("skewX")) { - type = QSvgAnimateTransform::SkewX; - } else if (typeStr == QLatin1String("skewY")) { - type = QSvgAnimateTransform::SkewY; - } else { - return false; - } - - QSvgAnimateTransform *anim = new QSvgAnimateTransform(begin, end, 0); - anim->setArgs(type, additive, vals); - anim->setFreeze(fillStr == QLatin1String("freeze")); - anim->setRepeatCount( - (repeatStr == QLatin1String("indefinite"))? -1 : - (repeatStr == QLatin1String(""))? 1 : toDouble(repeatStr)); - - parent->appendStyleProperty(anim, someId(attributes)); - parent->document()->setAnimated(true); - handler->setAnimPeriod(begin, end); - return true; -} - -static QSvgNode * createAnimationNode(QSvgNode *parent, - const QXmlStreamAttributes &attributes, - QSvgHandler *) -{ - Q_UNUSED(parent); Q_UNUSED(attributes); - return 0; -} - -static bool parseAudioNode(QSvgNode *parent, - const QXmlStreamAttributes &attributes, - QSvgHandler *) -{ - Q_UNUSED(parent); Q_UNUSED(attributes); - return true; -} - static QSvgNode *createCircleNode(QSvgNode *parent, const QXmlStreamAttributes &attributes, QSvgHandler *) @@ -2890,7 +2684,7 @@ static bool parseStopNode(QSvgStyleProperty *parent, // we force a dummy node with the same id and class into a rendering // tree to figure out whether the selector has a style for it // QSvgStyleSelector should be coded in a way that could avoid it - QSvgAnimation anim; + QSvgTspan anim(nullptr); anim.setNodeId(nodeIdStr); anim.setXmlClass(xmlClassStr); @@ -3149,14 +2943,6 @@ static QSvgNode *createUseNode(QSvgNode *parent, return nullptr; } -static QSvgNode *createVideoNode(QSvgNode *parent, - const QXmlStreamAttributes &attributes, - QSvgHandler *) -{ - Q_UNUSED(parent); Q_UNUSED(attributes); - return nullptr; -} - typedef QSvgNode *(*FactoryMethod)(QSvgNode *, const QXmlStreamAttributes &, QSvgHandler *); static FactoryMethod findGroupFactory(const QString &name) @@ -3189,9 +2975,6 @@ static FactoryMethod findGraphicsFactory(const QString &name) QStringRef ref(&name, 1, name.length() - 1); switch (name.at(0).unicode()) { - case 'a': - if (ref == QLatin1String("nimation")) return createAnimationNode; - break; case 'c': if (ref == QLatin1String("ircle")) return createCircleNode; break; @@ -3220,9 +3003,6 @@ static FactoryMethod findGraphicsFactory(const QString &name) case 'u': if (ref == QLatin1String("se")) return createUseNode; break; - case 'v': - if (ref == QLatin1String("ideo")) return createVideoNode; - break; default: break; } @@ -3240,11 +3020,6 @@ static ParseMethod findUtilFactory(const QString &name) switch (name.at(0).unicode()) { case 'a': if (ref.isEmpty()) return parseAnchorNode; - if (ref == QLatin1String("nimate")) return parseAnimateNode; - if (ref == QLatin1String("nimateColor")) return parseAnimateColorNode; - if (ref == QLatin1String("nimateMotion")) return parseAimateMotionNode; - if (ref == QLatin1String("nimateTransform")) return parseAnimateTransformNode; - if (ref == QLatin1String("udio")) return parseAudioNode; break; case 'd': if (ref == QLatin1String("esc")) return parseDescNode; @@ -3356,7 +3131,6 @@ void QSvgHandler::init() { m_doc = 0; m_style = 0; - m_animEnd = 0; xml->setNamespaceProcessing(false); m_selector = new QSvgStyleSelector; @@ -3705,17 +3479,6 @@ bool QSvgHandler::processingInstruction(const QString &target, const QString &da return true; } -void QSvgHandler::setAnimPeriod(int start, int end) -{ - Q_UNUSED(start); - m_animEnd = qMax(end, m_animEnd); -} - -int QSvgHandler::animationDuration() const -{ - return m_animEnd; -} - QSvgHandler::~QSvgHandler() { delete m_selector; diff --git a/src/svg/qsvghandler_p.h b/src/svg/qsvghandler_p.h index ca7636589..b18266b83 100644 --- a/src/svg/qsvghandler_p.h +++ b/src/svg/qsvghandler_p.h @@ -91,9 +91,6 @@ public: QSvgStyleSelector *selector() const; - void setAnimPeriod(int start, int end); - int animationDuration() const; - void parseCSStoXMLAttrs(const QString &css, QVector *attributes); bool startElement(const QString &localName, const QXmlStreamAttributes &attributes); @@ -130,8 +127,6 @@ private: QSvgStyleSelector *m_selector; - int m_animEnd; - QXmlStreamReader *const xml; QCss::Parser m_cssParser; void resolveGradients(QSvgNode *node) const; diff --git a/src/svg/qsvgnode.cpp b/src/svg/qsvgnode.cpp index f0fc0a4c9..47cd41ee4 100644 --- a/src/svg/qsvgnode.cpp +++ b/src/svg/qsvgnode.cpp @@ -80,15 +80,6 @@ void QSvgNode::appendStyleProperty(QSvgStyleProperty *prop, const QString &id) m_style.transform = static_cast(prop); break; } - case QSvgStyleProperty::ANIMATE_COLOR: { - m_style.animateColor = static_cast(prop); - break; - } - case QSvgStyleProperty::ANIMATE_TRANSFORM: { - m_style.animateTransforms.append( - static_cast(prop)); - break; - } case QSvgStyleProperty::OPACITY: { m_style.opacity = static_cast(prop); break; @@ -151,14 +142,6 @@ QSvgStyleProperty * QSvgNode::styleProperty(QSvgStyleProperty::Type type) const if (node->m_style.transform) return node->m_style.transform; break; - case QSvgStyleProperty::ANIMATE_COLOR: - if (node->m_style.animateColor) - return node->m_style.animateColor; - break; - case QSvgStyleProperty::ANIMATE_TRANSFORM: - if (!node->m_style.animateTransforms.isEmpty()) - return node->m_style.animateTransforms.first(); - break; case QSvgStyleProperty::OPACITY: if (node->m_style.opacity) return node->m_style.opacity; diff --git a/src/svg/qsvgnode_p.h b/src/svg/qsvgnode_p.h index 16d51cab1..c228ce13b 100644 --- a/src/svg/qsvgnode_p.h +++ b/src/svg/qsvgnode_p.h @@ -51,7 +51,6 @@ public: G, DEFS, SWITCH, - ANIMATION, ARC, CIRCLE, ELLIPSE, @@ -64,8 +63,7 @@ public: TEXT, TEXTAREA, TSPAN, - USE, - VIDEO + USE }; enum DisplayMode { InlineMode, diff --git a/src/svg/qsvgrenderer.cpp b/src/svg/qsvgrenderer.cpp index d220621db..24d0fa970 100644 --- a/src/svg/qsvgrenderer.cpp +++ b/src/svg/qsvgrenderer.cpp @@ -22,7 +22,6 @@ #include "qsvgrenderer.h" #include "qsvgtinydocument_p.h" #include "qbytearray.h" -#include "qtimer.h" #include "qdebug.h" #include "qobject_p.h" @@ -41,16 +40,14 @@ QT_BEGIN_NAMESPACE subclass, including QWidget and QImage. QSvgRenderer provides an API that supports basic features of SVG rendering, such as loading - and rendering of static drawings, and more interactive features like animation. Since the - rendering is performed using QPainter, SVG drawings can be rendered on any subclass of - QPaintDevice. + and rendering of static drawings. Since the rendering is performed using QPainter, SVG + drawings can be rendered on any subclass of QPaintDevice. SVG drawings are either loaded when an QSvgRenderer is constructed, or loaded later using the load() functions. Data is either supplied directly as serialized XML, or indirectly using a file name. If a valid file has been loaded, either when the renderer is constructed or at some later time, isValid() returns true; otherwise it returns false. - QSvgRenderer provides the render() slot to render the current document, or the current - frame of an animated document, using a given painter. + QSvgRenderer provides the render() slot to render the current document using a given painter. The defaultSize() function provides information about the amount of space that is required to render the currently loaded SVG file. This is useful for paint devices, such as QWidget, @@ -58,18 +55,7 @@ QT_BEGIN_NAMESPACE The default size of a drawing may differ from its visible area, found using the \l viewBox property. - Animated SVG drawings are supported, and can be controlled with a simple collection of - functions and properties: - - \list - \o The animated() function indicates whether a drawing contains animation information. - \omit - \o The animationDuration() function provides the duration in milliseconds of the - animation, without taking any looping into account. - \o The \l currentFrame property contains the current frame of the animation. - \endomit - \o The \l framesPerSecond property contains the rate at which the animation plays. - \endlist + Animated SVG drawings are not supported. Finally, the QSvgRenderer class provides the repaintNeeded() signal which is emitted whenever the rendering of the document needs to be updated. @@ -83,8 +69,7 @@ class QSvgRendererPrivate : public QObjectPrivate public: explicit QSvgRendererPrivate() : QObjectPrivate(), - render(0), timer(0), - fps(30) + render(nullptr) {} ~QSvgRendererPrivate() { @@ -94,8 +79,6 @@ public: static void callRepaintNeeded(QSvgRenderer *const q); QSvgTinyDocument *render; - QTimer *timer; - int fps; }; /*! @@ -194,85 +177,6 @@ void QSvgRenderer::setViewBox(const QRect &viewbox) } /*! - Returns true if the current document contains animated elements; otherwise - returns false. - - \sa framesPerSecond() -*/ -bool QSvgRenderer::animated() const -{ - Q_D(const QSvgRenderer); - if (d->render) { - return d->render->animated(); - } - return false; -} - -/*! - \property QSvgRenderer::framesPerSecond - \brief the number of frames per second to be shown - - The number of frames per second is 0 if the current document is not animated. - - \sa animated() -*/ -int QSvgRenderer::framesPerSecond() const -{ - Q_D(const QSvgRenderer); - return d->fps; -} - -void QSvgRenderer::setFramesPerSecond(int num) -{ - Q_D(QSvgRenderer); - if (Q_UNLIKELY(num < 0)) { - qWarning("QSvgRenderer::setFramesPerSecond: Cannot set negative value %d", num); - return; - } - d->fps = num; -} - -/*! - \property QSvgRenderer::currentFrame - \brief the current frame of the document's animation, or 0 if the document is not animated - \internal - - \sa animationDuration(), framesPerSecond, animated() -*/ - -/*! - \internal -*/ -int QSvgRenderer::currentFrame() const -{ - Q_D(const QSvgRenderer); - return d->render->currentFrame(); -} - -/*! - \internal -*/ -void QSvgRenderer::setCurrentFrame(int frame) -{ - Q_D(QSvgRenderer); - d->render->setCurrentFrame(frame); -} - -/*! - \internal - - Returns the number of frames in the animation, or 0 if the current document is not - animated. - - \sa animated(), framesPerSecond -*/ -int QSvgRenderer::animationDuration() const -{ - Q_D(const QSvgRenderer); - return d->render->animationDuration(); -} - -/*! \internal \since 4.5 @@ -291,17 +195,6 @@ static bool loadDocument(QSvgRenderer *const q, { delete d->render; d->render = QSvgTinyDocument::load(in); - if (d->render && d->render->animated() && d->fps > 0) { - if (!d->timer) - d->timer = new QTimer(q); - else - d->timer->stop(); - q->connect(d->timer, SIGNAL(timeout()), - q, SIGNAL(repaintNeeded())); - d->timer->start(1000/d->fps); - } else if (d->timer) { - d->timer->stop(); - } //force first update QSvgRendererPrivate::callRepaintNeeded(q); @@ -345,8 +238,7 @@ bool QSvgRenderer::load(QXmlStreamReader *contents) } /*! - Renders the current document, or the current frame of an animated - document, using the given \a painter. + Renders the current document using the given \a painter. */ void QSvgRenderer::render(QPainter *painter) { @@ -360,7 +252,7 @@ void QSvgRenderer::render(QPainter *painter) \fn void QSvgRenderer::repaintNeeded() This signal is emitted whenever the rendering of the document - needs to be updated, usually for the purposes of animation. + needs to be updated. */ /*! @@ -378,10 +270,9 @@ void QSvgRenderer::render(QPainter *painter, const QString &elementId, } /*! - Renders the current document, or the current frame of an animated - document, using the given \a painter on the specified \a bounds within - the painter. If the bounding rectangle is not specified - the SVG file is mapped to the whole paint device. + Renders the current document sing the given \a painter on the + specified \a bounds within the painter. If the bounding rectangle is not + specified the SVG file is mapped to the whole paint device. */ void QSvgRenderer::render(QPainter *painter, const QRectF &bounds) { diff --git a/src/svg/qsvgrenderer.h b/src/svg/qsvgrenderer.h index a9aa6e83b..bc5d186bb 100644 --- a/src/svg/qsvgrenderer.h +++ b/src/svg/qsvgrenderer.h @@ -41,8 +41,6 @@ class Q_SVG_EXPORT QSvgRenderer : public QObject Q_OBJECT Q_PROPERTY(QRectF viewBox READ viewBoxF WRITE setViewBox) - Q_PROPERTY(int framesPerSecond READ framesPerSecond WRITE setFramesPerSecond) - Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame) public: QSvgRenderer(QObject *parent=0); QSvgRenderer(const QString &filename, QObject *parent=0); @@ -59,13 +57,6 @@ public: void setViewBox(const QRect &viewbox); void setViewBox(const QRectF &viewbox); - bool animated() const; - int framesPerSecond() const; - void setFramesPerSecond(int num); - int currentFrame() const; - void setCurrentFrame(int); - int animationDuration() const;//in seconds - QRectF boundsOnElement(const QString &id) const; bool elementExists(const QString &id) const; QMatrix matrixForElement(const QString &id) const; diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp index 68221282a..9be5978e4 100644 --- a/src/svg/qsvgstyle.cpp +++ b/src/svg/qsvgstyle.cpp @@ -518,35 +518,6 @@ void QSvgStyle::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &states transform->apply(p, node, states); } - if (animateColor) { - animateColor->apply(p, node, states); - } - - //animated transforms have to be applied - //_after_ the original object transformations - if (!animateTransforms.isEmpty()) { - qreal totalTimeElapsed = node->document()->currentElapsed(); - // Find the last animateTransform with additive="replace", since this will override all - // previous animateTransforms. - QList >::const_iterator itr = animateTransforms.constEnd(); - do { - --itr; - if ((*itr)->animActive(totalTimeElapsed) - && (*itr)->additiveType() == QSvgAnimateTransform::Replace) { - // An animateTransform with additive="replace" will replace the transform attribute. - if (transform) - transform->revert(p, states); - break; - } - } while (itr != animateTransforms.constBegin()); - - // Apply the animateTransforms after and including the last one with additive="replace". - for (; itr != animateTransforms.constEnd(); ++itr) { - if ((*itr)->animActive(totalTimeElapsed)) - (*itr)->apply(p, node, states); - } - } - if (opacity) { opacity->apply(p, node, states); } @@ -578,28 +549,10 @@ void QSvgStyle::revert(QPainter *p, QSvgExtraStates &states) stroke->revert(p, states); } - //animated transforms need to be reverted _before_ - //the native transforms - if (!animateTransforms.isEmpty()) { - QList >::const_iterator itr = animateTransforms.constBegin(); - for (; itr != animateTransforms.constEnd(); ++itr) { - if ((*itr)->transformApplied()) { - (*itr)->revert(p, states); - break; - } - } - for (; itr != animateTransforms.constEnd(); ++itr) - (*itr)->clearTransformApplied(); - } - if (transform) { transform->revert(p, states); } - if (animateColor) { - animateColor->revert(p, states); - } - if (opacity) { opacity->revert(p, states); } @@ -609,275 +562,6 @@ void QSvgStyle::revert(QPainter *p, QSvgExtraStates &states) } } -QSvgAnimateTransform::QSvgAnimateTransform(int startMs, int endMs, int byMs ) - : QSvgStyleProperty(), - m_from(startMs), m_to(endMs), - m_type(Empty), m_additive(Replace), m_count(0), m_finished(false), m_transformApplied(false) -{ - m_totalRunningTime = m_to - m_from; - Q_UNUSED(byMs); -} - -void QSvgAnimateTransform::setArgs(TransformType type, Additive additive, const QVector &args) -{ - m_type = type; - m_args = args; - m_additive = additive; - Q_ASSERT(!(args.count()%3)); - m_count = args.count() / 3; -} - -void QSvgAnimateTransform::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &) -{ - m_oldWorldTransform = p->worldTransform(); - resolveMatrix(node); - p->setWorldTransform(m_transform, true); - m_transformApplied = true; -} - -void QSvgAnimateTransform::revert(QPainter *p, QSvgExtraStates &) -{ - p->setWorldTransform(m_oldWorldTransform, false /* don't combine */); - m_transformApplied = false; -} - -void QSvgAnimateTransform::resolveMatrix(const QSvgNode *node) -{ - qreal totalTimeElapsed = node->document()->currentElapsed(); - if (totalTimeElapsed < m_from || m_finished) - return; - - qreal animationFrame = 0; - if (m_totalRunningTime != 0) { - animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime; - - if (m_repeatCount >= 0 && m_repeatCount < animationFrame) { - m_finished = true; - animationFrame = m_repeatCount; - } - } - - qreal percentOfAnimation = animationFrame; - if (percentOfAnimation > 1) { - percentOfAnimation -= ((int)percentOfAnimation); - } - - qreal currentPosition = percentOfAnimation * (m_count - 1); - int startElem = qFloor(currentPosition); - int endElem = qCeil(currentPosition); - - switch(m_type) - { - case Translate: { - startElem *= 3; - endElem *= 3; - qreal from1, from2; - qreal to1, to2; - from1 = m_args[startElem++]; - from2 = m_args[startElem++]; - to1 = m_args[endElem++]; - to2 = m_args[endElem++]; - - qreal transXDiff = (to1-from1) * percentOfAnimation; - qreal transX = from1 + transXDiff; - qreal transYDiff = (to2-from2) * percentOfAnimation; - qreal transY = from2 + transYDiff; - m_transform = QTransform(); - m_transform.translate(transX, transY); - break; - } - case Scale: { - startElem *= 3; - endElem *= 3; - qreal from1, from2; - qreal to1, to2; - from1 = m_args[startElem++]; - from2 = m_args[startElem++]; - to1 = m_args[endElem++]; - to2 = m_args[endElem++]; - - qreal transXDiff = (to1-from1) * percentOfAnimation; - qreal transX = from1 + transXDiff; - qreal transYDiff = (to2-from2) * percentOfAnimation; - qreal transY = from2 + transYDiff; - if (transY == 0) - transY = transX; - m_transform = QTransform(); - m_transform.scale(transX, transY); - break; - } - case Rotate: { - startElem *= 3; - endElem *= 3; - qreal from1, from2, from3; - qreal to1, to2, to3; - from1 = m_args[startElem++]; - from2 = m_args[startElem++]; - from3 = m_args[startElem++]; - to1 = m_args[endElem++]; - to2 = m_args[endElem++]; - to3 = m_args[endElem++]; - - qreal rotationDiff = (to1 - from1) * percentOfAnimation; - //qreal rotation = from1 + rotationDiff; - - qreal transXDiff = (to2-from2) * percentOfAnimation; - qreal transX = from2 + transXDiff; - qreal transYDiff = (to3-from3) * percentOfAnimation; - qreal transY = from3 + transYDiff; - m_transform = QTransform(); - m_transform.translate(transX, transY); - m_transform.rotate(rotationDiff); - m_transform.translate(-transX, -transY); - break; - } - case SkewX: { - startElem *= 3; - endElem *= 3; - qreal from1; - qreal to1; - from1 = m_args[startElem++]; - to1 = m_args[endElem++]; - - qreal transXDiff = (to1-from1) * percentOfAnimation; - qreal transX = from1 + transXDiff; - m_transform = QTransform(); - m_transform.shear(qTan(transX * q_deg2rad), 0); - break; - } - case SkewY: { - startElem *= 3; - endElem *= 3; - qreal from1; - qreal to1; - from1 = m_args[startElem++]; - to1 = m_args[endElem++]; - - - qreal transYDiff = (to1 - from1) * percentOfAnimation; - qreal transY = from1 + transYDiff; - m_transform = QTransform(); - m_transform.shear(0, qTan(transY * q_deg2rad)); - break; - } - default: - break; - } -} - -QSvgStyleProperty::Type QSvgAnimateTransform::type() const -{ - return ANIMATE_TRANSFORM; -} - -void QSvgAnimateTransform::setFreeze(bool freeze) -{ - m_freeze = freeze; -} - -void QSvgAnimateTransform::setRepeatCount(qreal repeatCount) -{ - m_repeatCount = repeatCount; -} - -QSvgAnimateColor::QSvgAnimateColor(int startMs, int endMs, int byMs) - : QSvgStyleProperty(), - m_from(startMs), m_to(endMs), - m_finished(false) -{ - m_totalRunningTime = m_to - m_from; - Q_UNUSED(byMs); -} - -void QSvgAnimateColor::setArgs(bool fill, - const QList &colors) -{ - m_fill = fill; - m_colors = colors; -} - -void QSvgAnimateColor::setFreeze(bool freeze) -{ - m_freeze = freeze; -} - -void QSvgAnimateColor::setRepeatCount(qreal repeatCount) -{ - m_repeatCount = repeatCount; -} - -void QSvgAnimateColor::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &) -{ - qreal totalTimeElapsed = node->document()->currentElapsed(); - if (totalTimeElapsed < m_from || m_finished) - return; - - qreal animationFrame = 0; - if (m_totalRunningTime != 0) - animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime; - - if (m_repeatCount >= 0 && m_repeatCount < animationFrame) { - m_finished = true; - animationFrame = m_repeatCount; - } - - qreal percentOfAnimation = animationFrame; - if (percentOfAnimation > 1) { - percentOfAnimation -= ((int)percentOfAnimation); - } - - qreal currentPosition = percentOfAnimation * (m_colors.count() - 1); - - int startElem = qFloor(currentPosition); - int endElem = qCeil(currentPosition); - QColor start = m_colors[startElem]; - QColor end = m_colors[endElem]; - - qreal percentOfColorMorph = currentPosition; - if (percentOfColorMorph > 1) { - percentOfColorMorph -= ((int)percentOfColorMorph); - } - - // Interpolate between the two fixed colors start and end - qreal aDiff = (end.alpha() - start.alpha()) * percentOfColorMorph; - qreal rDiff = (end.red() - start.red()) * percentOfColorMorph; - qreal gDiff = (end.green() - start.green()) * percentOfColorMorph; - qreal bDiff = (end.blue() - start.blue()) * percentOfColorMorph; - - int alpha = int(start.alpha() + aDiff); - int red = int(start.red() + rDiff); - int green = int(start.green() + gDiff); - int blue = int(start.blue() + bDiff); - - QColor color(red, green, blue, alpha); - - if (m_fill) { - QBrush b = p->brush(); - m_oldBrush = b; - b.setColor(color); - p->setBrush(b); - } else { - QPen pen = p->pen(); - m_oldPen = pen; - pen.setColor(color); - p->setPen(pen); - } -} - -void QSvgAnimateColor::revert(QPainter *p, QSvgExtraStates &) -{ - if (m_fill) { - p->setBrush(m_oldBrush); - } else { - p->setPen(m_oldPen); - } -} - -QSvgStyleProperty::Type QSvgAnimateColor::type() const -{ - return ANIMATE_COLOR; -} - QSvgOpacityStyle::QSvgOpacityStyle(qreal opacity) : m_opacity(opacity), m_oldOpacity(0) { diff --git a/src/svg/qsvgstyle_p.h b/src/svg/qsvgstyle_p.h index fb29003e8..ac855d845 100644 --- a/src/svg/qsvgstyle_p.h +++ b/src/svg/qsvgstyle_p.h @@ -142,8 +142,6 @@ public: SOLID_COLOR, GRADIENT, TRANSFORM, - ANIMATE_TRANSFORM, - ANIMATE_COLOR, OPACITY, COMP_OP }; @@ -602,102 +600,6 @@ private: }; -class QSvgAnimateTransform : public QSvgStyleProperty -{ -public: - enum TransformType - { - Empty, - Translate, - Scale, - Rotate, - SkewX, - SkewY - }; - enum Additive - { - Sum, - Replace - }; -public: - QSvgAnimateTransform(int startMs, int endMs, int by = 0); - void setArgs(TransformType type, Additive additive, const QVector &args); - void setFreeze(bool freeze); - void setRepeatCount(qreal repeatCount); - virtual void apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &states); - virtual void revert(QPainter *p, QSvgExtraStates &states); - virtual Type type() const; - QSvgAnimateTransform::Additive additiveType() const - { - return m_additive; - } - - bool animActive(qreal totalTimeElapsed) - { - if (totalTimeElapsed < m_from) - return false; - if (m_freeze || m_repeatCount < 0) // fill="freeze" or repeat="indefinite" - return true; - if (m_totalRunningTime == 0) - return false; - qreal animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime; - if (animationFrame > m_repeatCount) - return false; - return true; - } - - bool transformApplied() const - { - return m_transformApplied; - } - - // Call this instead of revert if you know that revert is unnecessary. - void clearTransformApplied() - { - m_transformApplied = false; - } - -protected: - void resolveMatrix(const QSvgNode *node); -private: - qreal m_from, m_to; - qreal m_totalRunningTime; - TransformType m_type; - Additive m_additive; - QVector m_args; - int m_count; - QTransform m_transform; - QTransform m_oldWorldTransform; - bool m_finished; - bool m_freeze; - qreal m_repeatCount; - bool m_transformApplied; -}; - - -class QSvgAnimateColor : public QSvgStyleProperty -{ -public: - QSvgAnimateColor(int startMs, int endMs, int by = 0); - void setArgs(bool fill, const QList &colors); - void setFreeze(bool freeze); - void setRepeatCount(qreal repeatCount); - virtual void apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &states); - virtual void revert(QPainter *p, QSvgExtraStates &states); - virtual Type type() const; -private: - qreal m_from, m_to; - qreal m_totalRunningTime; - QList m_colors; - QBrush m_oldBrush; - QPen m_oldPen; - bool m_fill; - bool m_finished; - bool m_freeze; - qreal m_repeatCount; -}; - - class QSvgCompOpStyle : public QSvgStyleProperty { public: @@ -730,7 +632,6 @@ public: solidColor(0), gradient(0), transform(0), - animateColor(0), opacity(0), compop(0) {} @@ -746,8 +647,6 @@ public: QSvgRefCounter solidColor; QSvgRefCounter gradient; QSvgRefCounter transform; - QSvgRefCounter animateColor; - QList > animateTransforms; QSvgRefCounter opacity; QSvgRefCounter compop; }; diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index 67d81805f..b1aa97e29 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -36,9 +36,6 @@ QT_BEGIN_NAMESPACE QSvgTinyDocument::QSvgTinyDocument() : QSvgStructureNode(0) - , m_animated(false) - , m_animationDuration(0) - , m_fps(30) { } @@ -73,7 +70,6 @@ QSvgTinyDocument * QSvgTinyDocument::load(const QByteArray &contents) qPrintable(handler.errorString()), handler.lineNumber()); } else { doc = handler.document(); - doc->m_animationDuration = handler.animationDuration(); } return doc; } @@ -88,17 +84,12 @@ QSvgTinyDocument * QSvgTinyDocument::load(QXmlStreamReader *contents) qPrintable(handler.errorString()), handler.lineNumber()); } else { doc = handler.document(); - doc->m_animationDuration = handler.animationDuration(); } return doc; } void QSvgTinyDocument::draw(QPainter *p, const QRectF &bounds) { - if (m_time.isNull()) { - m_time.start(); - } - if (displayMode() == QSvgNode::NoneMode) return; @@ -132,9 +123,6 @@ void QSvgTinyDocument::draw(QPainter *p, const QString &id, qDebug("Couldn't find node %s. Skipping rendering.", qPrintable(id)); return; } - if (m_time.isNull()) { - m_time.start(); - } if (node->displayMode() == QSvgNode::NoneMode) return; @@ -228,21 +216,6 @@ QSvgFillStyleProperty *QSvgTinyDocument::namedStyle(const QString &id) const return m_namedStyles.value(id); } -void QSvgTinyDocument::restartAnimation() -{ - m_time.restart(); -} - -bool QSvgTinyDocument::animated() const -{ - return m_animated; -} - -void QSvgTinyDocument::setAnimated(bool a) -{ - m_animated = a; -} - void QSvgTinyDocument::draw(QPainter *p, QSvgExtraStates &) { draw(p, QRectF()); @@ -316,27 +289,4 @@ QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const return t.toAffine(); } -int QSvgTinyDocument::currentFrame() const -{ - double runningPercentage = qMin(m_time.elapsed()/double(m_animationDuration), 1.); - - int totalFrames = m_fps * m_animationDuration; - - return int(runningPercentage * totalFrames); -} - -void QSvgTinyDocument::setCurrentFrame(int frame) -{ - const int totalFrames = m_fps * m_animationDuration; - const int framePercentage = frame / totalFrames; - const int timeForFrame = m_animationDuration * framePercentage * 1000; //in ms - const int timeToAdd = timeForFrame - m_time.elapsed(); - m_time = m_time.addMSecs(timeToAdd); -} - -void QSvgTinyDocument::setFramesPerSecond(int num) -{ - m_fps = num; -} - QT_END_NAMESPACE diff --git a/src/svg/qsvgtinydocument_p.h b/src/svg/qsvgtinydocument_p.h index d24130c33..69b925d3e 100644 --- a/src/svg/qsvgtinydocument_p.h +++ b/src/svg/qsvgtinydocument_p.h @@ -84,14 +84,6 @@ public: void addNamedStyle(const QString &id, QSvgFillStyleProperty *style); QSvgFillStyleProperty *namedStyle(const QString &id) const; - void restartAnimation(); - int currentElapsed() const; - bool animated() const; - void setAnimated(bool a); - int animationDuration() const; - int currentFrame() const; - void setCurrentFrame(int); - void setFramesPerSecond(int num); private: void mapSourceToTarget(QPainter *p, const QRectF &targetRect, const QRectF &sourceRect); @@ -103,11 +95,6 @@ private: QHash m_namedNodes; QHash > m_namedStyles; - QTime m_time; - bool m_animated; - int m_animationDuration; - int m_fps; - QSvgExtraStates m_states; }; @@ -138,16 +125,6 @@ inline QRectF QSvgTinyDocument::viewBox() const return m_viewBox; } -inline int QSvgTinyDocument::currentElapsed() const -{ - return m_time.elapsed(); -} - -inline int QSvgTinyDocument::animationDuration() const -{ - return m_animationDuration; -} - QT_END_NAMESPACE #endif // QSVGTINYDOCUMENT_P_H -- 2.11.0