summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorosnola <alonso@loria.fr>2017-04-02 09:53:44 +0200
committerDavid Tardon <dtardon@redhat.com>2017-04-02 13:42:20 +0200
commit8988c925ce07395478fbbb10d25fd6c0a10fead5 (patch)
tree4770a03c18e2db296681297b4ef77322aa3dd522 /writerperfect
parentb0067c89e6b2a4e29465d9da9a731ae30a66dce6 (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')
-rw-r--r--writerperfect/Library_wpftimpress.mk2
-rw-r--r--writerperfect/source/common/WPXSvInputStream.cxx24
-rw-r--r--writerperfect/source/impress/StarOfficePresentationImportFilter.cxx95
-rw-r--r--writerperfect/source/impress/StarOfficePresentationImportFilter.hxx42
-rw-r--r--writerperfect/source/impress/wpftimpress.component5
5 files changed, 162 insertions, 6 deletions
diff --git a/writerperfect/Library_wpftimpress.mk b/writerperfect/Library_wpftimpress.mk
index 116b72a1235a..18c8afa110bc 100644
--- a/writerperfect/Library_wpftimpress.mk
+++ b/writerperfect/Library_wpftimpress.mk
@@ -49,6 +49,7 @@ $(eval $(call gb_Library_use_externals,wpftimpress,\
etonyek \
mwaw \
odfgen \
+ staroffice \
revenge \
zlib \
libxml2 \
@@ -57,6 +58,7 @@ $(eval $(call gb_Library_use_externals,wpftimpress,\
$(eval $(call gb_Library_add_exception_objects,wpftimpress,\
writerperfect/source/impress/KeynoteImportFilter \
writerperfect/source/impress/MWAWPresentationImportFilter \
+ writerperfect/source/impress/StarOfficePresentationImportFilter \
))
# vim: set noet sw=4 ts=4:
diff --git a/writerperfect/source/common/WPXSvInputStream.cxx b/writerperfect/source/common/WPXSvInputStream.cxx
index 4c4998cbaca7..4137cd6f5425 100644
--- a/writerperfect/source/common/WPXSvInputStream.cxx
+++ b/writerperfect/source/common/WPXSvInputStream.cxx
@@ -105,7 +105,7 @@ const rtl::OUString concatPath(const rtl::OUString &lhs, const rtl::OUString &rh
struct OLEStreamData
{
- explicit OLEStreamData(const rtl::OString &rName);
+ OLEStreamData(const rtl::OString &rName, const rtl::OString &rvngName);
SotStorageStreamRefWrapper stream;
@@ -115,6 +115,12 @@ struct OLEStreamData
* produce const char* from it.
*/
rtl::OString name;
+ /** librevenge name of the stream.
+ *
+ * This is not @c rtl::OUString, because we need to be able to
+ * produce const char* from it.
+ */
+ rtl::OString RVNGname;
};
typedef std::unordered_map<rtl::OUString, std::size_t, rtl::OUStringHash> NameMap_t;
@@ -158,9 +164,10 @@ public:
bool mbInitialized;
};
-OLEStreamData::OLEStreamData(const rtl::OString &rName)
+OLEStreamData::OLEStreamData(const rtl::OString &rName, const rtl::OString &rvngName)
: stream()
, name(rName)
+ , RVNGname(rvngName)
{
}
@@ -197,7 +204,7 @@ tools::SvRef<SotStorageStream> OLEStorageImpl::getStream(const rtl::OUString &rP
return tools::SvRef<SotStorageStream>();
if (!maStreams[aIt->second].stream.ref.is())
- maStreams[aIt->second].stream.ref = createStream(aPath);
+ maStreams[aIt->second].stream.ref = createStream(rtl::OStringToOUString(maStreams[aIt->second].name, RTL_TEXTENCODING_UTF8));
return maStreams[aIt->second].stream.ref;
}
@@ -220,8 +227,13 @@ void OLEStorageImpl::traverse(const tools::SvRef<SotStorage> &rStorage, const rt
{
if (aIt->IsStream())
{
- maStreams.push_back(OLEStreamData(rtl::OUStringToOString(concatPath(rPath, aIt->GetName()), RTL_TEXTENCODING_UTF8)));
- maNameMap[concatPath(rPath, aIt->GetName())] = maStreams.size() - 1;
+ rtl::OUString baseName=aIt->GetName(), rvngName=baseName;
+ // librevenge::RVNGOLEStream ignores the first character when is a control code, so ...
+ if (!rvngName.isEmpty() && rvngName.toChar()<32)
+ rvngName=rvngName.copy(1);
+ maStreams.push_back(OLEStreamData(rtl::OUStringToOString(concatPath(rPath, baseName), RTL_TEXTENCODING_UTF8),
+ rtl::OUStringToOString(concatPath(rPath, rvngName), RTL_TEXTENCODING_UTF8)));
+ maNameMap[concatPath(rPath, rvngName)] = maStreams.size() - 1;
}
else if (aIt->IsStorage())
{
@@ -590,7 +602,7 @@ const char *WPXSvInputStreamImpl::subStreamName(const unsigned id)
if (mpOLEStorage->maStreams.size() <= id)
return nullptr;
- return mpOLEStorage->maStreams[id].name.getStr();
+ return mpOLEStorage->maStreams[id].RVNGname.getStr();
}
mxSeekable->seek(0);
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>