[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - sw/qa sw/source

Szymon Kłos szymon.klos at collabora.com
Fri Aug 11 10:35:33 UTC 2017


 sw/qa/extras/uiwriter/data/watermark-position.odt |binary
 sw/qa/extras/uiwriter/uiwriter.cxx                |   79 ++++++++++++++++++++++
 sw/source/core/edit/edfcol.cxx                    |   22 ++++++
 3 files changed, 101 insertions(+)

New commits:
commit e0ac06d9c6325447253c819573dfe41eb627617d
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Sun Aug 6 16:22:38 2017 +0200

    tdf#108494 fix regression
    
    * correct watermark position
    * insert also on left and right pages if headers are different
    
    Change-Id: Ibacfa6ea14bd8e9c1fd0d0b15de020b30d0a109f
    Reviewed-on: https://gerrit.libreoffice.org/40829
    Reviewed-by: Aron Budea <aron.budea at collabora.com>
    Tested-by: Aron Budea <aron.budea at collabora.com>

diff --git a/sw/qa/extras/uiwriter/data/watermark-position.odt b/sw/qa/extras/uiwriter/data/watermark-position.odt
new file mode 100755
index 000000000000..53ff24781682
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/watermark-position.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 90b54c38d19d..8495768570e1 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -12,6 +12,7 @@
 #include <com/sun/star/i18n/TextConversionOption.hpp>
 #include <com/sun/star/frame/DispatchHelper.hpp>
 #include <com/sun/star/style/CaseMap.hpp>
+#include <tools/gen.hxx>
 #include <tools/errcode.hxx>
 #include <swmodeltestbase.hxx>
 #include <ndtxt.hxx>
@@ -84,6 +85,7 @@
 #include "com/sun/star/text/TextMarkupType.hpp"
 #include <com/sun/star/chart2/data/XDataSource.hpp>
 #include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
+#include <com/sun/star/drawing/XShape.hpp>
 #include <o3tl/make_unique.hxx>
 #include <osl/file.hxx>
 #include <paratr.hxx>
@@ -102,6 +104,7 @@
 #include <editeng/unolingu.hxx>
 #include <config_features.h>
 #include <sfx2/watermarkitem.hxx>
+#include <fmthdft.hxx>
 
 static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
 
@@ -124,6 +127,7 @@ public:
     void testDOTMAutoText();
     void testDOCXAutoTextGallery();
     void testWatermarkDOCX();
+    void testWatermarkPosition();
     void testTdf67238();
     void testFdo75110();
     void testFdo75898();
@@ -248,6 +252,7 @@ public:
     CPPUNIT_TEST(testDOTMAutoText);
     CPPUNIT_TEST(testDOCXAutoTextGallery);
     CPPUNIT_TEST(testWatermarkDOCX);
+    CPPUNIT_TEST(testWatermarkPosition);
     CPPUNIT_TEST(testTdf67238);
     CPPUNIT_TEST(testFdo75110);
     CPPUNIT_TEST(testFdo75898);
@@ -844,6 +849,80 @@ void SwUiWriterTest::testWatermarkDOCX()
     CPPUNIT_ASSERT_EQUAL((sal_Int16)50, pWatermark->GetTransparency());
 }
 
+void SwUiWriterTest::testWatermarkPosition()
+{
+    // tdf#108494 Watermark inserted in the document with page break was outside the first page
+    const int aPagesInDocument = 2;
+    const int aAdditionalPagesCount[] = {    0,     0,    1,     1,    5,     5,   20,    20 };
+    const bool aChangeHeader[]        = { true, false, true, false, true, false, true, false };
+
+    for (unsigned long i = 0; i < sizeof(aAdditionalPagesCount) / sizeof(int); ++i)
+    {
+        int aPages = aPagesInDocument + aAdditionalPagesCount[i];
+
+        // Empty document with one Page Break
+        SwDoc* pDoc = createDoc("watermark-position.odt");
+        SwEditShell* pEditShell = pDoc->GetEditShell();
+        SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+        const OUString rPageStyleName = "Default Style";
+        uno::Reference<frame::XModel> xModel = pDoc->GetDocShell()->GetBaseModel();
+        uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
+        uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
+        uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
+        uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
+
+        // 1. Add additional page breaks
+        for (int j = 0; j < aAdditionalPagesCount[i]; ++j)
+            pWrtShell->InsertPageBreak();
+
+        // 2. Change header state (On, Off, On)
+        if (aChangeHeader[i])
+        {
+            SwPageDesc aDesc(pDoc->GetPageDesc(0));
+            SwFrameFormat& rMaster = aDesc.GetMaster();
+            rMaster.SetFormatAttr(SwFormatHeader(true));
+            pDoc->ChgPageDesc(0, aDesc);
+
+            aDesc = pDoc->GetPageDesc(0);
+            SwFrameFormat& rMaster2 = aDesc.GetMaster();
+            rMaster2.SetFormatAttr(SwFormatHeader(false));
+            pDoc->ChgPageDesc(0, aDesc);
+
+            aDesc = pDoc->GetPageDesc(0);
+            SwFrameFormat& rMaster3 = aDesc.GetMaster();
+            rMaster3.SetFormatAttr(SwFormatHeader(true));
+            pDoc->ChgPageDesc(0, aDesc);
+        }
+
+        // 3. Insert Watermark
+        SfxWatermarkItem aWatermark;
+        aWatermark.SetText("Watermark");
+        aWatermark.SetFont("DejaVu Sans");
+
+        pEditShell->SetWatermark(aWatermark);
+
+        uno::Reference<css::drawing::XShape> xShape(getShape(1), uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xShape.is());
+
+        SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
+
+        // Get Watermark object
+        SdrObject* pObject = pPage->GetObj(0);
+        pObject->RecalcBoundRect();
+        const Rectangle& rRect = pObject->GetSnapRect();
+        Size rSize = pPage->GetSize();
+
+        // Page break, calculate height of a page
+        const int nPageHeight = rSize.getHeight() / aPages;
+
+        std::stringstream aMessage;
+        aMessage << "Case: " << i << ", nPageHeight = " << nPageHeight << ", rRect.Bottom = " << rRect.Bottom();
+
+        // Check if Watermark is inside a page
+        CPPUNIT_ASSERT_MESSAGE(aMessage.str(), nPageHeight >= rRect.Bottom());
+    }
+}
+
 void SwUiWriterTest::testFdo74981()
 {
     // create a document with an input field
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index df253bb29d7d..06a33461430f 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -525,14 +525,36 @@ void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark)
         if (!bHeaderIsOn)
             xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_ON, uno::makeAny(true));
 
+        // backup header height
+        bool bDynamicHeight = true;
+        sal_Int32 nOldValue;
+        xPageStyle->getPropertyValue(UNO_NAME_HEADER_HEIGHT) >>= nOldValue;
+        xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_DYNAMIC_HEIGHT) >>= bDynamicHeight;
+        xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_DYNAMIC_HEIGHT, uno::Any(false));
+
         // If the header already contains a document header field, no need to do anything.
         uno::Reference<text::XText> xHeaderText;
         uno::Reference<text::XText> xHeaderTextFirst;
+        uno::Reference<text::XText> xHeaderTextLeft;
+        uno::Reference<text::XText> xHeaderTextRight;
+
         xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
         lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderText);
 
         xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT_FIRST) >>= xHeaderTextFirst;
         lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderTextFirst);
+
+        xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT_LEFT) >>= xHeaderTextLeft;
+        lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderTextLeft);
+
+        xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT_RIGHT) >>= xHeaderTextRight;
+        lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderTextRight);
+
+        // tdf#108494 the header height was switched to height of a watermark
+        // and shape was moved to the lower part of a page
+        xPageStyle->setPropertyValue(UNO_NAME_HEADER_HEIGHT, uno::makeAny((sal_Int32)11));
+        xPageStyle->setPropertyValue(UNO_NAME_HEADER_HEIGHT, uno::makeAny(nOldValue));
+        xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_DYNAMIC_HEIGHT, uno::Any(bDynamicHeight));
     }
 }
 


More information about the Libreoffice-commits mailing list