summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-08-06 16:22:38 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2017-08-11 10:56:28 +0200
commit19b0171bbb6c2bcdab998b74a212dc68b1884e84 (patch)
treeaa248832d0e94f6339a13587b66c2eb558962f34 /sw
parent9456afaa5aa12926b1aa6b74ece1654d47e1c650 (diff)
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/40891 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sw')
-rwxr-xr-xsw/qa/extras/uiwriter/data/watermark-position.odtbin0 -> 8769 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx79
-rw-r--r--sw/source/core/edit/edfcol.cxx22
3 files changed, 101 insertions, 0 deletions
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
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/watermark-position.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 0d9a988559c2..68e96977139a 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -14,6 +14,7 @@
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <com/sun/star/style/CaseMap.hpp>
#include <vcl/errcode.hxx>
+#include <tools/gen.hxx>
#include <swmodeltestbase.hxx>
#include <ndtxt.hxx>
#include <wrtsh.hxx>
@@ -86,6 +87,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>
@@ -107,6 +109,7 @@
#include <vcl/scheduler.hxx>
#include <config_features.h>
#include <sfx2/watermarkitem.hxx>
+#include <fmthdft.hxx>
static const char* const DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
@@ -129,6 +132,7 @@ public:
void testDOTMAutoText();
void testDOCXAutoTextGallery();
void testWatermarkDOCX();
+ void testWatermarkPosition();
void testTdf67238();
void testFdo75110();
void testFdo75898();
@@ -279,6 +283,7 @@ public:
CPPUNIT_TEST(testDOTMAutoText);
CPPUNIT_TEST(testDOCXAutoTextGallery);
CPPUNIT_TEST(testWatermarkDOCX);
+ CPPUNIT_TEST(testWatermarkPosition);
CPPUNIT_TEST(testTdf67238);
CPPUNIT_TEST(testFdo75110);
CPPUNIT_TEST(testFdo75898);
@@ -901,6 +906,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 tools::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 c91d8e08712e..4e309a33761f 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -530,14 +530,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));
}
}