summaryrefslogtreecommitdiffstats
path: root/src/plugins/imageformats/svg
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/imageformats/svg')
-rw-r--r--src/plugins/imageformats/svg/main.cpp102
-rw-r--r--src/plugins/imageformats/svg/qsvgiohandler.cpp191
-rw-r--r--src/plugins/imageformats/svg/qsvgiohandler.h77
-rw-r--r--src/plugins/imageformats/svg/svg.pro11
4 files changed, 381 insertions, 0 deletions
diff --git a/src/plugins/imageformats/svg/main.cpp b/src/plugins/imageformats/svg/main.cpp
new file mode 100644
index 0000000..978ae40
--- /dev/null
+++ b/src/plugins/imageformats/svg/main.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@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");
+}
+
+QImageIOPlugin::Capabilities QSvgPlugin::capabilities(QIODevice *device, const QByteArray &format) const
+{
+ //### canRead disabled for now because it's hard to detect
+ // whether the file is actually svg without parsing it
+ //if (device->isReadable() && QSvgIOHandler::canRead(device))
+
+ if (format == "svg")
+ return Capabilities(CanRead);
+ else
+ return 0;
+
+
+ if (!device->isOpen())
+ return 0;
+
+ Capabilities cap;
+ if (device->isReadable())
+ 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..41b247b
--- /dev/null
+++ b/src/plugins/imageformats/svg/qsvgiohandler.cpp
@@ -0,0 +1,191 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@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 "qdebug.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSvgIOHandlerPrivate
+{
+public:
+ QSvgIOHandlerPrivate()
+ : r(new QSvgRenderer()), loaded(false)
+ {}
+ ~QSvgIOHandlerPrivate()
+ {
+ delete r;
+ }
+
+ bool load(QIODevice *device);
+
+ QSvgRenderer *r;
+ QSize defaultSize;
+ QSize currentSize;
+ bool loaded;
+};
+
+bool QSvgIOHandlerPrivate::load(QIODevice *device)
+{
+ if (loaded)
+ return true;
+
+ if (r->load(device->readAll())) {
+ defaultSize = QSize(r->viewBox().width(), r->viewBox().height());
+ if (currentSize.isEmpty())
+ currentSize = defaultSize;
+ }
+ loaded = r->isValid();
+
+ return loaded;
+}
+
+QSvgIOHandler::QSvgIOHandler()
+ : d(new QSvgIOHandlerPrivate())
+{
+
+}
+
+
+QSvgIOHandler::~QSvgIOHandler()
+{
+ delete d;
+}
+
+
+bool QSvgIOHandler::canRead() const
+{
+ QByteArray contents = device()->peek(80);
+
+ return contents.contains("<svg");
+}
+
+
+QByteArray QSvgIOHandler::name() const
+{
+ return "svg";
+}
+
+
+bool QSvgIOHandler::read(QImage *image)
+{
+ if (d->load(device())) {
+ *image = QImage(d->currentSize, QImage::Format_ARGB32_Premultiplied);
+ if (!d->currentSize.isEmpty()) {
+ image->fill(0x00000000);
+ QPainter p(image);
+ d->r->render(&p);
+ p.end();
+ }
+ 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 ScaledSize:
+ return d->currentSize;
+ break;
+ default:
+ break;
+ }
+ return QVariant();
+}
+
+
+void QSvgIOHandler::setOption(ImageOption option, const QVariant & value)
+{
+ switch(option) {
+ case Size:
+ d->defaultSize = value.toSize();
+ d->currentSize = value.toSize();
+ break;
+ case ScaledSize:
+ d->currentSize = value.toSize();
+ break;
+ default:
+ break;
+ }
+}
+
+
+bool QSvgIOHandler::supportsOption(ImageOption option) const
+{
+ switch(option)
+ {
+ case ImageFormat:
+ case Size:
+ case ScaledSize:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
+bool QSvgIOHandler::canRead(QIODevice *device)
+{
+ QByteArray contents = device->peek(80);
+ return contents.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..a7a5528
--- /dev/null
+++ b/src/plugins/imageformats/svg/qsvgiohandler.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@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..747d556
--- /dev/null
+++ b/src/plugins/imageformats/svg/svg.pro
@@ -0,0 +1,11 @@
+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