File indexing completed on 2024-05-12 16:35:04
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (C) 2009 Inge Wallin <inge@lysator.liu.se> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 // Own 0022 #include "VectorShapeFactory.h" 0023 0024 // VectorShape 0025 #include "VectorShape.h" 0026 #include "VectorShapeConfigWidget.h" 0027 #include "VectorDebug.h" 0028 0029 // Calligra 0030 #include <KoXmlNS.h> 0031 #include <KoShapeLoadingContext.h> 0032 #include <KoOdfLoadingContext.h> 0033 #include <KoIcon.h> 0034 0035 // KF5 0036 #include <klocalizedstring.h> 0037 0038 0039 VectorShapeFactory::VectorShapeFactory() 0040 : KoShapeFactoryBase(VectorShape_SHAPEID, i18n("Vector image")) 0041 { 0042 setToolTip(i18n("A shape that shows a vector image (EMF/WMF/SVM)")); 0043 setIconName(koIconNameNeededWithSubs("a generic vector image icon", "x-shape-vectorimage", "application-x-wmf")); 0044 setXmlElementNames(KoXmlNS::draw, QStringList("image")); 0045 setLoadingPriority(5); 0046 } 0047 0048 KoShape *VectorShapeFactory::createDefaultShape(KoDocumentResourceManager */*documentResources*/) const 0049 { 0050 VectorShape *shape = new VectorShape(); 0051 shape->setShapeId(VectorShape_SHAPEID); 0052 0053 return shape; 0054 } 0055 0056 bool VectorShapeFactory::supports(const KoXmlElement & e, KoShapeLoadingContext &context) const 0057 { 0058 if (e.localName() == "image" && e.namespaceURI() == KoXmlNS::draw) { 0059 QString href = e.attribute("href"); 0060 if (!href.isEmpty()) { 0061 // check the mimetype 0062 if (href.startsWith(QLatin1String("./"))) { 0063 href.remove(0, 2); 0064 } 0065 // LO 3.5 does not write a mimetype for embedded wmf files, so guess also from content 0066 const QString mimetype = context.odfLoadingContext().mimeTypeForPath(href, true); 0067 0068 return 0069 mimetype == QLatin1String("image/x-svm") || 0070 mimetype == QLatin1String("image/x-emf") || 0071 mimetype == QLatin1String("image/x-wmf") || 0072 // Note: the Vector Shape supports SVG, but _NOT_ in this method, otherwise it will stomp all over loading the artistic text shape's svg 0073 //mimetype == QLatin1String("image/svg+xml") || 0074 // next three for backward compatibility with Calligra 0075 mimetype == QLatin1String("application/x-svm") || 0076 mimetype == QLatin1String("application/x-emf") || 0077 mimetype == QLatin1String("application/x-wmf") || 0078 // seems like MSO does not always write a mimetype 0079 // see jeffcoweb.jeffco.k12.co.us%2Fhigh%2Fchatfield%2Fdepartments%2Fbusiness%2Fbanking_finance%2Funit_Plan_Budget.odp 0080 mimetype.isEmpty() || 0081 // next for compatibility with OO/LO and our filters 0082 // see drwho.virtadpt.net%2Ffiles%2FNOVALUG-Tor.odp 0083 mimetype.startsWith(QLatin1String("application/x-openoffice")); 0084 } 0085 return true; 0086 } 0087 0088 return false; 0089 } 0090 0091 QList<KoShapeConfigWidgetBase*> VectorShapeFactory::createShapeOptionPanels() 0092 { 0093 QList<KoShapeConfigWidgetBase*> result; 0094 result.append(new VectorShapeConfigWidget()); 0095 return result; 0096 }