1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <cppuhelper/supportsservice.hxx>
12 #include <libstaroffice/libstaroffice.hxx>
14 #include "StarOfficeDrawImportFilter.hxx"
16 using com::sun::star::uno::Sequence
;
17 using com::sun::star::uno::XComponentContext
;
18 using com::sun::star::uno::XInterface
;
20 static bool handleEmbeddedSTOFFGraphicObject(const librevenge::RVNGBinaryData
& data
,
21 OdfDocumentHandler
* pHandler
,
22 const OdfStreamType streamType
)
24 OdgGenerator exporter
;
25 exporter
.addDocumentHandler(pHandler
, streamType
);
26 return STOFFDocument::decodeGraphic(data
, &exporter
);
29 static bool handleEmbeddedSTOFFSpreadsheetObject(const librevenge::RVNGBinaryData
& data
,
30 OdfDocumentHandler
* pHandler
,
31 const OdfStreamType streamType
)
33 OdsGenerator exporter
;
34 exporter
.registerEmbeddedObjectHandler("image/stoff-odg", &handleEmbeddedSTOFFGraphicObject
);
35 exporter
.addDocumentHandler(pHandler
, streamType
);
36 return STOFFDocument::decodeSpreadsheet(data
, &exporter
);
39 bool StarOfficeDrawImportFilter::doImportDocument(weld::Window
*,
40 librevenge::RVNGInputStream
& rInput
,
41 OdgGenerator
& rGenerator
, utl::MediaDescriptor
&)
43 return STOFFDocument::STOFF_R_OK
== STOFFDocument::parse(&rInput
, &rGenerator
);
46 bool StarOfficeDrawImportFilter::doDetectFormat(librevenge::RVNGInputStream
& rInput
,
51 STOFFDocument::Kind docKind
= STOFFDocument::STOFF_K_UNKNOWN
;
52 const STOFFDocument::Confidence confidence
53 = STOFFDocument::isFileFormatSupported(&rInput
, docKind
);
55 if (confidence
== STOFFDocument::STOFF_C_EXCELLENT
56 || confidence
== STOFFDocument::STOFF_C_SUPPORTED_ENCRYPTION
)
60 case STOFFDocument::STOFF_K_DRAW
:
61 rTypeName
= "StarOffice_Drawing";
68 return !rTypeName
.isEmpty();
71 void StarOfficeDrawImportFilter::doRegisterHandlers(OdgGenerator
& rGenerator
)
73 rGenerator
.registerEmbeddedObjectHandler("image/stoff-odg", &handleEmbeddedSTOFFGraphicObject
);
74 rGenerator
.registerEmbeddedObjectHandler("image/stoff-ods",
75 &handleEmbeddedSTOFFSpreadsheetObject
);
79 OUString SAL_CALL
StarOfficeDrawImportFilter::getImplementationName()
81 return "org.libreoffice.comp.Draw.StarOfficeDrawImportFilter";
84 sal_Bool SAL_CALL
StarOfficeDrawImportFilter::supportsService(const OUString
& rServiceName
)
86 return cppu::supportsService(this, rServiceName
);
89 Sequence
<OUString
> SAL_CALL
StarOfficeDrawImportFilter::getSupportedServiceNames()
91 return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
94 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
95 org_libreoffice_comp_Draw_StarOfficeDrawImportFilter_get_implementation(
96 css::uno::XComponentContext
* const context
, const css::uno::Sequence
<css::uno::Any
>&)
98 return cppu::acquire(new StarOfficeDrawImportFilter(context
));
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */