[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Feb 3 09:47:02 UTC 2021


 sw/qa/core/layout/layout.cxx       |   25 +++++++++++++++++++++++++
 sw/source/core/inc/frmtool.hxx     |    1 +
 sw/source/core/layout/frmtool.cxx  |    6 ++++++
 sw/source/core/layout/paintfrm.cxx |   10 ++++++++++
 4 files changed, 42 insertions(+)

New commits:
commit b1779452bdf8b4d00791f013945cb9aa12b19723
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Feb 3 09:36:50 2021 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Feb 3 10:46:16 2021 +0100

    tdf#91920 sw page gutter margin: add layout
    
    Handle this in general by decreasing the print area of the page frame,
    that way the position and size of the child frames (header, body, etc)
    will be correct.
    
    One catch is that the page border is independent from the gutter margin
    in Word, so compensate for it in lcl_CalcBorderRect() have matching
    render result. (E.g. 1cm gutter margin, 1cm left and right margins, then
    we would default to drawing the left margin at 2cm from left edge, but
    1cm is wanted.)
    
    Change-Id: I41a697e8230c975e7665a06c7b739df04826e9a2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110339
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index 6fe44dae97b6..77a2db553aa4 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -272,6 +272,31 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testKeepwithnextFullheight)
     assertXPath(pXmlDoc, "//page[2]/body/txt/anchored/fly", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testGutterMargin)
+{
+    // Create a document, remember the old left edge of the page print area (the rectangle that is
+    // inside margins).
+    SwDoc* pDoc = createSwDoc();
+    uno::Reference<beans::XPropertySet> xStandard(getStyles("PageStyles")->getByName("Standard"),
+                                                  uno::UNO_QUERY);
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    SwFrame* pPage = pLayout->GetLower();
+    tools::Long nOldLeft = pPage->getFramePrintArea().Left();
+
+    // Set the gutter margin to 2cm.
+    sal_Int32 nGutterMm100 = 2000;
+    xStandard->setPropertyValue("GutterMargin", uno::makeAny(nGutterMm100));
+
+    // Verify that the new left edge is larger.
+    tools::Long nNewLeft = pPage->getFramePrintArea().Left();
+    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, nNewLeft - nOldLeft);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx
index b1cccfd2af4d..6fbb78fab253 100644
--- a/sw/source/core/inc/frmtool.hxx
+++ b/sw/source/core/inc/frmtool.hxx
@@ -383,6 +383,7 @@ public:
 
     const SwAttrSet      &GetAttrSet() const { return m_rAttrSet;  }
     const SvxULSpaceItem &GetULSpace() const { return m_rUL;       }
+    const std::shared_ptr<SvxLRSpaceItem>& GetLRSpace() const { return m_rLR; }
     const SvxBoxItem     &GetBox()     const { return m_rBox;      }
     const SvxShadowItem  &GetShadow()  const { return m_rShadow;   }
 
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index b0a0e13e9182..6a5fa10cb121 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -2316,6 +2316,12 @@ tools::Long SwBorderAttrs::CalcLeft( const SwFrame *pCaller ) const
         nLeft += static_cast<const SwTextFrame*>(pCaller)->GetTextNodeForParaProps()->GetLeftMarginWithNum();
     }
 
+    if (pCaller->IsPageFrame() && m_rLR)
+    {
+        // 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 9779a81a736e..2e01551d3876 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -1289,6 +1289,16 @@ static void lcl_CalcBorderRect( SwRect &rRect, const SwFrame *pFrame,
 
         SwRectFn fnRect = pFrame->IsVertical() ? ( pFrame->IsVertLR() ? (pFrame->IsVertLRBT() ? fnRectVertL2RB2T : fnRectVertL2R) : fnRectVert ) : fnRectHori;
 
+        if (pFrame->IsPageFrame() && rAttrs.GetLRSpace())
+        {
+            tools::Long nGutterMargin = rAttrs.GetLRSpace()->GetGutterMargin();
+            if (nGutterMargin)
+            {
+                // Paint the left border based on the left margin, ignoring the gutter margin.
+                (rRect.*fnRect->fnSubLeft)(nGutterMargin);
+            }
+        }
+
         const SvxBoxItem &rBox = rAttrs.GetBox();
         const bool bTop = 0 != (pFrame->*fnRect->fnGetTopMargin)();
         if ( bTop )


More information about the Libreoffice-commits mailing list