Kaydet (Commit) 8988c925 authored tarafından osnola's avatar osnola Kaydeden (comit) David Tardon

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
üst b0067c89
......@@ -600,6 +600,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_impress_types.xc
impress_OOXML_Presentation_Template \
impress_OOXML_Presentation_AutoPlay \
impress_ClarisWorks \
StarOffice_Presentation \
MWAW_Presentation \
impress_PowerPoint3 \
))
......@@ -625,6 +626,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_impress_filter
impress_OOXML_Template \
impress_OOXML_AutoPlay \
ClarisWorks_Impress \
StarOffice_Presentation \
MWAW_Presentation \
PowerPoint3 \
))
......
<!--
* 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/.
*
-->
<node oor:name="StarOffice_Presentation" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
</prop>
<prop oor:name="FilterService">
<value>org.libreoffice.comp.Impress.StarOfficePresentationImportFilter</value>
</prop>
<prop oor:name="UIName">
<value xml:lang="en-US">Legacy StarOffice Presentation</value>
</prop>
<prop oor:name="FileFormatVersion">
<value>0</value>
</prop>
<prop oor:name="Type">
<value>StarOffice_Presentation</value>
</prop>
<prop oor:name="DocumentService">
<value>com.sun.star.presentation.PresentationDocument</value>
</prop>
</node>
<!--
* 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/.
*
-->
<node oor:name="StarOffice_Presentation" oor:op="replace">
<prop oor:name="DetectService">
<value>org.libreoffice.comp.Impress.StarOfficePresentationImportFilter</value>
</prop>
<prop oor:name="Extensions">
<value>sdd</value>
</prop>
<prop oor:name="MediaType"/>
<prop oor:name="Preferred">
<value>true</value>
</prop>
<prop oor:name="PreferredFilter">
<value>StarOffice_Presentation</value>
</prop>
<prop oor:name="UIName">
<value>Legacy StarOffice Presentation</value>
</prop>
</node>
......@@ -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:
......@@ -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);
......
/* -*- 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: */
/* -*- 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: */
......@@ -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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment