diff --git a/libs/flake/KoSvgPaste.cpp b/libs/flake/KoSvgPaste.cpp index 21efa62187..d914c55d51 100644 --- a/libs/flake/KoSvgPaste.cpp +++ b/libs/flake/KoSvgPaste.cpp @@ -1,81 +1,99 @@ /* * Copyright (c) 2017 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KoSvgPaste.h" #include #include #include #include #include #include #include #include bool KoSvgPaste::hasShapes() { const QMimeData *mimeData = QApplication::clipboard()->mimeData(); - return mimeData && mimeData->hasFormat("image/svg+xml"); + bool hasSvg = false; + if (mimeData) { + Q_FOREACH(const QString &format, mimeData->formats()) { + if (format.toLower().contains("svg")) { + hasSvg = true; + break; + } + } + } + + return hasSvg; } QList KoSvgPaste::fetchShapes(const QRectF viewportInPx, qreal resolutionPPI, QSizeF *fragmentSize) { QList shapes; const QMimeData *mimeData = QApplication::clipboard()->mimeData(); if (!mimeData) return shapes; - QByteArray data = mimeData->data("image/svg+xml"); + QByteArray data; + + Q_FOREACH(const QString &format, mimeData->formats()) { + if (format.toLower().contains("svg")) { + data = mimeData->data(format); + break; + } + } + if (data.isEmpty()) { return shapes; } return fetchShapesFromData(data, viewportInPx, resolutionPPI, fragmentSize); } QList KoSvgPaste::fetchShapesFromData(const QByteArray &data, const QRectF viewportInPx, qreal resolutionPPI, QSizeF *fragmentSize) { QList shapes; if (data.isEmpty()) { return shapes; } QString errorMsg; int errorLine = 0; int errorColumn = 0; KoXmlDocument doc = SvgParser::createDocumentFromSvg(data, &errorMsg, &errorLine, &errorColumn); if (doc.isNull()) { qWarning() << "Failed to process an SVG file at" << errorLine << ":" << errorColumn << "->" << errorMsg; return shapes; } KoDocumentResourceManager resourceManager; SvgParser parser(&resourceManager); parser.setResolution(viewportInPx, resolutionPPI); shapes = parser.parseSvg(doc.documentElement(), fragmentSize); return shapes; }