summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-02-05 09:10:39 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-02-09 17:09:19 +0100
commitc5b0c15f56f3a74612b4808c7ec699c46d7f1e98 (patch)
tree184de6ae48df2bd8c1ebdd26f5f454effd7a4c25
parent9cf6612438a478da3c42de2a2fb83d4b5fdc626e (diff)
tdf#91920 sw page gutter margin, from top: add layout
Take the new doc setting into account and if it's true, then undo the existing "increase left margin" logic, and do an "increase top margin" one instead. (cherry picked from commit 59e816faa2a2bc0b88c39f063c53e00a33f23722) Conflicts: sw/source/core/layout/paintfrm.cxx Change-Id: I358a34790a52e2720ec23e6841d56e66858e28b0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110640 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/qa/core/layout/layout.cxx31
-rw-r--r--sw/source/core/layout/frmtool.cxx22
-rw-r--r--sw/source/core/layout/paintfrm.cxx10
3 files changed, 60 insertions, 3 deletions
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index 63fa7336d263..33642b84776d 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -101,6 +101,37 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testGutterMargin)
CPPUNIT_ASSERT_EQUAL(nGutterTwips, nNewLeft - nOldLeft);
}
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testGutterTopMargin)
+{
+ // Create a document, remember the old top edge of the page print area (the rectangle that is
+ // inside margins).
+ loadURL("private:factory/swriter", nullptr);
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xSettings(
+ xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
+ xSettings->setPropertyValue("GutterAtTop", uno::makeAny(true));
+ uno::Reference<beans::XPropertySet> xStandard(getStyles("PageStyles")->getByName("Standard"),
+ uno::UNO_QUERY);
+ SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+ SwFrame* pPage = pLayout->GetLower();
+ long nOldTop = pPage->getFramePrintArea().Top();
+
+ // Set the gutter margin to 2cm.
+ sal_Int32 nGutterMm100 = 2000;
+ xStandard->setPropertyValue("GutterMargin", uno::makeAny(nGutterMm100));
+
+ // Verify that the new top edge is larger.
+ long nNewTop = pPage->getFramePrintArea().Top();
+ long nGutterTwips = convertMm100ToTwip(nGutterMm100);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1134
+ // - Actual : 0
+ // i.e. the gutter was not added to the left margin.
+ CPPUNIT_ASSERT_EQUAL(nGutterTwips, nNewTop - nOldTop);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index 0d106946cd2b..550e54c05f70 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -2206,6 +2206,18 @@ SwBorderAttrs::~SwBorderAttrs()
void SwBorderAttrs::CalcTop_()
{
m_nTop = CalcTopLine() + m_rUL.GetUpper();
+
+ if (m_rLR)
+ {
+ bool bGutterAtTop = m_rAttrSet.GetDoc()->getIDocumentSettingAccess().get(
+ DocumentSettingId::GUTTER_AT_TOP);
+ if (bGutterAtTop)
+ {
+ // Decrease the print area: the top space is the sum of top and gutter margins.
+ m_nTop += m_rLR->GetGutterMargin();
+ }
+ }
+
m_bTop = false;
}
@@ -2308,8 +2320,14 @@ long SwBorderAttrs::CalcLeft( const SwFrame *pCaller ) const
if (pCaller->IsPageFrame() && m_rLR)
{
- // Decrease the print area: the left space is the sum of left and gutter margins.
- nLeft += m_rLR->GetGutterMargin();
+ const auto pPageFrame = static_cast<const SwPageFrame*>(pCaller);
+ bool bGutterAtTop = pPageFrame->GetFormat()->getIDocumentSettingAccess().get(
+ DocumentSettingId::GUTTER_AT_TOP);
+ if (!bGutterAtTop)
+ {
+ // Decrease the print area: the left space is the sum of left and gutter margins.
+ nLeft += m_rLR->GetGutterMargin();
+ }
}
return nLeft;
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index da8731a400d1..6563256804f9 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -1269,11 +1269,19 @@ static void lcl_CalcBorderRect( SwRect &rRect, const SwFrame *pFrame,
if (pFrame->IsPageFrame() && rAttrs.GetLRSpace())
{
long nGutterMargin = rAttrs.GetLRSpace()->GetGutterMargin();
- if (nGutterMargin)
+ const auto pPageFrame = static_cast<const SwPageFrame*>(pFrame);
+ bool bGutterAtTop = pPageFrame->GetFormat()->getIDocumentSettingAccess().get(
+ DocumentSettingId::GUTTER_AT_TOP);
+ if (nGutterMargin && !bGutterAtTop)
{
// Paint the left border based on the left margin, ignoring the gutter margin.
(rRect.*fnRect->fnSubLeft)(nGutterMargin);
}
+ else if (nGutterMargin)
+ {
+ // Paint the top border based on the top margin, ignoring the gutter margin.
+ (rRect.*fnRect->fnSubTop)(nGutterMargin);
+ }
}
const SvxBoxItem &rBox = rAttrs.GetBox();