Index: trunk/src/svg/qsvggraphics.cpp
===================================================================
--- trunk/src/svg/qsvggraphics.cpp	(revision 651)
+++ trunk/src/svg/qsvggraphics.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -79,13 +79,13 @@
 }
 
-static inline QRectF boundsOnStroke(const QPainterPath &path, qreal width)
+static inline QRectF boundsOnStroke(QPainter *p, const QPainterPath &path, qreal width)
 {
     QPainterPathStroker stroker;
     stroker.setWidth(width);
     QPainterPath stroke = stroker.createStroke(path);
-    return stroke.boundingRect();
-}
-
-QSvgCircle::QSvgCircle(QSvgNode *parent, const QRectF &rect)
+    return p->transform().map(stroke).boundingRect();
+}
+
+QSvgEllipse::QSvgEllipse(QSvgNode *parent, const QRectF &rect)
     : QSvgNode(parent), m_bounds(rect)
 {
@@ -93,17 +93,13 @@
 
 
-QRectF QSvgCircle::bounds() const
-{
-    qreal sw = strokeWidth();
-    if (qFuzzyIsNull(sw))
-        return m_bounds;
-    else {
-        QPainterPath path;
-        path.addRect(m_bounds);
-        return boundsOnStroke(path, sw);
-    }
-}
-
-void QSvgCircle::draw(QPainter *p, QSvgExtraStates &states)
+QRectF QSvgEllipse::bounds(QPainter *p, QSvgExtraStates &) const
+{
+    QPainterPath path;
+    path.addEllipse(m_bounds);
+    qreal sw = strokeWidth(p);
+    return qFuzzyIsNull(sw) ? p->transform().map(path).boundingRect() : boundsOnStroke(p, path, sw);
+}
+
+void QSvgEllipse::draw(QPainter *p, QSvgExtraStates &states)
 {
     applyStyle(p, states);
@@ -113,7 +109,6 @@
 
 QSvgArc::QSvgArc(QSvgNode *parent, const QPainterPath &path)
-    : QSvgNode(parent), cubic(path)
-{
-    m_cachedBounds = path.boundingRect();
+    : QSvgNode(parent), m_path(path)
+{
 }
 
@@ -124,31 +119,7 @@
         qreal oldOpacity = p->opacity();
         p->setOpacity(oldOpacity * states.strokeOpacity);
-        p->drawPath(cubic);
+        p->drawPath(m_path);
         p->setOpacity(oldOpacity);
     }
-    revertStyle(p, states);
-}
-
-QSvgEllipse::QSvgEllipse(QSvgNode *parent, const QRectF &rect)
-    : QSvgNode(parent), m_bounds(rect)
-{
-}
-
-QRectF QSvgEllipse::bounds() const
-{
-    qreal sw = strokeWidth();
-    if (qFuzzyIsNull(sw))
-        return m_bounds;
-    else {
-        QPainterPath path;
-        path.addEllipse(m_bounds);
-        return boundsOnStroke(path, sw);
-    }
-}
-
-void QSvgEllipse::draw(QPainter *p, QSvgExtraStates &states)
-{
-    applyStyle(p, states);
-    QT_SVG_DRAW_SHAPE(p->drawEllipse(m_bounds));
     revertStyle(p, states);
 }
@@ -174,5 +145,5 @@
 
 QSvgLine::QSvgLine(QSvgNode *parent, const QLineF &line)
-    : QSvgNode(parent), m_bounds(line)
+    : QSvgNode(parent), m_line(line)
 {
 }
@@ -185,5 +156,5 @@
         qreal oldOpacity = p->opacity();
         p->setOpacity(oldOpacity * states.strokeOpacity);
-        p->drawLine(m_bounds);
+        p->drawLine(m_line);
         p->setOpacity(oldOpacity);
     }
@@ -204,17 +175,9 @@
 }
 
-QRectF QSvgPath::bounds() const
-{
-    qreal sw = strokeWidth();
-    if (qFuzzyIsNull(sw)) {
-        if (m_cachedBounds.isNull())
-            //m_cachedBounds = m_path.controlPointRect();
-            m_cachedBounds = m_path.boundingRect();
-
-        return m_cachedBounds;
-    }
-    else {
-        return boundsOnStroke(m_path, sw);
-    }
+QRectF QSvgPath::bounds(QPainter *p, QSvgExtraStates &) const
+{
+    qreal sw = strokeWidth(p);
+    return qFuzzyIsNull(sw) ? p->transform().map(m_path).boundingRect()
+        : boundsOnStroke(p, m_path, sw);
 }
 
@@ -224,13 +187,13 @@
 }
 
