summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit983a4b61f1da719dac647a7190533d1edf2b2159 (patch)
tree3b52101d36c2b432540c20e0e188f62197c42c59 /src/plugins
downloadqtsvg-983a4b61f1da719dac647a7190533d1edf2b2159.tar.gz
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/iconengines/iconengines.pro3
-rw-r--r--src/plugins/iconengines/svgiconengine/main.cpp84
-rw-r--r--src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp357
-rw-r--r--src/plugins/iconengines/svgiconengine/qsvgiconengine.h84
-rw-r--r--src/plugins/iconengines/svgiconengine/svgiconengine.pro13
-rw-r--r--src/plugins/imageformats/imageformats.pro2
-rw-r--r--src/plugins/imageformats/svg/main.cpp94
-rw-r--r--src/plugins/imageformats/svg/qsvgiohandler.cpp267
-rw-r--r--src/plugins/imageformats/svg/qsvgiohandler.h77
-rw-r--r--src/plugins/imageformats/svg/svg.pro13
-rw-r--r--src/plugins/plugins.pro2
11 files changed, 996 insertions, 0 deletions
diff --git a/src/plugins/iconengines/iconengines.pro b/src/plugins/iconengines/iconengines.pro
new file mode 100644
index 0000000..bef8995
--- /dev/null
+++ b/src/plugins/iconengines/iconengines.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+
+contains(QT_CONFIG, svg): SUBDIRS += svgiconengine
diff --git a/src/plugins/iconengines/svgiconengine/main.cpp b/src/plugins/iconengines/svgiconengine/main.cpp
new file mode 100644
index 0000000..f7ca0c2
--- /dev/null
+++ b/src/plugins/iconengines/svgiconengine/main.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qiconengineplugin.h>
+#include <qstringlist.h>
+
+#if !defined(QT_NO_IMAGEFORMATPLUGIN) && !defined(QT_NO_SVG)
+
+#include "qsvgiconengine.h"
+
+#include <qiodevice.h>
+#include <qbytearray.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSvgIconPlugin : public QIconEnginePluginV2
+{
+public:
+ QStringList keys() const;
+ QIconEngineV2 *create(const QString &filename = QString());
+};
+
+QStringList QSvgIconPlugin::keys() const
+{
+ QStringList keys(QLatin1String("svg"));
+#ifndef QT_NO_COMPRESS
+ keys << QLatin1String("svgz") << QLatin1String("svg.gz");
+#endif
+ return keys;
+}
+
+QIconEngineV2 *QSvgIconPlugin::create(const QString &file)
+{
+ QSvgIconEngine *engine = new QSvgIconEngine;
+ if (!file.isNull())
+ engine->addFile(file, QSize(), QIcon::Normal, QIcon::Off);
+ return engine;
+}
+
+Q_EXPORT_STATIC_PLUGIN(QSvgIconPlugin)
+Q_EXPORT_PLUGIN2(qsvgicon, QSvgIconPlugin)
+
+QT_END_NAMESPACE
+
+#endif // !QT_NO_IMAGEFORMATPLUGIN
diff --git a/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp b/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp
new file mode 100644
index 0000000..9d9abb6
--- /dev/null
+++ b/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp
@@ -0,0 +1,357 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "qsvgiconengine.h"
+
+#ifndef QT_NO_SVGRENDERER
+
+#include "qpainter.h"
+#include "qpixmap.h"
+#include "qsvgrenderer.h"
+#include "qpixmapcache.h"
+#include "qstyle.h"
+#include "qapplication.h"
+#include "qstyleoption.h"
+#include "qfileinfo.h"
+#include <QAtomicInt>
+#include "qdebug.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSvgIconEnginePrivate : public QSharedData
+{
+public:
+ QSvgIconEnginePrivate()
+ : svgBuffers(0), addedPixmaps(0)
+ { stepSerialNum(); }
+
+ ~QSvgIconEnginePrivate()
+ { delete addedPixmaps; delete svgBuffers; }
+
+ static int hashKey(QIcon::Mode mode, QIcon::State state)
+ { return (((mode)<<4)|state); }
+
+ QString pmcKey(const QSize &size, QIcon::Mode mode, QIcon::State state)
+ { return QLatin1String("$qt_svgicon_")
+ + QString::number(serialNum, 16).append(QLatin1Char('_'))
+ + QString::number((((((size.width()<<11)|size.height())<<11)|mode)<<4)|state, 16); }
+
+ void stepSerialNum()
+ { serialNum = lastSerialNum.fetchAndAddRelaxed(1); }
+
+ void loadDataForModeAndState(QSvgRenderer *renderer, QIcon::Mode mode, QIcon::State state);
+
+ QHash<int, QString> svgFiles;
+ QHash<int, QByteArray> *svgBuffers;
+ QHash<int, QPixmap> *addedPixmaps;
+ int serialNum;
+ static QAtomicInt lastSerialNum;
+};
+
+QAtomicInt QSvgIconEnginePrivate::lastSerialNum;
+
+static inline int pmKey(const QSize &size, QIcon::Mode mode, QIcon::State state)
+{
+ return ((((((size.width()<<11)|size.height())<<11)|mode)<<4)|state);
+}
+
+QSvgIconEngine::QSvgIconEngine()
+ : d(new QSvgIconEnginePrivate)
+{
+}
+
+QSvgIconEngine::QSvgIconEngine(const QSvgIconEngine &other)
+ : QIconEngineV2(other), d(new QSvgIconEnginePrivate)
+{
+ d->svgFiles = other.d->svgFiles;
+ if (other.d->svgBuffers)
+ d->svgBuffers = new QHash<int, QByteArray>(*other.d->svgBuffers);
+ if (other.d->addedPixmaps)
+ d->addedPixmaps = new QHash<int, QPixmap>(*other.d->addedPixmaps);
+}
+
+
+QSvgIconEngine::~QSvgIconEngine()
+{
+}
+
+
+QSize QSvgIconEngine::actualSize(const QSize &size, QIcon::Mode mode,
+ QIcon::State state)
+{
+ if (d->addedPixmaps) {
+ QPixmap pm = d->addedPixmaps->value(d->hashKey(mode, state));
+ if (!pm.isNull() && pm.size() == size)
+ return size;
+ }
+
+ QPixmap pm = pixmap(size, mode, state);
+ if (pm.isNull())
+ return QSize();
+ return pm.size();
+}
+
+void QSvgIconEnginePrivate::loadDataForModeAndState(QSvgRenderer *renderer, QIcon::Mode mode, QIcon::State state)
+{
+ QByteArray buf;
+ if (svgBuffers) {
+ buf = svgBuffers->value(hashKey(mode, state));
+ if (buf.isEmpty())
+ buf = svgBuffers->value(hashKey(QIcon::Normal, QIcon::Off));
+ }
+ if (!buf.isEmpty()) {
+#ifndef QT_NO_COMPRESS
+ buf = qUncompress(buf);
+#endif
+ renderer->load(buf);
+ } else {
+ QString svgFile = svgFiles.value(hashKey(mode, state));
+ if (svgFile.isEmpty())
+ svgFile = svgFiles.value(hashKey(QIcon::Normal, QIcon::Off));
+ if (!svgFile.isEmpty())
+ renderer->load(svgFile);
+ }
+}
+
+QPixmap QSvgIconEngine::pixmap(const QSize &size, QIcon::Mode mode,
+ QIcon::State state)
+{
+ QPixmap pm;
+
+ QString pmckey(d->pmcKey(size, mode, state));
+ if (QPixmapCache::find(pmckey, pm))
+ return pm;
+
+ if (d->addedPixmaps) {
+ pm = d->addedPixmaps->value(d->hashKey(mode, state));
+ if (!pm.isNull() && pm.size() == size)
+ return pm;
+ }
+
+ QSvgRenderer renderer;
+ d->loadDataForModeAndState(&renderer, mode, state);
+ if (!renderer.isValid())
+ return pm;
+
+ QSize actualSize = renderer.defaultSize();
+ if (!actualSize.isNull())
+ actualSize.scale(size, Qt::KeepAspectRatio);
+
+ QImage img(actualSize, QImage::Format_ARGB32_Premultiplied);
+ img.fill(0x00000000);
+ QPainter p(&img);
+ renderer.render(&p);
+ p.end();
+ pm = QPixmap::fromImage(img);
+ QStyleOption opt(0);
+ opt.palette = QApplication::palette();
+ QPixmap generated = QApplication::style()->generatedIconPixmap(mode, pm, &opt);
+ if (!generated.isNull())
+ pm = generated;
+
+ if (!pm.isNull())
+ QPixmapCache::insert(pmckey, pm);
+
+ return pm;
+}
+
+
+void QSvgIconEngine::addPixmap(const QPixmap &pixmap, QIcon::Mode mode,
+ QIcon::State state)
+{
+ if (!d->addedPixmaps)
+ d->addedPixmaps = new QHash<int, QPixmap>;
+ d->stepSerialNum();
+ d->addedPixmaps->insert(d->hashKey(mode, state), pixmap);
+}
+
+
+void QSvgIconEngine::addFile(const QString &fileName, const QSize &,
+ QIcon::Mode mode, QIcon::State state)
+{
+ if (!fileName.isEmpty()) {
+ QString abs = fileName;
+ if (fileName.at(0) != QLatin1Char(':'))
+ abs = QFileInfo(fileName).absoluteFilePath();
+ if (abs.endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)
+#ifndef QT_NO_COMPRESS
+ || abs.endsWith(QLatin1String(".svgz"), Qt::CaseInsensitive)
+ || abs.endsWith(QLatin1String(".svg.gz"), Qt::CaseInsensitive))
+#endif
+ {
+ QSvgRenderer renderer(abs);
+ if (renderer.isValid()) {
+ d->stepSerialNum();
+ d->svgFiles.insert(d->hashKey(mode, state), abs);
+ }
+ } else {
+ QPixmap pm(abs);
+ if (!pm.isNull())
+ addPixmap(pm, mode, state);
+ }
+ }
+}
+
+void QSvgIconEngine::paint(QPainter *painter, const QRect &rect,
+ QIcon::Mode mode, QIcon::State state)
+{
+ painter->drawPixmap(rect, pixmap(rect.size(), mode, state));
+}
+
+QString QSvgIconEngine::key() const
+{
+ return QLatin1String("svg");
+}
+
+QIconEngineV2 *QSvgIconEngine::clone() const
+{
+ return new QSvgIconEngine(*this);
+}
+
+
+bool QSvgIconEngine::read(QDataStream &in)
+{
+ d = new QSvgIconEnginePrivate;
+ d->svgBuffers = new QHash<int, QByteArray>;
+
+ if (in.version() >= QDataStream::Qt_4_4) {
+ int isCompressed;
+ QHash<int, QString> fileNames; // For memoryoptimization later
+ in >> fileNames >> isCompressed >> *d->svgBuffers;
+#ifndef QT_NO_COMPRESS
+ if (!isCompressed) {
+ foreach(int key, d->svgBuffers->keys())
+ d->svgBuffers->insert(key, qCompress(d->svgBuffers->value(key)));
+ }
+#else
+ if (isCompressed) {
+ qWarning("QSvgIconEngine: Can not decompress SVG data");
+ d->svgBuffers->clear();
+ }
+#endif
+ int hasAddedPixmaps;
+ in >> hasAddedPixmaps;
+ if (hasAddedPixmaps) {
+ d->addedPixmaps = new QHash<int, QPixmap>;
+ in >> *d->addedPixmaps;
+ }
+ }
+ else {
+ QPixmap pixmap;
+ QByteArray data;
+ uint mode;
+ uint state;
+ int num_entries;
+
+ in >> data;
+ if (!data.isEmpty()) {
+#ifndef QT_NO_COMPRESS
+ data = qUncompress(data);
+#endif
+ if (!data.isEmpty())
+ d->svgBuffers->insert(d->hashKey(QIcon::Normal, QIcon::Off), data);
+ }
+ in >> num_entries;
+ for (int i=0; i<num_entries; ++i) {
+ if (in.atEnd())
+ return false;
+ in >> pixmap;
+ in >> mode;
+ in >> state;
+ // The pm list written by 4.3 is buggy and/or useless, so ignore.
+ //addPixmap(pixmap, QIcon::Mode(mode), QIcon::State(state));
+ }
+ }
+
+ return true;
+}
+
+
+bool QSvgIconEngine::write(QDataStream &out) const
+{
+ if (out.version() >= QDataStream::Qt_4_4) {
+ int isCompressed = 0;
+#ifndef QT_NO_COMPRESS
+ isCompressed = 1;
+#endif
+ QHash<int, QByteArray> svgBuffers;
+ if (d->svgBuffers)
+ svgBuffers = *d->svgBuffers;
+ foreach(int key, d->svgFiles.keys()) {
+ QByteArray buf;
+ QFile f(d->svgFiles.value(key));
+ if (f.open(QIODevice::ReadOnly))
+ buf = f.readAll();
+#ifndef QT_NO_COMPRESS
+ buf = qCompress(buf);
+#endif
+ svgBuffers.insert(key, buf);
+ }
+ out << d->svgFiles << isCompressed << svgBuffers;
+ if (d->addedPixmaps)
+ out << (int)1 << *d->addedPixmaps;
+ else
+ out << (int)0;
+ }
+ else {
+ QByteArray buf;
+ if (d->svgBuffers)
+ buf = d->svgBuffers->value(d->hashKey(QIcon::Normal, QIcon::Off));
+ if (buf.isEmpty()) {
+ QString svgFile = d->svgFiles.value(d->hashKey(QIcon::Normal, QIcon::Off));
+ if (!svgFile.isEmpty()) {
+ QFile f(svgFile);
+ if (f.open(QIODevice::ReadOnly))
+ buf = f.readAll();
+ }
+ }
+#ifndef QT_NO_COMPRESS
+ buf = qCompress(buf);
+#endif
+ out << buf;
+ // 4.3 has buggy handling of added pixmaps, so don't write any
+ out << (int)0;
+ }
+ return true;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SVGRENDERER
diff --git a/src/plugins/iconengines/svgiconengine/qsvgiconengine.h b/src/plugins/iconengines/svgiconengine/qsvgiconengine.h
new file mode 100644
index 0000000..245adf6
--- /dev/null
+++ b/src/plugins/iconengines/svgiconengine/qsvgiconengine.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSVGICONENGINE_H
+#define QSVGICONENGINE_H
+
+#include <QtGui/qiconengine.h>
+#include <QtCore/qshareddata.h>
+
+#ifndef QT_NO_SVG
+
+QT_BEGIN_NAMESPACE
+
+class QSvgIconEnginePrivate;
+
+class QSvgIconEngine : public QIconEngineV2
+{
+public:
+ QSvgIconEngine();
+ QSvgIconEngine(const QSvgIconEngine &other);
+ ~QSvgIconEngine();
+ void paint(QPainter *painter, const QRect &rect,
+ QIcon::Mode mode, QIcon::State state);
+ QSize actualSize(const QSize &size, QIcon::Mode mode,
+ QIcon::State state);
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode,
+ QIcon::State state);
+
+ void addPixmap(const QPixmap &pixmap, QIcon::Mode mode,
+ QIcon::State state);
+ void addFile(const QString &fileName, const QSize &size,
+ QIcon::Mode mode, QIcon::State state);
+
+ QString key() const;
+ QIconEngineV2 *clone() const;
+ bool read(QDataStream &in);
+ bool write(QDataStream &out) const;
+
+private:
+ QSharedDataPointer<QSvgIconEnginePrivate> d;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SVG
+#endif
diff --git a/src/plugins/iconengines/svgiconengine/svgiconengine.pro b/src/plugins/iconengines/svgiconengine/svgiconengine.pro
new file mode 100644
index 0000000..5c5a31e
--- /dev/null
+++ b/src/plugins/iconengines/svgiconengine/svgiconengine.pro
@@ -0,0 +1,13 @@
+TARGET = qsvgicon
+include(../../qpluginbase.pri)
+
+HEADERS += qsvgiconengine.h
+SOURCES += main.cpp \
+ qsvgiconengine.cpp
+QT += xml svg
+
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/iconengines
+target.path += $$[QT_INSTALL_PLUGINS]/iconengines
+INSTALLS += target
+
+symbian:TARGET.UID3=0x2001B2E3
diff --git a/src/plugins/imageformats/imageformats.pro b/src/plugins/imageformats/imageformats.pro
new file mode 100644
index 0000000..edffb73
--- /dev/null
+++ b/src/plugins/imageformats/imageformats.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += svg
diff --git a/src/plugins/imageformats/svg/main.cpp b/src/plugins/imageformats/svg/main.cpp
new file mode 100644
index 0000000..e143d3e
--- /dev/null
+++ b/src/plugins/imageformats/svg/main.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qimageiohandler.h>
+#include <qstringlist.h>
+
+#if !defined(QT_NO_IMAGEFORMATPLUGIN) && !defined(QT_NO_SVGRENDERER)
+
+#include "qsvgiohandler.h"
+
+#include <qiodevice.h>
+#include <qbytearray.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSvgPlugin : public QImageIOPlugin
+{
+public:
+ QStringList keys() const;
+ Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
+ QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
+};
+
+QStringList QSvgPlugin::keys() const
+{
+ return QStringList() << QLatin1String("svg") << QLatin1String("svgz");
+}
+
+QImageIOPlugin::Capabilities QSvgPlugin::capabilities(QIODevice *device, const QByteArray &format) const
+{
+ if (format == "svg" || format == "svgz")
+ return Capabilities(CanRead);
+ if (!format.isEmpty())
+ return 0;
+
+ Capabilities cap;
+ if (device->isReadable() && QSvgIOHandler::canRead(device))
+ cap |= CanRead;
+ return cap;
+}
+
+QImageIOHandler *QSvgPlugin::create(QIODevice *device, const QByteArray &format) const
+{
+ QSvgIOHandler *hand = new QSvgIOHandler();
+ hand->setDevice(device);
+ hand->setFormat(format);
+ return hand;
+}
+
+Q_EXPORT_STATIC_PLUGIN(QSvgPlugin)
+Q_EXPORT_PLUGIN2(qsvg, QSvgPlugin)
+
+QT_END_NAMESPACE
+
+#endif // !QT_NO_IMAGEFORMATPLUGIN
diff --git a/src/plugins/imageformats/svg/qsvgiohandler.cpp b/src/plugins/imageformats/svg/qsvgiohandler.cpp
new file mode 100644
index 0000000..3c8f2e9
--- /dev/null
+++ b/src/plugins/imageformats/svg/qsvgiohandler.cpp
@@ -0,0 +1,267 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsvgiohandler.h"
+
+#ifndef QT_NO_SVGRENDERER
+
+#include "qsvgrenderer.h"
+#include "qimage.h"
+#include "qpixmap.h"
+#include "qpainter.h"
+#include "qvariant.h"
+#include "qbuffer.h"
+#include "qdebug.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSvgIOHandlerPrivate
+{
+public:
+ QSvgIOHandlerPrivate(QSvgIOHandler *qq)
+ : q(qq), loaded(false), readDone(false), backColor(Qt::transparent)
+ {}
+
+ bool load(QIODevice *device);
+
+ QSvgIOHandler *q;
+ QSvgRenderer r;
+ QXmlStreamReader xmlReader;
+ QSize defaultSize;
+ QRect clipRect;
+ QSize scaledSize;
+ QRect scaledClipRect;
+ bool loaded;
+ bool readDone;
+ QColor backColor;
+};
+
+
+bool QSvgIOHandlerPrivate::load(QIODevice *device)
+{
+ if (loaded)
+ return true;
+ if (q->format().isEmpty())
+ q->canRead();
+
+ // # The SVG renderer doesn't handle trailing, unrelated data, so we must
+ // assume that all available data in the device is to be read.
+ bool res = false;
+ QBuffer *buf = qobject_cast<QBuffer *>(device);
+ if (buf) {
+ const QByteArray &ba = buf->data();
+ res = r.load(QByteArray::fromRawData(ba.constData() + buf->pos(), ba.size() - buf->pos()));
+ buf->seek(ba.size());
+ } else if (q->format() == "svgz") {
+ res = r.load(device->readAll());
+ } else {
+ xmlReader.setDevice(device);
+ res = r.load(&xmlReader);
+ }
+
+ if (res) {
+ defaultSize = QSize(r.viewBox().width(), r.viewBox().height());
+ loaded = true;
+ }
+
+ return loaded;
+}
+
+
+QSvgIOHandler::QSvgIOHandler()
+ : d(new QSvgIOHandlerPrivate(this))
+{
+
+}
+
+
+QSvgIOHandler::~QSvgIOHandler()
+{
+ delete d;
+}
+
+
+bool QSvgIOHandler::canRead() const
+{
+ if (!device())
+ return false;
+ if (d->loaded && !d->readDone)
+ return true; // Will happen if we have been asked for the size
+
+ QByteArray buf = device()->peek(8);
+ if (buf.startsWith("\x1f\x8b")) {
+ setFormat("svgz");
+ return true;
+ } else if (buf.contains("<?xml") || buf.contains("<svg")) {
+ setFormat("svg");
+ return true;
+ }
+ return false;
+}
+
+
+QByteArray QSvgIOHandler::name() const
+{
+ return "svg";
+}
+
+
+bool QSvgIOHandler::read(QImage *image)
+{
+ if (!d->readDone && d->load(device())) {
+ bool xform = (d->clipRect.isValid() || d->scaledSize.isValid() || d->scaledClipRect.isValid());
+ QSize finalSize = d->defaultSize;
+ QRectF bounds;
+ if (xform && !d->defaultSize.isEmpty()) {
+ bounds = QRectF(QPointF(0,0), QSizeF(d->defaultSize));
+ QPoint tr1, tr2;
+ QSizeF sc(1, 1);
+ if (d->clipRect.isValid()) {
+ tr1 = -d->clipRect.topLeft();
+ finalSize = d->clipRect.size();
+ }
+ if (d->scaledSize.isValid()) {
+ sc = QSizeF(qreal(d->scaledSize.width()) / finalSize.width(),
+ qreal(d->scaledSize.height()) / finalSize.height());
+ finalSize = d->scaledSize;
+ }
+ if (d->scaledClipRect.isValid()) {
+ tr2 = -d->scaledClipRect.topLeft();
+ finalSize = d->scaledClipRect.size();
+ }
+ QTransform t;
+ t.translate(tr2.x(), tr2.y());
+ t.scale(sc.width(), sc.height());
+ t.translate(tr1.x(), tr1.y());
+ bounds = t.mapRect(bounds);
+ }
+ *image = QImage(finalSize, QImage::Format_ARGB32_Premultiplied);
+ if (!finalSize.isEmpty()) {
+ image->fill(d->backColor.rgba());
+ QPainter p(image);
+ d->r.render(&p, bounds);
+ p.end();
+ }
+ d->readDone = true;
+ return true;
+ }
+
+ return false;
+}
+
+
+QVariant QSvgIOHandler::option(ImageOption option) const
+{
+ switch(option) {
+ case ImageFormat:
+ return QImage::Format_ARGB32_Premultiplied;
+ break;
+ case Size:
+ d->load(device());
+ return d->defaultSize;
+ break;
+ case ClipRect:
+ return d->clipRect;
+ break;
+ case ScaledSize:
+ return d->scaledSize;
+ break;
+ case ScaledClipRect:
+ return d->scaledClipRect;
+ break;
+ case BackgroundColor:
+ return d->backColor;
+ break;
+ default:
+ break;
+ }
+ return QVariant();
+}
+
+
+void QSvgIOHandler::setOption(ImageOption option, const QVariant & value)
+{
+ switch(option) {
+ case ClipRect:
+ d->clipRect = value.toRect();
+ break;
+ case ScaledSize:
+ d->scaledSize = value.toSize();
+ break;
+ case ScaledClipRect:
+ d->scaledClipRect = value.toRect();
+ break;
+ case BackgroundColor:
+ d->backColor = value.value<QColor>();
+ break;
+ default:
+ break;
+ }
+}
+
+
+bool QSvgIOHandler::supportsOption(ImageOption option) const
+{
+ switch(option)
+ {
+ case ImageFormat:
+ case Size:
+ case ClipRect:
+ case ScaledSize:
+ case ScaledClipRect:
+ case BackgroundColor:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
+
+bool QSvgIOHandler::canRead(QIODevice *device)
+{
+ QByteArray buf = device->peek(8);
+ return buf.startsWith("\x1f\x8b") || buf.contains("<?xml") || buf.contains("<svg");
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SVGRENDERER
diff --git a/src/plugins/imageformats/svg/qsvgiohandler.h b/src/plugins/imageformats/svg/qsvgiohandler.h
new file mode 100644
index 0000000..7ef0009
--- /dev/null
+++ b/src/plugins/imageformats/svg/qsvgiohandler.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSVGIOHANDLER_H
+#define QSVGIOHANDLER_H
+
+#include <QtGui/qimageiohandler.h>
+
+#ifndef QT_NO_SVGRENDERER
+
+QT_BEGIN_NAMESPACE
+
+class QImage;
+class QByteArray;
+class QIODevice;
+class QVariant;
+class QSvgIOHandlerPrivate;
+
+class QSvgIOHandler : public QImageIOHandler
+{
+public:
+ QSvgIOHandler();
+ ~QSvgIOHandler();
+ virtual bool canRead() const;
+ virtual QByteArray name() const;
+ virtual bool read(QImage *image);
+ static bool canRead(QIODevice *device);
+ virtual QVariant option(ImageOption option) const;
+ virtual void setOption(ImageOption option, const QVariant & value);
+ virtual bool supportsOption(ImageOption option) const;
+
+private:
+ QSvgIOHandlerPrivate *d;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SVGRENDERER
+#endif // QSVGIOHANDLER_H
diff --git a/src/plugins/imageformats/svg/svg.pro b/src/plugins/imageformats/svg/svg.pro
new file mode 100644
index 0000000..bcf4c21
--- /dev/null
+++ b/src/plugins/imageformats/svg/svg.pro
@@ -0,0 +1,13 @@
+TARGET = qsvg
+include(../../qpluginbase.pri)
+
+HEADERS += qsvgiohandler.h
+SOURCES += main.cpp \
+ qsvgiohandler.cpp
+QT += xml svg
+
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/imageformats
+target.path += $$[QT_INSTALL_PLUGINS]/imageformats
+INSTALLS += target
+
+symbian:TARGET.UID3=0x2001E618
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
new file mode 100644
index 0000000..1d714d4
--- /dev/null
+++ b/src/plugins/plugins.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += iconengines imageformats