[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - embeddedobj/source include/oox oox/source sd/CppunitTest_sd_import_tests.mk sd/qa

Zolnai Tamás tamas.zolnai at collabora.com
Mon Jan 5 03:29:34 PST 2015


 embeddedobj/source/msole/oleembed.cxx |   11 +++
 include/oox/export/shapes.hxx         |    2 
 oox/source/export/shapes.cxx          |  114 +++++++++++++++++++++++++---------
 sd/CppunitTest_sd_import_tests.mk     |   41 ------------
 sd/qa/unit/data/odp/bnc822341.odp     |binary
 sd/qa/unit/import-tests.cxx           |   46 +++++++++++++
 6 files changed, 145 insertions(+), 69 deletions(-)

New commits:
commit 2f7a4c04c0531a74b92546a7b8808d03a51ecd99
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Tue Dec 23 10:51:05 2014 +0100

    bnc#822341: PPTX export of embedded text documents
    
    -Make embedded text documents exported by analogy with spreadsheet
    embedded documents.
    -Convert MS ole objects to LO sepcific objecst to allow
    exporting those ole objects too.
    
    Plus use gb_CppunitTest_use_rdb instead of wasting time on
    finding out which missing components cause test failing.
    Especcially when we have platform dependent components
    (e.g. related to embedded object)
    
    (cherry picked from commit 0c3d5fb0ad35ff7fc18917fc86fa58d9312fe3ae)
    
    Conflicts:
    	sd/CppunitTest_sd_export_tests.mk
    	sd/qa/unit/export-tests.cxx
    
    
    ERROR: Attribute 'spid' must appear on element 'p:oleObj'.
    
    As pointed out by CppunitTest_sd_export_tests.
    
    (cherry picked from commit 124c33dd1d6bf2040f0153de8c9ecaebe759c3bd)
    
    ERROR: Invalid content was found starting with element 'p:pic'.
    
    Again, as pointed out by CppunitTest_sd_export_tests. Sadly it seems that the
    spec and PowerPoint is not in sync here, so just do what makes both happy. This
    fixes the --with-export-validation build.
    
    (cherry picked from commit cf15306ccf49da290b391517e2c5dd22a4f1be45)
    
    Change-Id: Ic76d659b51274777a1669c215344a1169ebcba81
    Reviewed-on: https://gerrit.libreoffice.org/13601
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/embeddedobj/source/msole/oleembed.cxx b/embeddedobj/source/msole/oleembed.cxx
index 0527900..abe4a24 100644
--- a/embeddedobj/source/msole/oleembed.cxx
+++ b/embeddedobj/source/msole/oleembed.cxx
@@ -587,6 +587,17 @@ void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 nNewState )
         }
     }
     else
+#else
+    // if it is possible, the object will be converted to OOo format
+    if ( !m_bTriedConversion )
+    {
+        m_bTriedConversion = true;
+        if ( TryToConvertToOOo() )
+        {
+            changeState( nNewState );
+            return;
+        }
+    }
 #endif
     {
         throw embed::UnreachableStateException();
diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx
index c7f8d15..bfc0cab 100644
--- a/include/oox/export/shapes.hxx
+++ b/include/oox/export/shapes.hxx
@@ -42,7 +42,7 @@ namespace oox { namespace drawingml {
 class OOX_DLLPUBLIC ShapeExport : public DrawingML {
 
 private:
-    static int mnSpreadsheetCounter;
+    static int mnEmbeddeDocumentCounter;
     struct ShapeCheck
     {
         bool operator()( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape> s1, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape> s2 ) const
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 82d2b5e..0b5a8ef 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -52,6 +52,7 @@
 #include <com/sun/star/text/XSimpleText.hpp>
 #include <com/sun/star/text/XText.hpp>
 #include <com/sun/star/text/XTextContent.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
 #include <com/sun/star/text/XTextField.hpp>
 #include <com/sun/star/text/XTextRange.hpp>
 #include <com/sun/star/table/XTable.hpp>
@@ -121,7 +122,7 @@ namespace oox { namespace drawingml {
         mAny >>= variable;
 
 // not thread safe
-int ShapeExport::mnSpreadsheetCounter = 1;
+int ShapeExport::mnEmbeddeDocumentCounter = 1;
 
 ShapeExport::ShapeExport( sal_Int32 nXmlNamespace, FSHelperPtr pFS, ShapeHashMap* pShapeMap, XmlFilterBase* pFB, DocumentType eDocumentType, DMLTextExport* pTextExport )
     : DrawingML( pFS, pFB, eDocumentType, pTextExport )
@@ -978,47 +979,90 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
             }
             else
             {
-                // this part now supports only embedded spreadsheets, it can be extended to support remaining ooxml documents
-                // only exporter, counter and object filename are specific to spreadsheet
-                Reference< XSpreadsheetDocument > xSheetDoc( mAny, UNO_QUERY );
-                if( xSheetDoc.is() && mpFB)
+                const bool bSpreadSheet = Reference< XSpreadsheetDocument >( mAny, UNO_QUERY ).is();
+                const bool bTextDocument = Reference< css::text::XTextDocument >( mAny, UNO_QUERY ).is();
+                if( ( bSpreadSheet || bTextDocument ) && mpFB)
                 {
                     Reference< XComponent > xDocument( mAny, UNO_QUERY );
                     if( xDocument.is() )
                     {
-                        Reference< XOutputStream > xOutStream = mpFB->openFragmentStream( OUStringBuffer()
-                                                                                          .appendAscii( GetComponentDir() )
-                                                                                          .appendAscii( "/embeddings/spreadsheet" )
-                                                                                          .append( (sal_Int32) mnSpreadsheetCounter )
-                                                                                          .appendAscii( ".xlsx" )
-                                                                                          .makeStringAndClear(),
-                                                                                          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" );
+                        Reference< XOutputStream > xOutStream;
+                        if( bSpreadSheet )
+                        {
+                            xOutStream = mpFB->openFragmentStream( OUStringBuffer()
+                                                                   .appendAscii( GetComponentDir() )
+                                                                   .appendAscii( "/embeddings/spreadsheet" )
+                                                                   .append( static_cast<sal_Int32>(mnEmbeddeDocumentCounter) )
+                                                                   .appendAscii( ".xlsx" )
+                                                                   .makeStringAndClear(),
+                                                                   "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" );
+                        }
+                        else
+                        {
+                            xOutStream = mpFB->openFragmentStream( OUStringBuffer()
+                                                                   .appendAscii( GetComponentDir() )
+                                                                   .appendAscii( "/embeddings/textdocument" )
+                                                                   .append( static_cast<sal_Int32>(mnEmbeddeDocumentCounter) )
+                                                                   .appendAscii( ".docx" )
+                                                                   .makeStringAndClear(),
+                                                                   "application/vnd.openxmlformats-officedocument.wordprocessingml.document" );
+                        }
+
                         // export the embedded document
                         Sequence< PropertyValue > rMedia(1);
 
                         rMedia[0].Name = utl::MediaDescriptor::PROP_STREAMFOROUTPUT();
                         rMedia[0].Value <<= xOutStream;
 
-                        Reference< XExporter > xExporter(
-                            mpFB->getComponentContext()->getServiceManager()->
-                                createInstanceWithContext(
-                                    "com.sun.star.comp.oox.xls.ExcelFilter",
-                                    mpFB->getComponentContext() ),
-                            UNO_QUERY_THROW );
+                        Reference< XExporter > xExporter;
+                        if( bSpreadSheet )
+                        {
+                            xExporter.set(
+                                mpFB->getComponentContext()->getServiceManager()->
+                                    createInstanceWithContext(
+                                        "com.sun.star.comp.oox.xls.ExcelFilter",
+                                        mpFB->getComponentContext() ),
+                                UNO_QUERY_THROW );
+                        }
+                        else
+                        {
+                            xExporter.set(
+                                mpFB->getComponentContext()->getServiceManager()->
+                                    createInstanceWithContext(
+                                        "com.sun.star.comp.Writer.WriterFilter",
+                                        mpFB->getComponentContext() ),
+                                UNO_QUERY_THROW );
+
+                        }
                         xExporter->setSourceDocument( xDocument );
                         Reference< XFilter >( xExporter, UNO_QUERY_THROW )->
                             filter( rMedia );
 
                         xOutStream->closeOutput();
 
-                        OUString sRelId = mpFB->addRelation( mpFS->getOutputStream(),
-                                                             "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
-                                                             OUStringBuffer()
-                                                             .appendAscii( GetRelationCompPrefix() )
-                                                             .appendAscii( "embeddings/spreadsheet" )
-                                                             .append( (sal_Int32) mnSpreadsheetCounter ++ )
-                                                             .appendAscii( ".xlsx" )
-                                                             .makeStringAndClear() );
+                        OUString sRelId;
+                        if( bSpreadSheet )
+                        {
+                            sRelId = mpFB->addRelation( mpFS->getOutputStream(),
+                                                        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
+                                                        OUStringBuffer()
+                                                        .appendAscii( GetRelationCompPrefix() )
+                                                        .appendAscii( "embeddings/spreadsheet" )
+                                                        .append( static_cast<sal_Int32>(mnEmbeddeDocumentCounter++) )
+                                                        .appendAscii( ".xlsx" )
+                                                        .makeStringAndClear() );
+                        }
+                        else
+                        {
+                            sRelId = mpFB->addRelation( mpFS->getOutputStream(),
+                                                        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
+                                                        OUStringBuffer()
+                                                        .appendAscii( GetRelationCompPrefix() )
+                                                        .appendAscii( "embeddings/textdocument" )
+                                                        .append( static_cast<sal_Int32>(mnEmbeddeDocumentCounter++) )
+                                                        .appendAscii( ".docx" )
+                                                        .makeStringAndClear() );
+                        }
 
                         mpFS->startElementNS( mnXmlNamespace, XML_graphicFrame, FSEND );
 
@@ -1043,16 +1087,30 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
                         mpFS->startElementNS( XML_a, XML_graphicData,
                                               XML_uri, "http://schemas.openxmlformats.org/presentationml/2006/ole",
                                               FSEND );
-                        mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
+                        if( bSpreadSheet )
+                        {
+                            mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
                                               XML_name, "Spreadsheet",
                                               FSNS(XML_r, XML_id), USS( sRelId ),
                                               FSEND );
+                        }
+                        else
+                        {
+                            mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
+                                              XML_name, "Document",
+                                              FSNS(XML_r, XML_id), USS( sRelId ),
+                                              // The spec says that this is a required attribute, but PowerPoint can only handle an empty value.
+                                              XML_spid, "",
+                                              FSEND );
+                        }
 
                         mpFS->singleElementNS( mnXmlNamespace, XML_embed, FSEND );
 
                         // pic element
                         SdrObject* pSdrOLE2( GetSdrObjectFromXShape( xShape ) );
-                        if ( pSdrOLE2 && pSdrOLE2->ISA( SdrOle2Obj ) )
+                        // The spec doesn't allow <p:pic> here, but PowerPoint requires it.
+                        bool bEcma = mpFB->getVersion() == oox::core::ECMA_DIALECT;
+                        if ( pSdrOLE2 && pSdrOLE2->ISA( SdrOle2Obj ) && bEcma)
                         {
                             const Graphic* pGraphic = ((SdrOle2Obj*)pSdrOLE2)->GetGraphic();
                             if ( pGraphic )
diff --git a/sd/CppunitTest_sd_import_tests.mk b/sd/CppunitTest_sd_import_tests.mk
index ce8ad63..de04320 100644
--- a/sd/CppunitTest_sd_import_tests.mk
+++ b/sd/CppunitTest_sd_import_tests.mk
@@ -64,46 +64,7 @@ $(eval $(call gb_CppunitTest_use_api,sd_import_tests,\
 
 $(eval $(call gb_CppunitTest_use_ure,sd_import_tests))
 
-$(eval $(call gb_CppunitTest_use_components,sd_import_tests,\
-    animations/source/animcore/animcore \
-    basic/util/sb \
-    chart2/source/chartcore \
-    chart2/source/controller/chartcontroller \
-    comphelper/util/comphelp \
-    configmgr/source/configmgr \
-    dbaccess/util/dba \
-    desktop/source/deployment/deployment \
-    embeddedobj/util/embobj \
-    filter/source/config/cache/filterconfig1 \
-    filter/source/svg/svgfilter \
-    forms/util/frm \
-    framework/util/fwk \
-    i18npool/util/i18npool \
-    linguistic/source/lng \
-    oox/util/oox \
-    package/source/xstor/xstor \
-    package/util/package2 \
-    sax/source/expatwrap/expwrap \
-    sd/util/sd \
-    sd/util/sdfilt \
-    sd/util/sdd \
-    sfx2/util/sfx \
-    sot/util/sot \
-    svl/source/fsstor/fsstorage \
-    svtools/util/svt \
-    toolkit/util/tk \
-    ucb/source/core/ucb1 \
-    ucb/source/ucp/expand/ucpexpand1 \
-    ucb/source/ucp/file/ucpfile1 \
-    ucb/source/ucp/package/ucppkg1 \
-    ucb/source/ucp/tdoc/ucptdoc1 \
-    unotools/util/utl \
-    unoxml/source/rdf/unordf \
-    unoxml/source/service/unoxml \
-    xmloff/util/xo \
-    xmlsecurity/util/xsec_fw \
-    xmlsecurity/util/xmlsecurity \
-))
+$(eval $(call gb_CppunitTest_use_rdb,sd_import_tests,services))
 
 $(eval $(call gb_CppunitTest_use_configuration,sd_import_tests))
 
diff --git a/sd/qa/unit/data/odp/bnc822341.odp b/sd/qa/unit/data/odp/bnc822341.odp
new file mode 100644
index 0000000..28fe2f4
Binary files /dev/null and b/sd/qa/unit/data/odp/bnc822341.odp differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 316740e..68a205e 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -97,6 +97,9 @@ public:
     void testFdo79731();
     void testBnc904423();
     void testShapeLineStyle();
+#if !defined WNT
+    void testBnc822341();
+#endif
 
     CPPUNIT_TEST_SUITE(SdFiltersTest);
     CPPUNIT_TEST(testDocumentLayout);
@@ -132,6 +135,10 @@ public:
     CPPUNIT_TEST(testFdo79731);
     CPPUNIT_TEST(testBnc904423);
     CPPUNIT_TEST(testShapeLineStyle);
+#if !defined WNT
+    CPPUNIT_TEST(testBnc822341);
+#endif
+
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -1244,6 +1251,45 @@ void SdFiltersTest::testShapeLineStyle()
     xDocShRef->DoClose();
 }
 
+#if !defined WNT
+
+void SdFiltersTest::testBnc822341()
+{
+    // Check import / export of embedded text document
+    ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("sd/qa/unit/data/odp/bnc822341.odp"));
+    xDocShRef = saveAndReload( xDocShRef, PPTX );
+
+    // Export an LO specific ole object (imported from an ODP document)
+    {
+        SdDrawDocument *pDoc = xDocShRef->GetDoc();
+        CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
+        const SdrPage *pPage = pDoc->GetPage(1);
+        CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
+
+        const SdrObject* pObj = dynamic_cast<SdrObject*>( pPage->GetObj(0) );
+        CPPUNIT_ASSERT_MESSAGE( "no object", pObj != NULL);
+        CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(OBJ_OLE2), pObj->GetObjIdentifier() );
+    }
+
+    xDocShRef = saveAndReload( xDocShRef, PPTX );
+
+    // Export an MS specific ole object (imported from a PPTX document)
+    {
+        SdDrawDocument *pDoc = xDocShRef->GetDoc();
+        CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
+        const SdrPage *pPage = pDoc->GetPage(1);
+        CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
+
+        const SdrObject* pObj = dynamic_cast<SdrObject*>( pPage->GetObj(0) );
+        CPPUNIT_ASSERT_MESSAGE( "no object", pObj != NULL);
+        CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(OBJ_OLE2), pObj->GetObjIdentifier() );
+    }
+
+    xDocShRef->DoClose();
+}
+
+#endif
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list