-QRectF QSvgPolygon::bounds() const
-{
-    qreal sw = strokeWidth();
-    if (qFuzzyIsNull(sw))
-        return m_poly.boundingRect();
-    else {
+QRectF QSvgPolygon::bounds(QPainter *p, QSvgExtraStates &) const
+{
+    qreal sw = strokeWidth(p);
+    if (qFuzzyIsNull(sw)) {
+        return p->transform().map(m_poly).boundingRect();
+    } else {
         QPainterPath path;
         path.addPolygon(m_poly);
-        return boundsOnStroke(path, sw);
+        return boundsOnStroke(p, path, sw);
     }
 }
@@ -275,13 +238,13 @@
 }
 
-QRectF QSvgRect::bounds() const
-{
-    qreal sw = strokeWidth();
-    if (qFuzzyIsNull(sw))
-        return m_rect;
-    else {
+QRectF QSvgRect::bounds(QPainter *p, QSvgExtraStates &) const
+{
+    qreal sw = strokeWidth(p);
+    if (qFuzzyIsNull(sw)) {
+        return p->transform().mapRect(m_rect);
+    } else {
         QPainterPath path;
         path.addRect(m_rect);
-        return boundsOnStroke(path, sw);
+        return boundsOnStroke(p, path, sw);
     }
 }
@@ -323,5 +286,5 @@
 }
 
-//QRectF QSvgText::bounds() const {}
+//QRectF QSvgText::bounds(QPainter *p, QSvgExtraStates &) const {}
 
 void QSvgText::draw(QPainter *p, QSvgExtraStates &states)
@@ -594,78 +557,55 @@
 }
 
-QRectF QSvgUse::bounds() const
-{
-    if (m_link && m_bounds.isEmpty())  {
-        m_bounds = m_link->bounds();
-        m_bounds = QRectF(m_bounds.x()+m_start.x(),
-                          m_bounds.y()+m_start.y(),
-                          m_bounds.width(),
-                          m_bounds.height());
-
-        return m_bounds;
-    }
-    return m_bounds;
-}
-
-QRectF QSvgUse::transformedBounds(const QTransform &transform) const
+QRectF QSvgUse::bounds(QPainter *p, QSvgExtraStates &states) const
 {
     QRectF bounds;
-    QTransform t = transform;
-
-    if (m_link)  {
-        QSvgTransformStyle *transStyle = m_style.transform;
-        if (transStyle) {
-            t = transStyle->qtransform() * t;
-        }
-        t.translate(m_start.x(), m_start.y());
-
-        bounds = m_link->transformedBounds(t);
-
-        return bounds;
+    if (m_link) {
+        p->translate(m_start);
+        bounds = m_link->transformedBounds(p, states);
+        p->translate(-m_start);
     }
     return bounds;
 }
 
-QRectF QSvgPolyline::bounds() const
-{
-    qreal sw = strokeWidth();
-    if (qFuzzyIsNull(sw))
-        return m_poly.boundingRect();
-    else {
+QRectF QSvgPolyline::bounds(QPainter *p, QSvgExtraStates &) const
+{
+    qreal sw = strokeWidth(p);
+    if (qFuzzyIsNull(sw)) {
+        return p->transform().map(m_poly).boundingRect();
+    } else {
         QPainterPath path;
         path.addPolygon(m_poly);
-        return boundsOnStroke(path, sw);
-    }
-}
-
-QRectF QSvgArc::bounds() const
-{
-    qreal sw = strokeWidth();
-    if (qFuzzyIsNull(sw))
-        return m_cachedBounds;
-    else {
-        return boundsOnStroke(cubic, sw);
-    }
-}
-
-QRectF QSvgImage::bounds() const
-{
-    return m_bounds;
-}
-
-QRectF QSvgLine::bounds() const
-{
-    qreal sw = strokeWidth();
+        return boundsOnStroke(p, path, sw);
+    }
+}
+
+QRectF QSvgArc::bounds(QPainter *p, QSvgExtraStates &) const
+{
+    qreal sw = strokeWidth(p);
+    return qFuzzyIsNull(sw) ? p->transform().map(m_path).boundingRect()
+        : boundsOnStroke(p, m_path, sw);
+}
+
+QRectF QSvgImage::bounds(QPainter *p, QSvgExtraStates &) const
+{
+    return p->transform().mapRect(m_bounds);
+}
+
+QRectF QSvgLine::bounds(QPainter *p, QSvgExtraStates &) const
+{
+    qreal sw = strokeWidth(p);
     if (qFuzzyIsNull(sw)) {
-        qreal minX = qMin(m_bounds.x1(), m_bounds.x2());
-        qreal minY = qMin(m_bounds.y1(), m_bounds.y2());
-        qreal maxX = qMax(m_bounds.x1(), m_bounds.x2());
-        qreal maxY = qMax(m_bounds.y1(), m_bounds.y2());
-        return QRectF(minX, minY, maxX-minX, maxY-minY);
+        QPointF p1 = p->transform().map(m_line.p1());
+        QPointF p2 = p->transform().map(m_line.p2());
+        qreal minX = qMin(p1.x(), p2.x());
+        qreal minY = qMin(p1.y(), p2.y());
+        qreal maxX = qMax(p1.x(), p2.x());
+        qreal maxY = qMax(p1.y(), p2.y());
+        return QRectF(minX, minY, maxX - minX, maxY - minY);
     } else {
         QPainterPath path;
-        path.moveTo(m_bounds.x1(), m_bounds.y1());
-        path.lineTo(m_bounds.x2(), m_bounds.y2());
-        return boundsOnStroke(path, sw);
+        path.moveTo(m_line.p1());
+        path.lineTo(m_line.p2());
+        return boundsOnStroke(p, path, sw);
     }
 }
