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
This commit is contained in:
Miklos Vajna 2021-02-05 09:10:39 +01:00
parent 8cc78b527b
commit 59e816faa2
3 changed files with 58 additions and 3 deletions

View File

@ -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: */

View File

@ -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;

View File

@ -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();