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-05 10:02:14 +0100
commit59e816faa2a2bc0b88c39f063c53e00a33f23722 (patch)
tree9f3f6b6f80db988dc9a743665b55bc52ecef04f3
parent8cc78b527bf2b7dcaaff73d8f0770f3d324ac839 (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. Change-Id: I358a34790a52e2720ec23e6841d56e66858e28b0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110454 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sw/qa/core/layout/layout.cxx29
-rw-r--r--sw/source/core/layout/frmtool.cxx22
-rw-r--r--sw/source/core/layout/paintfrm.cxx10
3 files changed, 58 insertions, 3 deletions
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index 77a2db553aa4..ebf7f816b918 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -297,6 +297,35 @@ 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).
+ SwDoc* pDoc = createSwDoc();
+ 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();
+ tools::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.
+ tools::Long nNewTop = pPage->getFramePrintArea().Top();
+ tools::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 6a5fa10cb121..0cac4ad2ca96 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -2217,6 +2217,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;
}
@@ -2318,8 +2330,14 @@ tools::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 2e01551d3876..e941c68988a9 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -1292,11 +1292,19 @@ static void lcl_CalcBorderRect( SwRect &rRect, const SwFrame *pFrame,
if (pFrame->IsPageFrame() && rAttrs.GetLRSpace())
{
tools::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();