| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include <qimageiohandler.h> |
| 5 | #include <qstringlist.h> |
| 6 | |
| 7 | #if !defined(QT_NO_SVGRENDERER) |
| 8 | |
| 9 | #include "qsvgiohandler.h" |
| 10 | |
| 11 | #include <qiodevice.h> |
| 12 | #include <qbytearray.h> |
| 13 | #include <qdebug.h> |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | class QSvgPlugin : public QImageIOPlugin |
| 18 | { |
| 19 | Q_OBJECT |
| 20 | #ifndef QT_NO_COMPRESS |
| 21 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface"FILE "svg.json") |
| 22 | #else |
| 23 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface"FILE "svg-nocompress.json") |
| 24 | #endif |
| 25 | |
| 26 | public: |
| 27 | Capabilities capabilities(QIODevice *device, const QByteArray &format) const override; |
| 28 | QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override; |
| 29 | }; |
| 30 | |
| 31 | QImageIOPlugin::Capabilities QSvgPlugin::capabilities(QIODevice *device, const QByteArray &format) const |
| 32 | { |
| 33 | #ifndef QT_NO_COMPRESS |
| 34 | if (format == "svg"|| format == "svgz") |
| 35 | #else |
| 36 | if (format == "svg") |
| 37 | #endif |
| 38 | return Capabilities(CanRead); |
| 39 | Capabilities cap; |
| 40 | if (!format.isEmpty()) |
| 41 | return cap; |
| 42 | if (device->isReadable() && QSvgIOHandler::canRead(device)) |
| 43 | cap |= CanRead; |
| 44 | return cap; |
| 45 | } |
| 46 | |
| 47 | QImageIOHandler *QSvgPlugin::create(QIODevice *device, const QByteArray &format) const |
| 48 | { |
| 49 | QSvgIOHandler *hand = new QSvgIOHandler(); |
| 50 | hand->setDevice(device); |
| 51 | hand->setFormat(format); |
| 52 | return hand; |
| 53 | } |
| 54 | |
| 55 | QT_END_NAMESPACE |
| 56 | |
| 57 | #include "main.moc" |
| 58 | |
| 59 | #endif // !QT_NO_IMAGEFORMATPLUGIN |
| 60 |
