Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / writerperfect / source / draw / MWAWDrawImportFilter.cxx
blobf99c67e9df7708e84020997374d56fb3d00194bf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* MWAWDrawImportFilter: Sets up the filter, and calls DocumentCollector
3 * to do the actual filtering
5 * This file is part of the LibreOffice project.
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <cppuhelper/supportsservice.hxx>
14 #include <libmwaw/libmwaw.hxx>
15 #include <libodfgen/libodfgen.hxx>
17 #include "MWAWDrawImportFilter.hxx"
19 using com::sun::star::uno::Sequence;
20 using com::sun::star::uno::XInterface;
21 using com::sun::star::uno::RuntimeException;
22 using com::sun::star::uno::XComponentContext;
24 static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
26 OdgGenerator exporter;
27 exporter.addDocumentHandler(pHandler, streamType);
28 return MWAWDocument::decodeGraphic(data, &exporter);
31 static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
33 OdsGenerator exporter;
34 exporter.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
35 exporter.addDocumentHandler(pHandler, streamType);
36 return MWAWDocument::decodeSpreadsheet(data, &exporter);
39 bool MWAWDrawImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdgGenerator &rGenerator, utl::MediaDescriptor &)
41 return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
44 bool MWAWDrawImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
46 rTypeName.clear();
48 MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN;
49 MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN;
50 const MWAWDocument::Confidence confidence = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
52 if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
54 switch (docKind)
56 case MWAWDocument::MWAW_K_DRAW:
57 switch (docType)
59 case MWAWDocument::MWAW_T_CLARISWORKS:
60 rTypeName = "draw_ClarisWorks";
61 break;
62 default:
63 rTypeName = "MWAW_Drawing";
64 break;
66 break;
67 case MWAWDocument::MWAW_K_PAINT:
68 switch (docType)
70 case MWAWDocument::MWAW_T_CLARISWORKS:
71 rTypeName = "draw_ClarisWorks";
72 break;
73 default:
74 rTypeName = "MWAW_Bitmap";
75 break;
77 break;
78 default:
79 break;
83 return !rTypeName.isEmpty();
86 void MWAWDrawImportFilter::doRegisterHandlers(OdgGenerator &rGenerator)
88 rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
89 rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods", &handleEmbeddedMWAWSpreadsheetObject);
92 // XServiceInfo
93 OUString SAL_CALL MWAWDrawImportFilter::getImplementationName()
94 throw (RuntimeException, std::exception)
96 return OUString("com.sun.star.comp.Draw.MWAWDrawImportFilter");
99 sal_Bool SAL_CALL MWAWDrawImportFilter::supportsService(const OUString &rServiceName)
100 throw (RuntimeException, std::exception)
102 return cppu::supportsService(this, rServiceName);
105 Sequence< OUString > SAL_CALL MWAWDrawImportFilter::getSupportedServiceNames()
106 throw (RuntimeException, std::exception)
108 Sequence < OUString > aRet(2);
109 OUString *pArray = aRet.getArray();
110 pArray[0] = "com.sun.star.document.ImportFilter";
111 pArray[1] = "com.sun.star.document.ExtendedTypeDetection";
112 return aRet;
115 extern "C"
116 SAL_DLLPUBLIC_EXPORT css::uno::XInterface *SAL_CALL
117 com_sun_star_comp_Draw_MWAWDrawImportFilter_get_implementation(
118 css::uno::XComponentContext *const context,
119 const css::uno::Sequence<css::uno::Any> &)
121 return cppu::acquire(new MWAWDrawImportFilter(context));
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */