[Libreoffice-commits] core.git: sd/qa svx/source

Mark Hung marklh9 at gmail.com
Thu Feb 2 21:12:22 UTC 2017


 sd/qa/unit/misc-tests.cxx       |   43 ++++++++++++++++++++++++++++++++++++++++
 svx/source/unodraw/unoshape.cxx |   17 ++++++++++++---
 2 files changed, 56 insertions(+), 4 deletions(-)

New commits:
commit eb9b9c28ed32cacb5ed0410875af2ec03345fbf9
Author: Mark Hung <marklh9 at gmail.com>
Date:   Thu Jan 26 23:13:03 2017 +0800

    tdf#91795: prevent default item overwrite actual values.
    
    A few properties of FillProeprties have the same nWID
    but have different nMemberId, such as FillGradient,
    FillGradientName,FillHatch,FillHatchName, FillBitmap,
    FillBitmapName, and FillBitmapURL.
    
    When putting value of an item, the default item was put
    first, despite the value of the item might have already
    been put.
    
    Move the part of the code that put default item upfront
    so that it will not overwrite actual value accidentally.
    
    Change-Id: I54288420abde333e5b3e4cdd31ca9fae0c3ed7ab
    Reviewed-on: https://gerrit.libreoffice.org/33594
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
index ff95dc9..2a1620c 100644
--- a/sd/qa/unit/misc-tests.cxx
+++ b/sd/qa/unit/misc-tests.cxx
@@ -20,6 +20,14 @@
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XModel2.hpp>
 
+#include <com/sun/star/awt/Gradient.hpp>
+#include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/drawing/XDrawPages.hpp>
+#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/drawing/XShapes.hpp>
+#include <com/sun/star/container/XIndexAccess.hpp>
+
 #include <vcl/scheduler.hxx>
 #include <osl/thread.hxx>
 #include <FactoryIds.hxx>
@@ -51,12 +59,14 @@ public:
     void testTdf96708();
     void testTdf99396();
     void testTdf99396TextEdit();
+    void testFillGradient();
 
     CPPUNIT_TEST_SUITE(SdMiscTest);
     CPPUNIT_TEST(testTdf96206);
     CPPUNIT_TEST(testTdf96708);
     CPPUNIT_TEST(testTdf99396);
     CPPUNIT_TEST(testTdf99396TextEdit);
+    CPPUNIT_TEST(testFillGradient);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -255,6 +265,39 @@ void SdMiscTest::testTdf99396TextEdit()
     xDocSh->DoClose();
 }
 
+void SdMiscTest::testFillGradient()
+{
+    ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false);
+    uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier = getDoc( xDocShRef );
+    uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
+    // Insert a new page.
+    uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->insertNewByIndex(0), uno::UNO_QUERY_THROW );
+    uno::Reference<drawing::XShapes> xShapes(xDrawPage,uno::UNO_QUERY_THROW);
+    uno::Reference<lang::XMultiServiceFactory> const xDoc(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY);
+    // Create a rectangle
+    uno::Reference<drawing::XShape> xShape1(xDoc->createInstance("com.sun.star.drawing.RectangleShape"),uno::UNO_QUERY_THROW );
+    uno::Reference<beans::XPropertySet> xPropSet(xShape1, uno::UNO_QUERY_THROW);
+    // Set FillStyle and FillGradient
+    awt::Gradient aGradient;
+    aGradient.StartColor = sal_Int32(RGB_COLORDATA(255, 0, 0));
+    aGradient.EndColor = sal_Int32(RGB_COLORDATA(0, 255, 0));
+    xPropSet->setPropertyValue("FillStyle", uno::makeAny(drawing::FillStyle_GRADIENT));
+    xPropSet->setPropertyValue("FillGradient", uno::makeAny(aGradient));
+    // Add the rectangle to the page.
+    xShapes->add(xShape1);
+
+    // Retrieve the shape and check FillStyle and FillGradient
+    uno::Reference<container::XIndexAccess> xIndexAccess(xDrawPage, uno::UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySet > xPropSet2(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW);
+    drawing::FillStyle eFillStyle;
+    awt::Gradient aGradient2;
+    CPPUNIT_ASSERT(xPropSet2->getPropertyValue("FillStyle") >>= eFillStyle);
+    CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT,eFillStyle);
+    CPPUNIT_ASSERT(xPropSet2->getPropertyValue("FillGradient") >>= aGradient2);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(255, 0, 0)),aGradient2.StartColor);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(0, 255, 0)),aGradient2.EndColor);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index d20eaef..bb6e8fa 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -95,7 +95,7 @@
 
 #include <memory>
 #include <vector>
-
+#include <iostream>
 using namespace ::osl;
 using namespace ::cppu;
 using namespace ::com::sun::star;
@@ -598,6 +598,18 @@ void SvxItemPropertySet_ObtainSettingsFromPropertySet(const SvxItemPropertySet&
         const SfxItemPropertyMap& rSrc = rPropSet.getPropertyMap();
         PropertyEntryVector_t aSrcPropVector = rSrc.getPropertyEntries();
         PropertyEntryVector_t::const_iterator aSrcIt = aSrcPropVector.begin();
+
+        while(aSrcIt != aSrcPropVector.end())
+        {
+            const sal_uInt16 nWID = aSrcIt->nWID;
+            if(SfxItemPool::IsWhich(nWID)
+                    && (nWID < OWN_ATTR_VALUE_START || nWID > OWN_ATTR_VALUE_END)
+                    && rPropSet.GetUsrAnyForID(nWID))
+                rSet.Put(rSet.GetPool()->GetDefaultItem(nWID));
+            ++aSrcIt;
+        }
+
+        aSrcIt = aSrcPropVector.begin();
         while(aSrcIt != aSrcPropVector.end())
         {
             if(aSrcIt->nWID)
@@ -618,9 +630,6 @@ void SvxItemPropertySet_ObtainSettingsFromPropertySet(const SvxItemPropertySet&
                         }
                         else
                         {
-                            if(SfxItemPool::IsWhich(pEntry->nWID))
-                                rSet.Put(rSet.GetPool()->GetDefaultItem(pEntry->nWID));
-                            // set
                             SvxItemPropertySet_setPropertyValue(pEntry, *pUsrAny, rSet);
                         }
                     }


More information about the Libreoffice-commits mailing list