diff options
author | osnola <alonso@loria.fr> | 2017-04-02 09:53:44 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2017-04-02 13:42:20 +0200 |
commit | 8988c925ce07395478fbbb10d25fd6c0a10fead5 (patch) | |
tree | 4770a03c18e2db296681297b4ef77322aa3dd522 /writerperfect/source/impress | |
parent | b0067c89e6b2a4e29465d9da9a731ae30a66dce6 (diff) |
libstaroffice import filter improvements
+ add support for presentation file (i.e. the file created will StarImpress
are now open as presentation).
+ modify the OLE parser to be similar to the librevenge OLE parser,
ie. the librevenge parser ignores the first character of a filename if
this is a control character...
Change-Id: I913a70cba29839d43dac58d5e00dbebfc4d28abc
Diffstat (limited to 'writerperfect/source/impress')
3 files changed, 142 insertions, 0 deletions
diff --git a/writerperfect/source/impress/StarOfficePresentationImportFilter.cxx b/writerperfect/source/impress/StarOfficePresentationImportFilter.cxx new file mode 100644 index 000000000000..00fdd5b22933 --- /dev/null +++ b/writerperfect/source/impress/StarOfficePresentationImportFilter.cxx @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <cppuhelper/supportsservice.hxx> + +#include <libstaroffice/libstaroffice.hxx> +#include <libodfgen/libodfgen.hxx> + +#include "StarOfficePresentationImportFilter.hxx" + +using com::sun::star::uno::Sequence; +using com::sun::star::uno::XInterface; +using com::sun::star::uno::RuntimeException; +using com::sun::star::uno::XComponentContext; + +static bool handleEmbeddedSTOFFGraphicObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType) +{ + OdgGenerator exporter; + exporter.addDocumentHandler(pHandler, streamType); + return STOFFDocument::decodeGraphic(data, &exporter); +} + +static bool handleEmbeddedSTOFFSpreadsheetObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType) +{ + OdsGenerator exporter; + exporter.registerEmbeddedObjectHandler("image/stoff-odg", &handleEmbeddedSTOFFGraphicObject); + exporter.addDocumentHandler(pHandler, streamType); + return STOFFDocument::decodeSpreadsheet(data, &exporter); +} + +bool StarOfficePresentationImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &) +{ + return STOFFDocument::STOFF_R_OK == STOFFDocument::parse(&rInput, &rGenerator); +} + +bool StarOfficePresentationImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) +{ + rTypeName.clear(); + + STOFFDocument::Kind docKind = STOFFDocument::STOFF_K_UNKNOWN; + const STOFFDocument::Confidence confidence = STOFFDocument::isFileFormatSupported(&rInput, docKind); + + if (confidence == STOFFDocument::STOFF_C_EXCELLENT || confidence == STOFFDocument::STOFF_C_SUPPORTED_ENCRYPTION) + { + switch (docKind) + { + case STOFFDocument::STOFF_K_PRESENTATION: + rTypeName = "StarOffice_Presentation"; + break; + default: + break; + } + } + + return !rTypeName.isEmpty(); +} + +void StarOfficePresentationImportFilter::doRegisterHandlers(OdpGenerator &rGenerator) +{ + rGenerator.registerEmbeddedObjectHandler("image/stoff-odg", &handleEmbeddedSTOFFGraphicObject); + rGenerator.registerEmbeddedObjectHandler("image/stoff-ods", &handleEmbeddedSTOFFSpreadsheetObject); +} + +// XServiceInfo +OUString SAL_CALL StarOfficePresentationImportFilter::getImplementationName() +{ + return OUString("org.libreoffice.comp.Impress.StarOfficePresentationImportFilter"); +} + +sal_Bool SAL_CALL StarOfficePresentationImportFilter::supportsService(const OUString &rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence< OUString > SAL_CALL StarOfficePresentationImportFilter::getSupportedServiceNames() +{ + return Sequence< OUString > {"com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection"}; +} + +extern "C" +SAL_DLLPUBLIC_EXPORT css::uno::XInterface *SAL_CALL +org_libreoffice_comp_Presentation_StarOfficePresentationImportFilter_get_implementation( + css::uno::XComponentContext *const context, + const css::uno::Sequence<css::uno::Any> &) +{ + return cppu::acquire(new StarOfficePresentationImportFilter(context)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/impress/StarOfficePresentationImportFilter.hxx b/writerperfect/source/impress/StarOfficePresentationImportFilter.hxx new file mode 100644 index 000000000000..3651315b0e3a --- /dev/null +++ b/writerperfect/source/impress/StarOfficePresentationImportFilter.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERPERFECT_SOURCE_PRESENTATION_STAROFFICEPRESENTATIONIMPORTFILTER_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_PRESENTATION_STAROFFICEPRESENTATIONIMPORTFILTER_HXX + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include "ImportFilter.hxx" + +#include "DocumentHandlerForOdp.hxx" + +/* This component will be instantiated for both import or export. Whether it calls + * setSourceDocument or setTargetDocument determines which Impl function the filter + * member calls */ +class StarOfficePresentationImportFilter : public writerperfect::ImportFilter<OdpGenerator> +{ +public: + explicit StarOfficePresentationImportFilter(const css::uno::Reference< css::uno::XComponentContext > &rxContext) + : writerperfect::ImportFilter<OdpGenerator>(rxContext) {} + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + +private: + virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) override; + virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &) override; + virtual void doRegisterHandlers(OdpGenerator &rGenerator) override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/impress/wpftimpress.component b/writerperfect/source/impress/wpftimpress.component index 5413c9a7b4bd..0f7df39fa94e 100644 --- a/writerperfect/source/impress/wpftimpress.component +++ b/writerperfect/source/impress/wpftimpress.component @@ -19,4 +19,9 @@ <service name="com.sun.star.document.ImportFilter"/> <service name="com.sun.star.document.ExtendedTypeDetection"/> </implementation> + <implementation name="org.libreoffice.comp.Impress.StarOfficePresentationImportFilter" + constructor="org_libreoffice_comp_Presentation_StarOfficePresentationImportFilter_get_implementation"> + <service name="com.sun.star.document.ImportFilter"/> + <service name="com.sun.star.document.ExtendedTypeDetection"/> + </implementation> </component> |