Kaydet (Commit) 19b0171b authored tarafından Szymon Kłos's avatar Szymon Kłos

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/40891Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarSzymon Kłos <szymon.klos@collabora.com>
üst 9456afaa
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <com/sun/star/frame/DispatchHelper.hpp> #include <com/sun/star/frame/DispatchHelper.hpp>
#include <com/sun/star/style/CaseMap.hpp> #include <com/sun/star/style/CaseMap.hpp>
#include <vcl/errcode.hxx> #include <vcl/errcode.hxx>
#include <tools/gen.hxx>
#include <swmodeltestbase.hxx> #include <swmodeltestbase.hxx>
#include <ndtxt.hxx> #include <ndtxt.hxx>
#include <wrtsh.hxx> #include <wrtsh.hxx>
...@@ -86,6 +87,7 @@ ...@@ -86,6 +87,7 @@
#include "com/sun/star/text/TextMarkupType.hpp" #include "com/sun/star/text/TextMarkupType.hpp"
#include <com/sun/star/chart2/data/XDataSource.hpp> #include <com/sun/star/chart2/data/XDataSource.hpp>
#include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp> #include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <o3tl/make_unique.hxx> #include <o3tl/make_unique.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <paratr.hxx> #include <paratr.hxx>
...@@ -107,6 +109,7 @@ ...@@ -107,6 +109,7 @@
#include <vcl/scheduler.hxx> #include <vcl/scheduler.hxx>
#include <config_features.h> #include <config_features.h>
#include <sfx2/watermarkitem.hxx> #include <sfx2/watermarkitem.hxx>
#include <fmthdft.hxx>
static const char* const DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/"; static const char* const DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
...@@ -129,6 +132,7 @@ public: ...@@ -129,6 +132,7 @@ public:
void testDOTMAutoText(); void testDOTMAutoText();
void testDOCXAutoTextGallery(); void testDOCXAutoTextGallery();
void testWatermarkDOCX(); void testWatermarkDOCX();
void testWatermarkPosition();
void testTdf67238(); void testTdf67238();
void testFdo75110(); void testFdo75110();
void testFdo75898(); void testFdo75898();
...@@ -279,6 +283,7 @@ public: ...@@ -279,6 +283,7 @@ public:
CPPUNIT_TEST(testDOTMAutoText); CPPUNIT_TEST(testDOTMAutoText);
CPPUNIT_TEST(testDOCXAutoTextGallery); CPPUNIT_TEST(testDOCXAutoTextGallery);
CPPUNIT_TEST(testWatermarkDOCX); CPPUNIT_TEST(testWatermarkDOCX);
CPPUNIT_TEST(testWatermarkPosition);
CPPUNIT_TEST(testTdf67238); CPPUNIT_TEST(testTdf67238);
CPPUNIT_TEST(testFdo75110); CPPUNIT_TEST(testFdo75110);
CPPUNIT_TEST(testFdo75898); CPPUNIT_TEST(testFdo75898);
...@@ -901,6 +906,80 @@ void SwUiWriterTest::testWatermarkDOCX() ...@@ -901,6 +906,80 @@ void SwUiWriterTest::testWatermarkDOCX()
CPPUNIT_ASSERT_EQUAL((sal_Int16)50, pWatermark->GetTransparency()); 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() void SwUiWriterTest::testFdo74981()
{ {
// create a document with an input field // create a document with an input field
......
...@@ -530,14 +530,36 @@ void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark) ...@@ -530,14 +530,36 @@ void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark)
if (!bHeaderIsOn) if (!bHeaderIsOn)
xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_ON, uno::makeAny(true)); 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. // If the header already contains a document header field, no need to do anything.
uno::Reference<text::XText> xHeaderText; uno::Reference<text::XText> xHeaderText;
uno::Reference<text::XText> xHeaderTextFirst; uno::Reference<text::XText> xHeaderTextFirst;
uno::Reference<text::XText> xHeaderTextLeft;
uno::Reference<text::XText> xHeaderTextRight;
xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText; xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderText); lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, xHeaderText);
xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT_FIRST) >>= xHeaderTextFirst; xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT_FIRST) >>= xHeaderTextFirst;
lcl_placeWatermarkInHeader(rWatermark, xModel, xPageStyle, 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));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment