[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - sfx2/source sw/CppunitTest_sw_odfexport.mk sw/qa

Michael Stahl mstahl at redhat.com
Thu Feb 18 09:27:47 UTC 2016


 sfx2/source/doc/objstor.cxx                  |   13 ++++++++++-
 sw/CppunitTest_sw_odfexport.mk               |    1 
 sw/qa/extras/odfexport/data/2_MathType3.docx |binary
 sw/qa/extras/odfexport/odfexport.cxx         |   30 +++++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 1 deletion(-)

New commits:
commit b21bb8d7b3808eee06320b634e11e3a4ab217839
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 12 18:22:51 2016 +0100

    sfx2: related tdf#56270: loss of embedded objects imported from DOCX
    
    After the import some of these are kept in RUNNING state.  For Math
    objects imported from MathType3 OLEs in particular, first a new
    Math object is created and stored to the XStorage, only then is the
    MathType3 stream imported.  This means the Math object is modified and
    contains data that must be stored.
    
    The problem is then that SfxObjectShell::ImportFrom() simply calls
    setModified(false), clearing the flag without storing the object.
    
    For Flat ODF export we lose all the objects that are cached in sw's
    SwOLELRUCache; for the bugdoc something more inexplicable happens for
    ODT export where we lose "Object 214" (which is the first one in the
    cache) but no other ones.
    
    (The main difference is that for ODF there is an optimization to copy the
    embedded object's storage without loading the object, but for Flat ODF
    every object must be loaded and exported.)
    
    (regression from 83777cd6e0f3f1a4458af896fd13344c696ecb1e)
    
    (cherry picked from commit d81d104833f0ee9349ebcd0d79d2de84ba9a7262)
    
    Change-Id: Id1474fba9f4da2d5247c7ff4dc6819ddb9829fe8
    Reviewed-on: https://gerrit.libreoffice.org/22337
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index be8ecd0..7bc028d 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2281,8 +2281,19 @@ bool SfxObjectShell::ImportFrom(SfxMedium& rMedium,
                 if ( nState == embed::EmbedStates::LOADED || nState == embed::EmbedStates::RUNNING )    // means that the object is not active
                 {
                     uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
-                    if ( xModifiable.is() )
+                    if (xModifiable.is() && xModifiable->isModified())
+                    {
+                        uno::Reference<embed::XEmbedPersist> const xPers(xObj, uno::UNO_QUERY);
+                        if (xPers.is())
+                        {   // store it before resetting modified!
+                            xPers->storeOwn();
+                        }
+                        else
+                        {
+                            SAL_WARN("sfx.doc", "Modified object without persistence!");
+                        }
                         xModifiable->setModified(sal_False);
+                    }
                 }
             }
         }
diff --git a/sw/CppunitTest_sw_odfexport.mk b/sw/CppunitTest_sw_odfexport.mk
index c6ec626..0930732 100644
--- a/sw/CppunitTest_sw_odfexport.mk
+++ b/sw/CppunitTest_sw_odfexport.mk
@@ -81,6 +81,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_odfexport,\
     writerfilter/util/writerfilter \
     $(if $(filter DESKTOP,$(BUILD_TYPE)),xmlhelp/util/ucpchelp1) \
     xmloff/util/xo \
+    xmlscript/util/xmlscript \
 ))
 
 $(eval $(call gb_CppunitTest_use_custom_headers,sw_odfexport,\
diff --git a/sw/qa/extras/odfexport/data/2_MathType3.docx b/sw/qa/extras/odfexport/data/2_MathType3.docx
new file mode 100644
index 0000000..0694921
Binary files /dev/null and b/sw/qa/extras/odfexport/data/2_MathType3.docx differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 2506ec3..a917596 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -68,10 +68,40 @@ public:
             pBatch->commit();
             return pResetter;
         }
+        if (OString(pFilename) == "2_MathType3.docx")
+        {
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [this] () {
+                    mpFilter = "writer8";
+                    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+                            comphelper::ConfigurationChanges::create());
+                    officecfg::Office::Common::Cache::Writer::OLE_Objects::set(20, pBatch);
+                    return pBatch->commit();
+                }));
+            mpFilter = "OpenDocument Text Flat XML"; // doesn't happen with ODF package
+            std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+                    comphelper::ConfigurationChanges::create());
+            officecfg::Office::Common::Cache::Writer::OLE_Objects::set(1, pBatch);
+            pBatch->commit();
+            return pResetter;
+        }
         return nullptr;
     }
 };
 
+DECLARE_ODFEXPORT_TEST(testMathObjectFlatExport, "2_MathType3.docx")
+{
+    uno::Reference<util::XModifiable> xModifiable(mxComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(!xModifiable->isModified());
+    // see preTest(), set the OLE cache to 1 for this test
+    // and the problem was that the formulas that were in the cache
+    // (the second one) were lost
+    OUString formula1(getFormula(getRun(getParagraph(1), 1)));
+    CPPUNIT_ASSERT_EQUAL(OUString(" size 12{1+1=2} {}"), formula1);
+    OUString formula2(getFormula(getRun(getParagraph(2), 1)));
+    CPPUNIT_ASSERT_EQUAL(OUString(" size 12{2+2=4} {}"), formula2);
+}
+
 DECLARE_ODFEXPORT_TEST(testFramebackgrounds, "framebackgrounds.odt")
 {
    //Counting the Number of Frames and checking with the expected count


More information about the Libreoffice-commits mailing list