[Libreoffice-commits] core.git: Branch 'feature/image_rework' - 2 commits - filter/source include/svx svx/source sw/CppunitTest_sw_globalfilter.mk sw/qa

Zolnai Tamás tamas.zolnai at collabora.com
Sun Nov 2 08:13:32 PST 2014


 dev/null                                                    |binary
 filter/source/msfilter/msdffimp.cxx                         |    1 
 include/svx/svdograf.hxx                                    |    3 
 svx/source/sdr/contact/viewobjectcontactofgraphic.cxx       |   13 --
 sw/CppunitTest_sw_globalfilter.mk                           |    4 
 sw/qa/extras/globalfilter/data/document_with_two_images.odt |binary
 sw/qa/extras/globalfilter/globalfilter.cxx                  |   64 +++++++-----
 7 files changed, 51 insertions(+), 34 deletions(-)

New commits:
commit 2fd3c39b7389e6a7a283dc218b627a7723e960b1
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Sun Nov 2 17:10:08 2014 +0100

    Make SdrGrafObj swapping methods private.
    
    Plus remove some useless call of them.
    
    Change-Id: I47a50b5734d799ac02ee7221c95f82415afb9497

diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index 7396abe..5f48e7e 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -3970,7 +3970,6 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, cons
 
         if ( bLinkGrf && !bGrfRead )
         {
-            static_cast<SdrGrafObj*>(pRet)->ForceSwapIn();
             Graphic aGraf(static_cast<SdrGrafObj*>(pRet)->GetGraphic());
             lcl_ApplyCropping( *this, &rSet, aGraf );
         }
diff --git a/include/svx/svdograf.hxx b/include/svx/svdograf.hxx
index e600609..27beb28 100644
--- a/include/svx/svdograf.hxx
+++ b/include/svx/svdograf.hxx
@@ -69,6 +69,7 @@ private:
 
     // to allow sdr::contact::ViewObjectContactOfGraphic access to ImpUpdateGraphicLink()
     friend class sdr::contact::ViewObjectContactOfGraphic;
+    friend class SdrExchangeView; // Only for a ForceSwapIn() call.
     friend class SdrGraphicLink;
 
 private:
@@ -135,9 +136,11 @@ public:
     void                    SetGrafStreamURL( const OUString& rGraphicStreamURL );
     OUString                GetGrafStreamURL() const;
 
+private:
     void                    ForceSwapIn() const;
     void                    ForceSwapOut() const;
 
+public:
     void                    SetGraphicLink(const OUString& rFileName, const OUString& rReferer, const OUString& rFilterName);
     void                    ReleaseGraphicLink();
     bool IsLinkedGraphic() const;
diff --git a/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx b/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx
index a445b75..c95b42d 100644
--- a/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx
+++ b/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx
@@ -245,8 +245,6 @@ namespace sdr
             // prepare primitive generation with evtl. loading the graphic when it's swapped out
             SdrGrafObj& rGrafObj = const_cast< ViewObjectContactOfGraphic* >(this)->getSdrGrafObj();
             bool bDoAsynchronGraphicLoading(rGrafObj.GetModel() && rGrafObj.GetModel()->IsSwapGraphics());
-            bool bSwapInDone(false);
-            bool bSwapInExclusive(false);
 
             if( bDoAsynchronGraphicLoading && rGrafObj.IsSwappedOut() )
             {
@@ -262,16 +260,15 @@ namespace sdr
                     || GetObjectContact().isOutputToPDFFile() )
                 {
                     bDoAsynchronGraphicLoading = false;
-                    bSwapInExclusive = true;
                 }
             }
             if( bDoAsynchronGraphicLoading )
             {
-                bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithAsynchroniousLoading();
+                const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithAsynchroniousLoading();
             }
             else
             {
-                bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithSynchroniousLoading();
+                const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithSynchroniousLoading();
             }
 
             // get return value by calling parent
@@ -294,12 +291,6 @@ namespace sdr
                 }
             }
 
-            // if swap in was forced only for printing metafile and pdf, swap out again
-            if( bSwapInDone && bSwapInExclusive )
-            {
-                rGrafObj.ForceSwapOut();
-            }
-
             return xRetval;
         }
 
commit 5a5be09081fd88a985341ed5d7da0998fd5bc729
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Sun Nov 2 12:43:35 2014 +0100

    Improve swapped out image export writer test
    
    Change-Id: Ibb5d9f1f0503ef16da89e3586f6e3fe2262a89c6

diff --git a/sw/CppunitTest_sw_globalfilter.mk b/sw/CppunitTest_sw_globalfilter.mk
index 96787c0..b25bc89 100644
--- a/sw/CppunitTest_sw_globalfilter.mk
+++ b/sw/CppunitTest_sw_globalfilter.mk
@@ -83,6 +83,10 @@ $(eval $(call gb_CppunitTest_use_components,sw_globalfilter,\
 	xmloff/util/xo \
 ))
 
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_globalfilter,\
+	officecfg/registry \
+))
+
 $(eval $(call gb_CppunitTest_use_configuration,sw_globalfilter))
 
 $(eval $(call gb_CppunitTest_use_unittest_configuration,sw_globalfilter))
diff --git a/sw/qa/extras/globalfilter/data/document_with_an_image.odt b/sw/qa/extras/globalfilter/data/document_with_an_image.odt
deleted file mode 100644
index ce7a29a..0000000
Binary files a/sw/qa/extras/globalfilter/data/document_with_an_image.odt and /dev/null differ
diff --git a/sw/qa/extras/globalfilter/data/document_with_two_images.odt b/sw/qa/extras/globalfilter/data/document_with_two_images.odt
new file mode 100644
index 0000000..54d3d66
Binary files /dev/null and b/sw/qa/extras/globalfilter/data/document_with_two_images.odt differ
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index 005ab66..19bdb5f 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -11,11 +11,13 @@
 
 #include <com/sun/star/awt/XBitmap.hpp>
 #include <com/sun/star/graphic/XGraphic.hpp>
-
+#include <officecfg/Office/Common.hxx>
+#include <comphelper/processfactory.hxx>
 #include <unotxdoc.hxx>
 #include <docsh.hxx>
 #include <doc.hxx>
 #include <ndgrf.hxx>
+#include <drawdoc.hxx>
 
 class Test : public SwModelTestBase
 {
@@ -41,31 +43,19 @@ void Test::testSwappedOutImageExport()
 
     for( size_t nFilter = 0; nFilter < aFilterNames.size(); ++nFilter )
     {
-        // Check whether the export code swaps in the image which was swapped out before.
+        // Check whether the export code swaps in the image which was swapped out before by auto mechanism
+
+        // Set cache size to a very small value to make sure one of the images is swapped out
+        boost::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create());
+        officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(sal_Int32(1), batch);
+        batch->commit();
+
         if (mxComponent.is())
             mxComponent->dispose();
-        mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/globalfilter/data/document_with_an_image.odt"), "com.sun.star.text.TextDocument");
+        mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/globalfilter/data/document_with_two_images.odt"), "com.sun.star.text.TextDocument");
 
         const OString sFailedMessage = OString("Failed on filter: ")
                                        + OUStringToOString(aFilterNames[nFilter], RTL_TEXTENCODING_ASCII_US);
-        SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
-        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTxtDoc);
-        SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
-        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pDoc);
-        SwNodes& aNodes = pDoc->GetNodes();
-
-        // Find and swap out the image
-        bool bImageFound = false;
-        for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
-        {
-            if( aNodes[nIndex]->IsGrfNode() )
-            {
-                SwGrfNode* pGrfNode = aNodes[nIndex]->GetGrfNode();
-                pGrfNode->SwapOut();
-                bImageFound = true;
-            }
-        }
-        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), bImageFound);
 
         // Export the document and import again for a check
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
@@ -83,8 +73,9 @@ void Test::testSwappedOutImageExport()
         // Check whether graphic exported well after it was swapped out
         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
         uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(1), xDraws->getCount());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2), xDraws->getCount());
 
+        // First image
         uno::Reference<drawing::XShape> xImage(xDraws->getByIndex(0), uno::UNO_QUERY);
         uno::Reference< beans::XPropertySet > XPropSet( xImage, uno::UNO_QUERY_THROW );
         // Check URL
@@ -112,6 +103,35 @@ void Test::testSwappedOutImageExport()
             CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(610), xBitmap->getSize().Width );
             CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(381), xBitmap->getSize().Height );
         }
+
+        // Second Image
+        xImage.set(xDraws->getByIndex(1), uno::UNO_QUERY);
+        XPropSet.set( xImage, uno::UNO_QUERY_THROW );
+        // Check URL
+        {
+            OUString sURL;
+            XPropSet->getPropertyValue("GraphicURL") >>= sURL;
+            // HTML filter changes the name, but the real indicater here is the "null" URL.
+            if( aFilterNames[nFilter] == "HTML (StarWriter)" )
+            {
+                CPPUNIT_ASSERT_MESSAGE(
+                    sFailedMessage.getStr(), sURL != OUString("vnd.sun.star.GraphicObject:00000000000000000000000000000000"));
+            }
+            else
+            {
+                CPPUNIT_ASSERT_EQUAL_MESSAGE(
+                    sFailedMessage.getStr(), OUString("vnd.sun.star.GraphicObject:1000000000000384000002580A24B597"), sURL);
+            }
+        }
+        // Check size
+        {
+            uno::Reference<graphic::XGraphic> xGraphic;
+            XPropSet->getPropertyValue("Graphic") >>= xGraphic;
+            uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
+            CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(900), xBitmap->getSize().Width );
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(600), xBitmap->getSize().Height );
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list