diff options
Diffstat (limited to 'src/svg')
-rw-r--r-- | src/svg/qsvggenerator.cpp | 2 | ||||
-rw-r--r-- | src/svg/qsvghandler.cpp | 2 | ||||
-rw-r--r-- | src/svg/qsvghandler_p.h | 2 | ||||
-rw-r--r-- | src/svg/qsvgnode.cpp | 2 | ||||
-rw-r--r-- | src/svg/qsvgstyle.cpp | 2 | ||||
-rw-r--r-- | src/svg/qsvgtinydocument.cpp | 57 | ||||
-rw-r--r-- | src/svg/qsvgtinydocument_p.h | 9 |
7 files changed, 50 insertions, 26 deletions
diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index 07f8d74..b671c44 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -1009,7 +1009,7 @@ void QSvgPaintEngine::updateState(const QPaintEngineState &state) } if (flags & QPaintEngine::DirtyTransform) { - d->matrix = state.matrix(); + d->matrix = state.transform().toAffine(); *d->stream << "transform=\"matrix(" << d->matrix.m11() << ',' << d->matrix.m12() << ',' << d->matrix.m21() << ',' << d->matrix.m22() << ',' diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index fe79977..86ca77e 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -1986,7 +1986,7 @@ static void parseCSStoXMLAttrs(const QVector<QCss::Declaration> &declarations, } } -void QSvgHandler::parseCSStoXMLAttrs(QString css, QVector<QSvgCssAttribute> *attributes) +void QSvgHandler::parseCSStoXMLAttrs(const QString &css, QVector<QSvgCssAttribute> *attributes) { // preprocess (for unicode escapes), tokenize and remove comments m_cssParser.init(css); diff --git a/src/svg/qsvghandler_p.h b/src/svg/qsvghandler_p.h index 8eb061b..d76e56c 100644 --- a/src/svg/qsvghandler_p.h +++ b/src/svg/qsvghandler_p.h @@ -128,7 +128,7 @@ public: int animationDuration() const; #ifndef QT_NO_CSSPARSER - void parseCSStoXMLAttrs(QString css, QVector<QSvgCssAttribute> *attributes); + void parseCSStoXMLAttrs(const QString &css, QVector<QSvgCssAttribute> *attributes); #endif inline QPen defaultPen() const diff --git a/src/svg/qsvgnode.cpp b/src/svg/qsvgnode.cpp index 14aaea4..29fd4e5 100644 --- a/src/svg/qsvgnode.cpp +++ b/src/svg/qsvgnode.cpp @@ -341,7 +341,7 @@ QSvgNode::DisplayMode QSvgNode::displayMode() const qreal QSvgNode::strokeWidth(QPainter *p) { - QPen pen = p->pen(); + const QPen &pen = p->pen(); if (pen.style() == Qt::NoPen || pen.brush().style() == Qt::NoBrush || pen.isCosmetic()) return 0; return pen.widthF(); diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp index b934f94..c4edd25 100644 --- a/src/svg/qsvgstyle.cpp +++ b/src/svg/qsvgstyle.cpp @@ -126,7 +126,7 @@ void QSvgFillStyle::setFillStyle(QSvgFillStyleProperty* style) void QSvgFillStyle::setBrush(QBrush brush) { - m_fill = brush; + m_fill = std::move(brush); m_style = 0; m_fillSet = 1; } diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index da464cc..3143ad2 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -60,6 +60,7 @@ QSvgTinyDocument::QSvgTinyDocument() : QSvgStructureNode(0) , m_widthPercent(false) , m_heightPercent(false) + , m_time(0) , m_animated(false) , m_animationDuration(0) , m_fps(30) @@ -230,9 +231,8 @@ QSvgTinyDocument * QSvgTinyDocument::load(QXmlStreamReader *contents) void QSvgTinyDocument::draw(QPainter *p, const QRectF &bounds) { - if (m_time.isNull()) { - m_time.start(); - } + if (m_time == 0) + m_time = QDateTime::currentMSecsSinceEpoch(); if (displayMode() == QSvgNode::NoneMode) return; @@ -269,9 +269,8 @@ void QSvgTinyDocument::draw(QPainter *p, const QString &id, qCDebug(lcSvgHandler, "Couldn't find node %s. Skipping rendering.", qPrintable(id)); return; } - if (m_time.isNull()) { - m_time.start(); - } + if (m_time == 0) + m_time = QDateTime::currentMSecsSinceEpoch(); if (node->displayMode() == QSvgNode::NoneMode) return; @@ -339,6 +338,7 @@ void QSvgTinyDocument::setHeight(int len, bool percent) void QSvgTinyDocument::setViewBox(const QRectF &rect) { m_viewBox = rect; + m_implicitViewBox = false; } void QSvgTinyDocument::addSvgFont(QSvgFont *font) @@ -376,7 +376,7 @@ QSvgFillStyleProperty *QSvgTinyDocument::namedStyle(const QString &id) const void QSvgTinyDocument::restartAnimation() { - m_time.restart(); + m_time = QDateTime::currentMSecsSinceEpoch(); } bool QSvgTinyDocument::animated() const @@ -420,14 +420,35 @@ void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect, source = viewBox(); if (source != target && !source.isNull()) { - QTransform transform; - transform.scale(target.width() / source.width(), - target.height() / source.height()); - QRectF c2 = transform.mapRect(source); - p->translate(target.x() - c2.x(), - target.y() - c2.y()); - p->scale(target.width() / source.width(), - target.height() / source.height()); + if (m_implicitViewBox) { + QTransform transform; + transform.scale(target.width() / source.width(), + target.height() / source.height()); + QRectF c2 = transform.mapRect(source); + p->translate(target.x() - c2.x(), + target.y() - c2.y()); + p->scale(target.width() / source.width(), + target.height() / source.height()); + } else { + // Code path used when a view box is specified and we're not rendering a specific element by id + // but the entire document. This attempts to emulate the default values of the <preserveAspectRatio> + // tag that's implicitly defined when <viewbox> is used. + + // Apply the view box translation if specified. + p->translate(target.x() - source.x(), + target.y() - source.y()); + + // Scale the view box into the view port (target) by preserve the aspect ratio. + QSizeF viewBoxSize = source.size(); + viewBoxSize.scale(target.width(), target.height(), Qt::KeepAspectRatio); + + // Center the view box in the view port + p->translate((target.width() - viewBoxSize.width()) / 2, + (target.height() - viewBoxSize.height()) / 2); + + p->scale(viewBoxSize.width() / source.width(), + viewBoxSize.height() / source.height()); + } } } @@ -469,7 +490,7 @@ QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const int QSvgTinyDocument::currentFrame() const { - double runningPercentage = qMin(m_time.elapsed()/double(m_animationDuration), 1.); + double runningPercentage = qMin(currentElapsed() / double(m_animationDuration), 1.); int totalFrames = m_fps * m_animationDuration; @@ -482,8 +503,8 @@ void QSvgTinyDocument::setCurrentFrame(int frame) double framePercentage = frame/double(totalFrames); double timeForFrame = m_animationDuration * framePercentage; //in S timeForFrame *= 1000; //in ms - int timeToAdd = int(timeForFrame - m_time.elapsed()); - m_time = m_time.addMSecs(timeToAdd); + int timeToAdd = int(timeForFrame - currentElapsed()); + m_time += timeToAdd; } void QSvgTinyDocument::setFramesPerSecond(int num) diff --git a/src/svg/qsvgtinydocument_p.h b/src/svg/qsvgtinydocument_p.h index aa51751..404587d 100644 --- a/src/svg/qsvgtinydocument_p.h +++ b/src/svg/qsvgtinydocument_p.h @@ -125,13 +125,14 @@ private: bool m_widthPercent; bool m_heightPercent; + mutable bool m_implicitViewBox = true; mutable QRectF m_viewBox; QHash<QString, QSvgRefCounter<QSvgFont> > m_fonts; QHash<QString, QSvgNode *> m_namedNodes; QHash<QString, QSvgRefCounter<QSvgFillStyleProperty> > m_namedStyles; - QTime m_time; + qint64 m_time; bool m_animated; int m_animationDuration; int m_fps; @@ -173,8 +174,10 @@ inline bool QSvgTinyDocument::heightPercent() const inline QRectF QSvgTinyDocument::viewBox() const { - if (m_viewBox.isNull()) + if (m_viewBox.isNull()) { m_viewBox = transformedBounds(); + m_implicitViewBox = true; + } return m_viewBox; } @@ -186,7 +189,7 @@ inline bool QSvgTinyDocument::preserveAspectRatio() const inline int QSvgTinyDocument::currentElapsed() const { - return m_time.elapsed(); + return QDateTime::currentMSecsSinceEpoch() - m_time; } inline int QSvgTinyDocument::animationDuration() const |