Fix scaling of svgz images.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Mon, 28 May 2012 06:38:35 +0000 (16:38 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 29 May 2012 06:55:01 +0000 (08:55 +0200)
Force scaling of svgz images to source size as is done for svg.  This
also removes a work around for QTBUG-9053 which has now been resolved.

Task-number: QTBUG-9053
Change-Id: I3aa898f74960ceb2e515bdb3aa44aa5a1a7a64d2
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>

src/quick/util/qquickpixmapcache.cpp
tests/auto/quick/qquickimage/data/heart.svgz [new file with mode: 0644]
tests/auto/quick/qquickimage/tst_qquickimage.cpp

index 2ef95a5..f9fc755 100644 (file)
@@ -321,11 +321,7 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
 {
     QImageReader imgio(dev);
 
-    bool force_scale = false;
-    if (url.path().endsWith(QLatin1String(".svg"),Qt::CaseInsensitive)) {
-        imgio.setFormat("svg"); // QSvgPlugin::capabilities bug QTBUG-9053
-        force_scale = true;
-    }
+    const bool force_scale = imgio.format() == "svg" || imgio.format() == "svgz";
 
     if (requestSize.width() > 0 || requestSize.height() > 0) {
         QSize s = imgio.size();
diff --git a/tests/auto/quick/qquickimage/data/heart.svgz b/tests/auto/quick/qquickimage/data/heart.svgz
new file mode 100644 (file)
index 0000000..c1cb110
Binary files /dev/null and b/tests/auto/quick/qquickimage/data/heart.svgz differ
index aa64490..5e55793 100644 (file)
@@ -84,6 +84,7 @@ private slots:
     void smooth();
     void mirror();
     void svg();
+    void svg_data();
     void geometry();
     void geometry_data();
     void big();
@@ -144,7 +145,8 @@ void tst_qquickimage::imageSource_data()
     QTest::newRow("remote redirected") << SERVER_ADDR "/oldcolors.png" << 120.0 << 120.0 << true << false << false << "";
     if (QImageReader::supportedImageFormats().contains("svg"))
         QTest::newRow("remote svg") << SERVER_ADDR "/heart.svg" << 550.0 << 500.0 << true << false << false << "";
-
+    if (QImageReader::supportedImageFormats().contains("svgz"))
+        QTest::newRow("remote svgz") << SERVER_ADDR "/heart.svgz" << 550.0 << 500.0 << true << false << false << "";
     QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << 0.0 << 0.0 << true
         << false << true << "file::2:1: QML Image: Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found";
 
@@ -359,12 +361,22 @@ void tst_qquickimage::mirror()
     }
 }
 
+void tst_qquickimage::svg_data()
+{
+    QTest::addColumn<QString>("src");
+    QTest::addColumn<QByteArray>("format");
+
+    QTest::newRow("svg") << testFileUrl("heart.svg").toString() << QByteArray("svg");
+    QTest::newRow("svgz") << testFileUrl("heart.svgz").toString() << QByteArray("svgz");
+}
+
 void tst_qquickimage::svg()
 {
-    if (!QImageReader::supportedImageFormats().contains("svg"))
+    QFETCH(QString, src);
+    QFETCH(QByteArray, format);
+    if (!QImageReader::supportedImageFormats().contains(format))
         QSKIP("svg support not available");
 
-    QString src = testFileUrl("heart.svg").toString();
     QString componentStr = "import QtQuick 2.0\nImage { source: \"" + src + "\"; sourceSize.width: 300; sourceSize.height: 300 }";
     QQmlComponent component(&engine);
     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));