From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- .../source/impress/KeynoteImportFilter.cxx | 247 +++++++++++++++++++++ .../source/impress/KeynoteImportFilter.hxx | 44 ++++ .../impress/MWAWPresentationImportFilter.cxx | 104 +++++++++ .../impress/MWAWPresentationImportFilter.hxx | 45 ++++ .../impress/StarOfficePresentationImportFilter.cxx | 102 +++++++++ .../impress/StarOfficePresentationImportFilter.hxx | 45 ++++ writerperfect/source/impress/wpftimpress.component | 27 +++ 7 files changed, 614 insertions(+) create mode 100644 writerperfect/source/impress/KeynoteImportFilter.cxx create mode 100644 writerperfect/source/impress/KeynoteImportFilter.hxx create mode 100644 writerperfect/source/impress/MWAWPresentationImportFilter.cxx create mode 100644 writerperfect/source/impress/MWAWPresentationImportFilter.hxx create mode 100644 writerperfect/source/impress/StarOfficePresentationImportFilter.cxx create mode 100644 writerperfect/source/impress/StarOfficePresentationImportFilter.hxx create mode 100644 writerperfect/source/impress/wpftimpress.component (limited to 'writerperfect/source/impress') diff --git a/writerperfect/source/impress/KeynoteImportFilter.cxx b/writerperfect/source/impress/KeynoteImportFilter.cxx new file mode 100644 index 000000000..c212c5ab8 --- /dev/null +++ b/writerperfect/source/impress/KeynoteImportFilter.cxx @@ -0,0 +1,247 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* KeynoteImportFilter: Sets up the filter, and calls OdpExporter + * to do the actual filtering + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "KeynoteImportFilter.hxx" + +using writerperfect::WPXSvInputStream; + +namespace beans = com::sun::star::beans; +namespace ucb = com::sun::star::ucb; + +bool KeynoteImportFilter::doImportDocument(weld::Window*, librevenge::RVNGInputStream& rInput, + OdpGenerator& rGenerator, utl::MediaDescriptor&) +{ + return libetonyek::EtonyekDocument::parse(&rInput, &rGenerator); +} + +bool KeynoteImportFilter::doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) +{ + if (libetonyek::EtonyekDocument::isSupported(&rInput)) + { + rTypeName = "impress_Keynote_Document"; + return true; + } + + return false; +} + +// XExtendedFilterDetection +OUString SAL_CALL +KeynoteImportFilter::detect(css::uno::Sequence& Descriptor) +{ + sal_Int32 nLength = Descriptor.getLength(); + sal_Int32 nNewLength = nLength + 2; + sal_Int32 nComponentDataLocation = -1; + sal_Int32 nTypeNameLocation = -1; + sal_Int32 nUCBContentLocation = -1; + bool bIsPackage = false; + bool bUCBContentChanged = false; + const beans::PropertyValue* pValue = Descriptor.getConstArray(); + css::uno::Reference xInputStream; + css::uno::Reference xContent; + css::uno::Sequence lComponentDataNV; + css::uno::Sequence lComponentDataPV; + bool bComponentDataNV = true; + + for (sal_Int32 i = 0; i < nLength; i++) + { + if (pValue[i].Name == "TypeName") + { + nTypeNameLocation = i; + --nNewLength; + } + if (pValue[i].Name == "ComponentData") + { + bComponentDataNV = pValue[i].Value >>= lComponentDataNV; + if (!bComponentDataNV) + pValue[i].Value >>= lComponentDataPV; + nComponentDataLocation = i; + --nNewLength; + } + else if (pValue[i].Name == "InputStream") + { + pValue[i].Value >>= xInputStream; + } + else if (pValue[i].Name == "UCBContent") + { + pValue[i].Value >>= xContent; + nUCBContentLocation = i; + } + } + + assert(nNewLength >= nLength); + + if (!xInputStream.is()) + return OUString(); + + std::unique_ptr input + = std::make_unique(xInputStream); + + /* Apple Keynote documents come in two variants: + * * actual files (zip), only produced by Keynote 5 (at least with + * default settings) + * * packages (IOW, directories), produced by Keynote 1-4 and again + * starting with 6. + * But since the libetonyek import only works with a stream, we need + * to pass it one for the whole package. Here we determine if that + * is needed. + * + * Note: for convenience, we also recognize that the main XML file + * from a package was passed and pass the whole package to the + * filter instead. + */ + if (xContent.is()) + { + ucbhelper::Content aContent(xContent, utl::UCBContentHelper::getDefaultCommandEnvironment(), + comphelper::getProcessComponentContext()); + try + { + if (aContent.isFolder()) + { + input = std::make_unique(xContent); + bIsPackage = true; + } + } + catch (...) + { + return OUString(); + } + } + + libetonyek::EtonyekDocument::Type type = libetonyek::EtonyekDocument::TYPE_UNKNOWN; + const libetonyek::EtonyekDocument::Confidence confidence + = libetonyek::EtonyekDocument::isSupported(input.get(), &type); + if ((libetonyek::EtonyekDocument::CONFIDENCE_NONE == confidence) + || (libetonyek::EtonyekDocument::TYPE_KEYNOTE != type)) + return OUString(); + + if (confidence == libetonyek::EtonyekDocument::CONFIDENCE_SUPPORTED_PART) + { + if (bIsPackage) // we passed a directory stream, but the filter claims it's APXL file? + return OUString(); + + std::unique_ptr xDir + = writerperfect::DirectoryStream::createForParent(xContent); + auto pDir = xDir.get(); + input = std::move(xDir); + if (bool(input)) + { + if (libetonyek::EtonyekDocument::CONFIDENCE_EXCELLENT + == libetonyek::EtonyekDocument::isSupported(input.get())) + { + xContent = pDir->getContent(); + bUCBContentChanged = true; + bIsPackage = true; + } + else + { + // The passed stream has been detected as APXL file, but its parent dir is not a valid Keynote + // package? Something is wrong here... + return OUString(); + } + } + } + + // we do not need to insert ComponentData if this is not a package + if (!bIsPackage && (nComponentDataLocation == -1)) + --nNewLength; + + if (nNewLength > nLength) + Descriptor.realloc(nNewLength); + + if (nTypeNameLocation == -1) + { + assert(nLength < nNewLength); + nTypeNameLocation = nLength++; + Descriptor[nTypeNameLocation].Name = "TypeName"; + } + + if (bIsPackage && (nComponentDataLocation == -1)) + { + assert(nLength < nNewLength); + nComponentDataLocation = nLength++; + Descriptor[nComponentDataLocation].Name = "ComponentData"; + } + + if (bIsPackage) + { + if (bComponentDataNV) + { + const sal_Int32 nCDSize = lComponentDataNV.getLength(); + lComponentDataNV.realloc(nCDSize + 1); + beans::NamedValue aValue; + aValue.Name = "IsPackage"; + aValue.Value <<= true; + lComponentDataNV[nCDSize] = aValue; + Descriptor[nComponentDataLocation].Value <<= lComponentDataNV; + } + else + { + const sal_Int32 nCDSize = lComponentDataPV.getLength(); + lComponentDataPV.realloc(nCDSize + 1); + beans::PropertyValue aProp; + aProp.Name = "IsPackage"; + aProp.Value <<= true; + aProp.Handle = -1; + aProp.State = beans::PropertyState_DIRECT_VALUE; + lComponentDataPV[nCDSize] = aProp; + Descriptor[nComponentDataLocation].Value <<= lComponentDataPV; + } + } + + if (bUCBContentChanged) + Descriptor[nUCBContentLocation].Value <<= xContent; + + const OUString sTypeName("impress_AppleKeynote"); + Descriptor[nTypeNameLocation].Value <<= sTypeName; + + return sTypeName; +} + +// XServiceInfo +OUString SAL_CALL KeynoteImportFilter::getImplementationName() +{ + return "org.libreoffice.comp.Impress.KeynoteImportFilter"; +} + +sal_Bool SAL_CALL KeynoteImportFilter::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +css::uno::Sequence SAL_CALL KeynoteImportFilter::getSupportedServiceNames() +{ + return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +org_libreoffice_comp_Impress_KeynoteImportFilter_get_implementation( + css::uno::XComponentContext* const context, const css::uno::Sequence&) +{ + return cppu::acquire(new KeynoteImportFilter(context)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/impress/KeynoteImportFilter.hxx b/writerperfect/source/impress/KeynoteImportFilter.hxx new file mode 100644 index 000000000..1ae6002a5 --- /dev/null +++ b/writerperfect/source/impress/KeynoteImportFilter.hxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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_IMPRESS_KEYNOTEIMPORTFILTER_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_IMPRESS_KEYNOTEIMPORTFILTER_HXX + +#include + +#include +#include + +/* 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 KeynoteImportFilter : public writerperfect::ImportFilter +{ +public: + explicit KeynoteImportFilter(const css::uno::Reference& rxContext) + : writerperfect::ImportFilter(rxContext) + { + } + + //XExtendedFilterDetection + virtual OUString SAL_CALL + detect(css::uno::Sequence& Descriptor) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence SAL_CALL getSupportedServiceNames() override; + +private: + virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) override; + virtual bool doImportDocument(weld::Window* pParent, librevenge::RVNGInputStream& rInput, + OdpGenerator& rGenerator, utl::MediaDescriptor&) override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/impress/MWAWPresentationImportFilter.cxx b/writerperfect/source/impress/MWAWPresentationImportFilter.cxx new file mode 100644 index 000000000..c5de6984a --- /dev/null +++ b/writerperfect/source/impress/MWAWPresentationImportFilter.cxx @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* MWAWPresentationImportFilter: Sets up the filter, and calls DocumentCollector + * to do the actual filtering + * + * 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 + +#include + +#include "MWAWPresentationImportFilter.hxx" + +static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData& data, + OdfDocumentHandler* pHandler, + const OdfStreamType streamType) +{ + OdgGenerator exporter; + exporter.addDocumentHandler(pHandler, streamType); + return MWAWDocument::decodeGraphic(data, &exporter); +} + +static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData& data, + OdfDocumentHandler* pHandler, + const OdfStreamType streamType) +{ + OdsGenerator exporter; + exporter.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject); + exporter.addDocumentHandler(pHandler, streamType); + return MWAWDocument::decodeSpreadsheet(data, &exporter); +} + +bool MWAWPresentationImportFilter::doImportDocument(weld::Window*, + librevenge::RVNGInputStream& rInput, + OdpGenerator& rGenerator, utl::MediaDescriptor&) +{ + return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator); +} + +bool MWAWPresentationImportFilter::doDetectFormat(librevenge::RVNGInputStream& rInput, + OUString& rTypeName) +{ + rTypeName.clear(); + + MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN; + MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN; + const MWAWDocument::Confidence confidence + = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind); + + if (confidence == MWAWDocument::MWAW_C_EXCELLENT) + { + if (docKind == MWAWDocument::MWAW_K_PRESENTATION) + { + switch (docType) + { + case MWAWDocument::MWAW_T_CLARISWORKS: + rTypeName = "impress_ClarisWorks"; + break; + case MWAWDocument::MWAW_T_RESERVED8: + rTypeName = "impress_PowerPoint3"; + break; + default: + rTypeName = "MWAW_Presentation"; + break; + } + } + } + + return !rTypeName.isEmpty(); +} + +void MWAWPresentationImportFilter::doRegisterHandlers(OdpGenerator& rGenerator) +{ + rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject); + rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods", + &handleEmbeddedMWAWSpreadsheetObject); +} + +// XServiceInfo +OUString SAL_CALL MWAWPresentationImportFilter::getImplementationName() +{ + return "com.sun.star.comp.Impress.MWAWPresentationImportFilter"; +} +sal_Bool SAL_CALL MWAWPresentationImportFilter::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} +css::uno::Sequence SAL_CALL MWAWPresentationImportFilter::getSupportedServiceNames() +{ + return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_comp_Impress_MWAWPresentationImportFilter_get_implementation( + css::uno::XComponentContext* const context, const css::uno::Sequence&) +{ + return cppu::acquire(new MWAWPresentationImportFilter(context)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/impress/MWAWPresentationImportFilter.hxx b/writerperfect/source/impress/MWAWPresentationImportFilter.hxx new file mode 100644 index 000000000..4bb1afb55 --- /dev/null +++ b/writerperfect/source/impress/MWAWPresentationImportFilter.hxx @@ -0,0 +1,45 @@ +/* -*- 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_IMPRESS_MWAWPRESENTATIONIMPORTFILTER_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_IMPRESS_MWAWPRESENTATIONIMPORTFILTER_HXX + +#include + +#include + +#include + +/* 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 MWAWPresentationImportFilter : public writerperfect::ImportFilter +{ +public: + explicit MWAWPresentationImportFilter( + const css::uno::Reference& rxContext) + : writerperfect::ImportFilter(rxContext) + { + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence SAL_CALL getSupportedServiceNames() override; + +private: + virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) override; + virtual bool doImportDocument(weld::Window* pParent, 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/StarOfficePresentationImportFilter.cxx b/writerperfect/source/impress/StarOfficePresentationImportFilter.cxx new file mode 100644 index 000000000..4f60f57e3 --- /dev/null +++ b/writerperfect/source/impress/StarOfficePresentationImportFilter.cxx @@ -0,0 +1,102 @@ +/* -*- 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 + +#include + +#include "StarOfficePresentationImportFilter.hxx" + +using com::sun::star::uno::Sequence; +using com::sun::star::uno::XComponentContext; +using com::sun::star::uno::XInterface; + +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(weld::Window*, + 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 "org.libreoffice.comp.Impress.StarOfficePresentationImportFilter"; +} + +sal_Bool SAL_CALL StarOfficePresentationImportFilter::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence SAL_CALL StarOfficePresentationImportFilter::getSupportedServiceNames() +{ + return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +org_libreoffice_comp_Presentation_StarOfficePresentationImportFilter_get_implementation( + css::uno::XComponentContext* const context, const css::uno::Sequence&) +{ + 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 000000000..7a5e6103a --- /dev/null +++ b/writerperfect/source/impress/StarOfficePresentationImportFilter.hxx @@ -0,0 +1,45 @@ +/* -*- 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 + +#include + +#include + +/* 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 +{ +public: + explicit StarOfficePresentationImportFilter( + const css::uno::Reference& rxContext) + : writerperfect::ImportFilter(rxContext) + { + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence SAL_CALL getSupportedServiceNames() override; + +private: + virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) override; + virtual bool doImportDocument(weld::Window* pParent, 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 new file mode 100644 index 000000000..0f7df39fa --- /dev/null +++ b/writerperfect/source/impress/wpftimpress.component @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + -- cgit v1.2.3