summaryrefslogtreecommitdiffstats
path: root/src/plugins/imageformats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-06-12 12:35:46 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-06-12 12:35:46 (GMT)
commitc53414e11b3f980f81a4470b3fb52f9d1aa80d56 (patch)
tree7d51540148af638b1c4fb7cda939d34739245457 /src/plugins/imageformats
parentf2b93868f48a3e2d6e462ca8a051ab47eefef49d (diff)
parent304bf2ef0a99882d2d969347f85a330523086fb3 (diff)
downloadQt-c53414e11b3f980f81a4470b3fb52f9d1aa80d56.zip
Qt-c53414e11b3f980f81a4470b3fb52f9d1aa80d56.tar.gz
Qt-c53414e11b3f980f81a4470b3fb52f9d1aa80d56.tar.bz2
Merge commit 'origin/4.5'
Conflicts: demos/boxes/glshaders.cpp src/gui/graphicsview/qgraphicsitem.cpp tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp tools/linguist/shared/cpp.cpp translations/linguist_ja.qm translations/qt_ru.qm
Diffstat (limited to 'src/plugins/imageformats')
-rw-r--r--src/plugins/imageformats/svg/qsvgiohandler.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/plugins/imageformats/svg/qsvgiohandler.cpp b/src/plugins/imageformats/svg/qsvgiohandler.cpp
index 41b247b..405a760 100644
--- a/src/plugins/imageformats/svg/qsvgiohandler.cpp
+++ b/src/plugins/imageformats/svg/qsvgiohandler.cpp
@@ -64,6 +64,7 @@ public:
}
bool load(QIODevice *device);
+ static bool findSvgTag(QIODevice *device);
QSvgRenderer *r;
QSize defaultSize;
@@ -86,6 +87,33 @@ bool QSvgIOHandlerPrivate::load(QIODevice *device)
return loaded;
}
+bool QSvgIOHandlerPrivate::findSvgTag(QIODevice *device)
+{
+ qint64 pos = device->pos();
+ device->seek(0);
+ char buffer[256];
+ const char svg_tag[] = "<svg";
+
+ while (1) {
+ int size = device->read(buffer, 256);
+ for (int i=0; i<size - 5; ++i) {
+ if (!memcmp(buffer + i, svg_tag, 4)) {
+ if (buffer[i+4] == ' ' || buffer[i+4] == '\t'
+ || buffer[i+4] == '\n' || buffer[i+4] == '\r')
+ {
+ device->seek(pos);
+ return true;
+ }
+ }
+ }
+ if (device->atEnd())
+ break;
+ device->seek(device->pos()-4);
+ }
+ device->seek(pos);
+ return false;
+}
+
QSvgIOHandler::QSvgIOHandler()
: d(new QSvgIOHandlerPrivate())
{
@@ -101,9 +129,7 @@ QSvgIOHandler::~QSvgIOHandler()
bool QSvgIOHandler::canRead() const
{
- QByteArray contents = device()->peek(80);
-
- return contents.contains("<svg");
+ return QSvgIOHandlerPrivate::findSvgTag(device());
}
@@ -182,8 +208,7 @@ bool QSvgIOHandler::supportsOption(ImageOption option) const
bool QSvgIOHandler::canRead(QIODevice *device)
{
- QByteArray contents = device->peek(80);
- return contents.contains("<svg");
+ return QSvgIOHandlerPrivate::findSvgTag(device);
}
QT_END_NAMESPACE