From 412975713b4838582f635ac9e61a8a8e720ff09c Mon Sep 17 00:00:00 2001 From: David Tardon Date: Wed, 30 Oct 2013 08:56:06 +0100 Subject: integrate Apple Keynote import filter Change-Id: Icc36b761da9262a99af730cfe71f576bcaab3ee1 Reviewed-on: https://gerrit.libreoffice.org/6488 Tested-by: LibreOffice gerrit bot Reviewed-by: David Tardon Tested-by: David Tardon --- Repository.mk | 1 + filter/Configuration_filter.mk | 2 + .../config/fragments/filters/AppleKeynote.xcu | 29 +++ .../fragments/types/impress_AppleKeynote.xcu | 29 +++ postprocess/Rdb_services.mk | 1 + writerperfect/Library_wpftimpress.mk | 61 ++++++ writerperfect/Module_writerperfect.mk | 4 + .../source/impress/KeynoteImportFilter.cxx | 221 +++++++++++++++++++++ .../source/impress/KeynoteImportFilter.hxx | 89 +++++++++ writerperfect/source/impress/wpftimpress.component | 16 ++ .../source/impress/wpftimpress_genericfilter.cxx | 47 +++++ 11 files changed, 500 insertions(+) create mode 100644 filter/source/config/fragments/filters/AppleKeynote.xcu create mode 100644 filter/source/config/fragments/types/impress_AppleKeynote.xcu create mode 100644 writerperfect/Library_wpftimpress.mk create mode 100644 writerperfect/source/impress/KeynoteImportFilter.cxx create mode 100644 writerperfect/source/impress/KeynoteImportFilter.hxx create mode 100644 writerperfect/source/impress/wpftimpress.component create mode 100644 writerperfect/source/impress/wpftimpress_genericfilter.cxx diff --git a/Repository.mk b/Repository.mk index c957433b23bc..b3e21fe74fd1 100644 --- a/Repository.mk +++ b/Repository.mk @@ -180,6 +180,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,impress, \ placeware \ PresenterScreen \ PresentationMinimizer \ + wpftimpress \ )) $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,onlineupdate, \ diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk index 645768e84fb3..62f21b6cbc14 100644 --- a/filter/Configuration_filter.mk +++ b/filter/Configuration_filter.mk @@ -581,6 +581,7 @@ $(call filter_Configuration_add_ui_filters,fcfg_langpack,filter/source/config/fr # fcfg_impress $(call filter_Configuration_add_types,fcfg_langpack,fcfg_impress_types.xcu,filter/source/config/fragments/types,\ draw_StarOffice_XML_Draw \ + impress_AppleKeynote \ impress_MS_PowerPoint_97 \ impress_MS_PowerPoint_97_AutoPlay \ impress_MS_PowerPoint_97_Vorlage \ @@ -600,6 +601,7 @@ $(call filter_Configuration_add_types,fcfg_langpack,fcfg_impress_types.xcu,filte ) $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_impress_filters.xcu,filter/source/config/fragments/filters,\ + AppleKeynote \ MS_PowerPoint_97 \ MS_PowerPoint_97_AutoPlay \ MS_PowerPoint_97_Vorlage \ diff --git a/filter/source/config/fragments/filters/AppleKeynote.xcu b/filter/source/config/fragments/filters/AppleKeynote.xcu new file mode 100644 index 000000000000..84deba44fa49 --- /dev/null +++ b/filter/source/config/fragments/filters/AppleKeynote.xcu @@ -0,0 +1,29 @@ + + + + + IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED + + + org.libreoffice.comp.Impress.KeynoteImportFilter + + + Apple Keynote 5 + + + 0 + + + impress_AppleKeynote + + + com.sun.star.presentation.PresentationDocument + + diff --git a/filter/source/config/fragments/types/impress_AppleKeynote.xcu b/filter/source/config/fragments/types/impress_AppleKeynote.xcu new file mode 100644 index 000000000000..797df7ae0a45 --- /dev/null +++ b/filter/source/config/fragments/types/impress_AppleKeynote.xcu @@ -0,0 +1,29 @@ + + + + + org.libreoffice.comp.Impress.KeynoteImportFilter + + + key + + + application/x-iwork-keynote-sffkey + + + true + + + Apple Keynote + + + Apple Keynote + + diff --git a/postprocess/Rdb_services.mk b/postprocess/Rdb_services.mk index 0f28e03d4d22..06d90e3ec7f9 100644 --- a/postprocess/Rdb_services.mk +++ b/postprocess/Rdb_services.mk @@ -118,6 +118,7 @@ $(eval $(call gb_Rdb_add_components,services,\ writerfilter/util/writerfilter \ writerperfect/util/wpftwriter \ writerperfect/util/wpftdraw \ + writerperfect/source/impress/wpftimpress \ $(if $(filter MACOSX,$(OS)), \ $(if $(filter-out X86_64,$(CPUNAME)), \ avmedia/source/quicktime/avmediaQuickTime \ diff --git a/writerperfect/Library_wpftimpress.mk b/writerperfect/Library_wpftimpress.mk new file mode 100644 index 000000000000..cb69f98ca7a7 --- /dev/null +++ b/writerperfect/Library_wpftimpress.mk @@ -0,0 +1,61 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +$(eval $(call gb_Library_Library,wpftimpress)) + +$(eval $(call gb_Library_set_componentfile,wpftimpress,writerperfect/source/impress/wpftimpress)) + +$(eval $(call gb_Library_set_include,wpftimpress,\ + $$(INCLUDE) \ + -I$(SRCDIR)/writerperfect/source \ +)) + +$(eval $(call gb_Library_use_sdk_api,wpftimpress)) + +$(eval $(call gb_Library_use_libraries,wpftimpress,\ + comphelper \ + cppu \ + cppuhelper \ + sal \ + sot \ + tl \ + utl \ + xo \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_Library_use_static_libraries,wpftimpress,\ + writerperfect \ +)) + +$(eval $(call gb_Library_use_externals,wpftimpress,\ + etonyek \ + odfgen \ + wpd \ + wpg \ + zlib \ + libxml2 \ +)) + +$(eval $(call gb_Library_add_exception_objects,wpftimpress,\ + writerperfect/source/impress/KeynoteImportFilter \ + writerperfect/source/impress/wpftimpress_genericfilter \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk index fee590dc5344..8f02300ce3ff 100644 --- a/writerperfect/Module_writerperfect.mk +++ b/writerperfect/Module_writerperfect.mk @@ -45,6 +45,10 @@ endif endif endif +$(eval $(call gb_Module_add_targets,writerperfect,\ + Library_wpftimpress \ +)) + ifneq (,$(SYSTEM_WPD)) ifneq (,$(SYSTEM_WPG)) ifneq (,$(SYSTEM_ODFGEN)) diff --git a/writerperfect/source/impress/KeynoteImportFilter.cxx b/writerperfect/source/impress/KeynoteImportFilter.cxx new file mode 100644 index 000000000000..0035d5df7a29 --- /dev/null +++ b/writerperfect/source/impress/KeynoteImportFilter.cxx @@ -0,0 +1,221 @@ +/* -*- 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 "common/DocumentHandler.hxx" +#include "common/WPXSvStream.hxx" +#include "KeynoteImportFilter.hxx" + +#include + +using namespace ::com::sun::star::uno; +using com::sun::star::uno::Reference; +using com::sun::star::io::XInputStream; +using com::sun::star::io::XSeekable; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::Any; +using com::sun::star::uno::UNO_QUERY; +using com::sun::star::uno::XInterface; +using com::sun::star::uno::Exception; +using com::sun::star::uno::RuntimeException; +using com::sun::star::beans::PropertyValue; +using com::sun::star::document::XFilter; +using com::sun::star::document::XExtendedFilterDetection; +using com::sun::star::document::XImporter; +using com::sun::star::xml::sax::InputSource; +using com::sun::star::xml::sax::XAttributeList; +using com::sun::star::xml::sax::XDocumentHandler; +using com::sun::star::xml::sax::XParser; + + +sal_Bool SAL_CALL KeynoteImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) +throw (RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter::filter"); + sal_Int32 nLength = aDescriptor.getLength(); + const PropertyValue *pValue = aDescriptor.getConstArray(); + Reference < XInputStream > xInputStream; + for ( sal_Int32 i = 0 ; i < nLength; i++) + { + if ( pValue[i].Name == "InputStream" ) + pValue[i].Value >>= xInputStream; + } + if ( !xInputStream.is() ) + { + OSL_ASSERT( 0 ); + return sal_False; + } + + // An XML import service: what we push sax messages to.. + Reference < XDocumentHandler > xInternalHandler( + mxContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.comp.Draw.XMLOasisImporter", mxContext), + css::uno::UNO_QUERY_THROW); + + // The XImporter sets up an empty target document for XDocumentHandler to write to.. + Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY); + xImporter->setTargetDocument( mxDoc ); + + // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here + // writes to in-memory target doc + DocumentHandler xHandler(xInternalHandler); + + WPXSvInputStream input( xInputStream ); + + OdpGenerator exporter(&xHandler, ODF_FLAT_XML); + bool tmpParseResult = libetonyek::KEYDocument::parse(&input, &exporter); + return tmpParseResult; +} + +void SAL_CALL KeynoteImportFilter::cancel( ) +throw (RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter::cancel"); +} + +// XImporter +void SAL_CALL KeynoteImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) +throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter::setTargetDocument"); + mxDoc = xDoc; +} + +// XExtendedFilterDetection +OUString SAL_CALL KeynoteImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) +throw( com::sun::star::uno::RuntimeException ) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter::detect"); + OUString sTypeName; + sal_Int32 nLength = Descriptor.getLength(); + sal_Int32 location = nLength; + const PropertyValue *pValue = Descriptor.getConstArray(); + Reference < XInputStream > xInputStream; + for ( sal_Int32 i = 0 ; i < nLength; i++) + { + if ( pValue[i].Name == "TypeName" ) + location=i; + else if ( pValue[i].Name == "InputStream" ) + pValue[i].Value >>= xInputStream; + } + + if (!xInputStream.is()) + return OUString(); + + WPXSvInputStream input( xInputStream ); + + if (libetonyek::KEYDocument::isSupported(&input)) + sTypeName = "impress_AppleKeynote"; + + if (!sTypeName.isEmpty()) + { + if ( location == nLength ) + { + Descriptor.realloc(nLength+1); + Descriptor[location].Name = "TypeName"; + } + + Descriptor[location].Value <<=sTypeName; + } + return sTypeName; +} + + +// XInitialization +void SAL_CALL KeynoteImportFilter::initialize( const Sequence< Any >& aArguments ) +throw (Exception, RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter::initialize"); + Sequence < PropertyValue > aAnySeq; + sal_Int32 nLength = aArguments.getLength(); + if ( nLength && ( aArguments[0] >>= aAnySeq ) ) + { + const PropertyValue *pValue = aAnySeq.getConstArray(); + nLength = aAnySeq.getLength(); + for ( sal_Int32 i = 0 ; i < nLength; i++) + { + if ( pValue[i].Name == "Type" ) + { + pValue[i].Value >>= msFilterName; + break; + } + } + } +} +OUString KeynoteImportFilter_getImplementationName () +throw (RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter_getImplementationName"); + return OUString ( "org.libreoffice.comp.Impress.KeynoteImportFilter" ); +} + +#define SERVICE_NAME1 "com.sun.star.document.ImportFilter" +#define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection" +sal_Bool SAL_CALL KeynoteImportFilter_supportsService( const OUString &ServiceName ) +throw (RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter_supportsService"); + return ( ServiceName == SERVICE_NAME1 || ServiceName == SERVICE_NAME2 ); +} +Sequence< OUString > SAL_CALL KeynoteImportFilter_getSupportedServiceNames( ) +throw (RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter_getSupportedServiceNames"); + Sequence < OUString > aRet(2); + OUString *pArray = aRet.getArray(); + pArray[0] = OUString ( SERVICE_NAME1 ); + pArray[1] = OUString ( SERVICE_NAME2 ); + return aRet; +} +#undef SERVICE_NAME2 +#undef SERVICE_NAME1 + +Reference< XInterface > SAL_CALL KeynoteImportFilter_createInstance( const Reference< XComponentContext > & rContext) +throw( Exception ) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter_createInstance"); + return (cppu::OWeakObject *) new KeynoteImportFilter( rContext ); +} + +// XServiceInfo +OUString SAL_CALL KeynoteImportFilter::getImplementationName( ) +throw (RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter::getImplementationName"); + return KeynoteImportFilter_getImplementationName(); +} +sal_Bool SAL_CALL KeynoteImportFilter::supportsService( const OUString &rServiceName ) +throw (RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter::supportsService"); + return KeynoteImportFilter_supportsService( rServiceName ); +} +Sequence< OUString > SAL_CALL KeynoteImportFilter::getSupportedServiceNames( ) +throw (RuntimeException) +{ + SAL_INFO("writerperfect", "KeynoteImportFilter::getSupportedServiceNames"); + return KeynoteImportFilter_getSupportedServiceNames(); +} + +/* 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 000000000000..05d235b71af9 --- /dev/null +++ b/writerperfect/source/impress/KeynoteImportFilter.hxx @@ -0,0 +1,89 @@ +/* -*- 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 +#include +#include +#include +#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 cppu::WeakImplHelper5 + < + com::sun::star::document::XFilter, + com::sun::star::document::XImporter, + com::sun::star::document::XExtendedFilterDetection, + com::sun::star::lang::XInitialization, + com::sun::star::lang::XServiceInfo + > +{ +protected: + // oo.org declares + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc; + OUString msFilterName; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > mxHandler; + +public: + KeynoteImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) + : mxContext( rxContext ) {} + virtual ~KeynoteImportFilter() {} + + // XFilter + virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL cancel( ) + throw (::com::sun::star::uno::RuntimeException); + + // XImporter + virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + //XExtendedFilterDetection + virtual OUString SAL_CALL detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor ) + throw( com::sun::star::uno::RuntimeException ); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString &ServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) + throw (::com::sun::star::uno::RuntimeException); + +}; + +OUString KeynoteImportFilter_getImplementationName() +throw ( ::com::sun::star::uno::RuntimeException ); + +sal_Bool SAL_CALL KeynoteImportFilter_supportsService( const OUString &ServiceName ) +throw ( ::com::sun::star::uno::RuntimeException ); + +::com::sun::star::uno::Sequence< OUString > SAL_CALL KeynoteImportFilter_getSupportedServiceNames( ) +throw ( ::com::sun::star::uno::RuntimeException ); + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > +SAL_CALL KeynoteImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rContext) +throw ( ::com::sun::star::uno::Exception ); + +#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 000000000000..b7b87c56a264 --- /dev/null +++ b/writerperfect/source/impress/wpftimpress.component @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/writerperfect/source/impress/wpftimpress_genericfilter.cxx b/writerperfect/source/impress/wpftimpress_genericfilter.cxx new file mode 100644 index 000000000000..4081137cdf03 --- /dev/null +++ b/writerperfect/source/impress/wpftimpress_genericfilter.cxx @@ -0,0 +1,47 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* genericfilter: mostly generic code for registering the filter */ + +#include "sal/config.h" + +#include "cppuhelper/factory.hxx" +#include "cppuhelper/implementationentry.hxx" +#include "sal/types.h" + +#include "KeynoteImportFilter.hxx" + +namespace { + +static cppu::ImplementationEntry const services[] = { + { &KeynoteImportFilter_createInstance, &KeynoteImportFilter_getImplementationName, + &KeynoteImportFilter_getSupportedServiceNames, + &cppu::createSingleComponentFactory, 0, 0 }, + { 0, 0, 0, 0, 0, 0 } }; + +} + +extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL wpftimpress_component_getFactory( + char const * pImplName, void * pServiceManager, void * pRegistryKey) +{ + return cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, services); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit