diff options
author | Lars Schmertmann <Lars.Schmertmann@governikus.de> | 2018-11-25 19:58:55 +0100 |
---|---|---|
committer | Lars Schmertmann <lars.schmertmann@governikus.de> | 2018-11-30 09:23:29 +0000 |
commit | 1a66404fd0312a835da03a940894737c1bf77310 (patch) | |
tree | 62a51af2769adf978a15f444740900b5434021f3 /src | |
parent | 601cfab349f57a765f174804e1d17769484c4fcb (diff) | |
download | qtsvg-1a66404fd0312a835da03a940894737c1bf77310.tar.gz |
Consider relative path in image tags
Task-number: QTBUG-16198
Change-Id: I26bf48cbac39af0fae490ed21579e8de326cd1a3
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/svg/qsvghandler.cpp | 24 | ||||
-rw-r--r-- | src/svg/qsvghandler_p.h | 1 |
2 files changed, 20 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 { |