diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-12-04 03:03:25 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-12-04 03:03:25 +0100 |
commit | 5472d45b461749c440b2f9743e1e07ee0d5e9a48 (patch) | |
tree | 6c4e98ff4f3f7316853e97c7ce5573c90fadfe27 | |
parent | 95adb2fb5b068be9dfd5253c04a00bcd98fe27bb (diff) | |
parent | 1a66404fd0312a835da03a940894737c1bf77310 (diff) | |
download | qtsvg-5472d45b461749c440b2f9743e1e07ee0d5e9a48.tar.gz |
Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: I4221ef67f66bdf111a04978d1e8976339f8071af
-rw-r--r-- | src/svg/qsvghandler.cpp | 24 | ||||
-rw-r--r-- | src/svg/qsvghandler_p.h | 1 | ||||
-rw-r--r-- | tests/auto/qsvgplugin/imageInclude.svg | 18 | ||||
-rw-r--r-- | tests/auto/qsvgplugin/imageIncludeA.svg | 5 | ||||
-rw-r--r-- | tests/auto/qsvgplugin/resources.qrc | 2 | ||||
-rw-r--r-- | tests/auto/qsvgplugin/tst_qsvgplugin.cpp | 41 |
6 files changed, 86 insertions, 5 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 5242ffe..e935649 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -2739,7 +2739,7 @@ static QSvgNode *createImageNode(QSvgNode *parent, const QStringRef y = attributes.value(QLatin1String("y")); const QStringRef width = attributes.value(QLatin1String("width")); const QStringRef height = attributes.value(QLatin1String("height")); - QStringRef filename = attributes.value(QLatin1String("xlink:href")); + QString filename = attributes.value(QLatin1String("xlink:href")).toString(); qreal nx = toDouble(x); qreal ny = toDouble(y); QSvgHandler::LengthType type; @@ -2764,17 +2764,26 @@ static QSvgNode *createImageNode(QSvgNode *parent, int idx = filename.lastIndexOf(QLatin1String("base64,")); if (idx != -1) { idx += 7; - QStringRef dataStr = filename.mid(idx); + const QString dataStr = filename.mid(idx); QByteArray data = QByteArray::fromBase64(dataStr.toLatin1()); image = QImage::fromData(data); } else { qCDebug(lcSvgHandler) << "QSvgHandler::createImageNode: Unrecognized inline image format!"; } - } else - image = QImage(filename.toString()); + } else { + const auto *file = qobject_cast<QFile *>(handler->device()); + if (file) { + QUrl url(filename); + if (url.isRelative()) { + QFileInfo info(file->fileName()); + filename = info.absoluteDir().absoluteFilePath(filename); + } + } + image = QImage(filename); + } if (image.isNull()) { - qDebug()<<"couldn't create image from "<<filename; + qCWarning(lcSvgHandler) << "Could not create image from" << filename; return 0; } @@ -3908,6 +3917,11 @@ bool QSvgHandler::characters(const QStringRef &str) return true; } +QIODevice *QSvgHandler::device() const +{ + return xml->device(); +} + QSvgTinyDocument * QSvgHandler::document() const { return m_doc; diff --git a/src/svg/qsvghandler_p.h b/src/svg/qsvghandler_p.h index 5c13003..8eb061b 100644 --- a/src/svg/qsvghandler_p.h +++ b/src/svg/qsvghandler_p.h @@ -99,6 +99,7 @@ public: QSvgHandler(QXmlStreamReader *const data); ~QSvgHandler(); + QIODevice *device() const; QSvgTinyDocument *document() const; inline bool ok() const { diff --git a/tests/auto/qsvgplugin/imageInclude.svg b/tests/auto/qsvgplugin/imageInclude.svg new file mode 100644 index 0000000..c78d3fa --- /dev/null +++ b/tests/auto/qsvgplugin/imageInclude.svg @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> +<svg version="1.0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100"> + <circle cx="50" cy="50" r="25" fill="#00ff00" /> + + <image x="0" y="0" width="100" height="100" xlink:href="imageIncludeA.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href="./imageIncludeA.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href=":/imageIncludeA.svg" /> + + <image x="0" y="0" width="100" height="100" xlink:href="notExisting.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href="./notExisting.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href="../notExisting.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href="/notExisting.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href=":/notExisting.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href="qrc:///notExisting.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href="file:///notExisting.svg" /> + <image x="0" y="0" width="100" height="100" xlink:href="http://qt.io/notExisting.svg" /> +</svg> diff --git a/tests/auto/qsvgplugin/imageIncludeA.svg b/tests/auto/qsvgplugin/imageIncludeA.svg new file mode 100644 index 0000000..5811505 --- /dev/null +++ b/tests/auto/qsvgplugin/imageIncludeA.svg @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> +<svg version="1.0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> + <circle cx="50" cy="50" r="25" fill="#00ff00" /> +</svg> diff --git a/tests/auto/qsvgplugin/resources.qrc b/tests/auto/qsvgplugin/resources.qrc index fcb311a..fd83b80 100644 --- a/tests/auto/qsvgplugin/resources.qrc +++ b/tests/auto/qsvgplugin/resources.qrc @@ -1,5 +1,7 @@ <!DOCTYPE RCC><RCC version="1.0"> <qresource> + <file>imageInclude.svg</file> + <file>imageIncludeA.svg</file> <file>square.svg</file> <file>square_size.svg</file> <file>square_size_viewbox.svg</file> diff --git a/tests/auto/qsvgplugin/tst_qsvgplugin.cpp b/tests/auto/qsvgplugin/tst_qsvgplugin.cpp index 4ec1737..da49b75 100644 --- a/tests/auto/qsvgplugin/tst_qsvgplugin.cpp +++ b/tests/auto/qsvgplugin/tst_qsvgplugin.cpp @@ -39,6 +39,16 @@ #endif +QStringList logMessages; + +static void messageHandler(QtMsgType pType, const QMessageLogContext& pContext, const QString& pMsg) +{ + Q_UNUSED(pType); + Q_UNUSED(pContext); + logMessages.append(pMsg); +} + + class tst_QSvgPlugin : public QObject { Q_OBJECT @@ -50,6 +60,7 @@ public: private slots: void checkSize_data(); void checkSize(); + void checkImageInclude(); }; @@ -103,6 +114,36 @@ void tst_QSvgPlugin::checkSize() QCOMPARE(imageWidth, image.width()); } +void tst_QSvgPlugin::checkImageInclude() +{ + const QString filename(SRCDIR "imageInclude.svg"); + + QFile file(filename); + file.open(QIODevice::ReadOnly); + + QSvgIOHandler plugin; + plugin.setDevice(&file); + + QImage image; + qInstallMessageHandler(messageHandler); + plugin.read(&image); + qInstallMessageHandler(nullptr); + + file.close(); + + QCOMPARE(logMessages.size(), 8); + QCOMPARE(logMessages.at(0), QString("Could not create image from \"%1notExisting.svg\"").arg(SRCDIR)); + QCOMPARE(logMessages.at(1), QString("Could not create image from \"%1./notExisting.svg\"").arg(SRCDIR)); + QCOMPARE(logMessages.at(2), QString("Could not create image from \"%1../notExisting.svg\"").arg(SRCDIR)); + QCOMPARE(logMessages.at(3), QString("Could not create image from \"%1notExisting.svg\"").arg(QDir::rootPath())); + QCOMPARE(logMessages.at(4), QLatin1String("Could not create image from \":/notExisting.svg\"")); + QCOMPARE(logMessages.at(5), QLatin1String("Could not create image from \"qrc:///notExisting.svg\"")); + QCOMPARE(logMessages.at(6), QLatin1String("Could not create image from \"file:///notExisting.svg\"")); + QCOMPARE(logMessages.at(7), QLatin1String("Could not create image from \"http://qt.io/notExisting.svg\"")); + + logMessages.clear(); +} + QTEST_MAIN(tst_QSvgPlugin) #include "tst_qsvgplugin.moc" |