sw/inc/paratr.hxx                                |    2 
 sw/qa/extras/pagelinespacing/pagelinespacing.cxx |  160 ++++++++++++++++++++---
 2 files changed, 147 insertions(+), 15 deletions(-)

New commits:
commit 9c56e440d80b74a8a2ffe22264f64d5a8f2ea361
Author:     Tamás Zolnai <[email protected]>
AuthorDate: Tue Jan 27 16:42:42 2026 +0100
Commit:     Tamás Zolnai <[email protected]>
CommitDate: Wed Jan 28 12:18:18 2026 +0100

    Add more unit tests for page line-spacing.
    
    Change-Id: I63ade0bac061925f667f1384181e328db718f6bf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198228
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <[email protected]>

diff --git a/sw/inc/paratr.hxx b/sw/inc/paratr.hxx
index 77931bc207ad..d686f2fb86ef 100644
--- a/sw/inc/paratr.hxx
+++ b/sw/inc/paratr.hxx
@@ -134,7 +134,7 @@ public:
             { m_pDefinedIn = const_cast<sw::FormatDropDefiner*>(pDefiner); };
 };
 
-class SwRegisterItem final : public SfxBoolItem
+class SW_DLLPUBLIC SwRegisterItem final : public SfxBoolItem
 {
 public:
     static SfxPoolItem* CreateDefault();
diff --git a/sw/qa/extras/pagelinespacing/pagelinespacing.cxx 
b/sw/qa/extras/pagelinespacing/pagelinespacing.cxx
index ca3429353d5a..e186a73321dc 100644
--- a/sw/qa/extras/pagelinespacing/pagelinespacing.cxx
+++ b/sw/qa/extras/pagelinespacing/pagelinespacing.cxx
@@ -37,8 +37,12 @@ protected:
     void applyPageLineSpacing(const uint16_t nPage, const bool bEnable,
                               const OUString& rReferenceStyle);
 
+    void applyPageLineSpacing(const OUString& rParagraphStyle);
+
     Size getTextFrameSize(const uint16_t nTextFrame, const OUString& 
rTextContent);
 
+    void setLineHeightForReferenceStyle(const uint16_t nPage, const sal_uInt16 
nLineHeight);
+
 private:
     void checkTextAlignedToBaselineGrid(SwTextFrame* pTextFrame, const bool 
bAligned);
 };
@@ -156,6 +160,38 @@ void SwPageLineSpacingTest::applyPageLineSpacing(const 
uint16_t nPage, const boo
     calcLayout();
 }
 
+void SwPageLineSpacingTest::applyPageLineSpacing(const OUString& 
rParagraphStyle)
+{
+    SwDocShell* pDocShell = getSwDocShell();
+    CPPUNIT_ASSERT(pDocShell);
+
+    SwDoc* pDoc = pDocShell->GetDoc();
+    CPPUNIT_ASSERT(pDoc);
+
+    // Enable page line-spacing for the given paragraph style.
+    {
+        SwTextFormatColl* pTextFormat = 
pDoc->FindTextFormatCollByName(UIName(rParagraphStyle));
+        CPPUNIT_ASSERT(pTextFormat);
+
+        const SwAttrSet& rAttrSet = pTextFormat->GetAttrSet();
+        SwRegisterItem aRegisterItem = rAttrSet.GetRegister();
+        aRegisterItem.SetValue(true);
+        CPPUNIT_ASSERT_EQUAL(true, aRegisterItem.GetValue());
+
+        std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone();
+        pNewSet->Put(aRegisterItem);
+        pDoc->ChgFormat(*pTextFormat, *pNewSet);
+        calcLayout();
+    }
+
+    // Verify the paragraph style was updated properly.
+    {
+        SwTextFormatColl* pTextFormat = 
pDoc->FindTextFormatCollByName(UIName(rParagraphStyle));
+        const SwAttrSet& rAttrSet = pTextFormat->GetAttrSet();
+        CPPUNIT_ASSERT_EQUAL(true, rAttrSet.GetRegister().GetValue());
+    }
+}
+
 Size SwPageLineSpacingTest::getTextFrameSize(const uint16_t nTextFrame,
                                              const OUString& rTextContent)
 {
@@ -205,6 +241,79 @@ Size SwPageLineSpacingTest::getTextFrameSize(const 
uint16_t nTextFrame,
     return { 0, 0 };
 }
 
+void SwPageLineSpacingTest::setLineHeightForReferenceStyle(const uint16_t 
nPage,
+                                                           const sal_uInt16 
nLineHeight)
+{
+    SwDocShell* pDocShell = getSwDocShell();
+    CPPUNIT_ASSERT(pDocShell);
+
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+
+    SwDoc* pDoc = pDocShell->GetDoc();
+    CPPUNIT_ASSERT(pDoc);
+
+    SwFrame* pNextFrame = pWrtShell->GetLayout();
+    while (pNextFrame)
+    {
+        if (pNextFrame->IsPageFrame())
+        {
+            uint16_t nCurrentPage = 1;
+            while (pNextFrame)
+            {
+                // Find the correct page.
+                if (nCurrentPage == nPage)
+                {
+                    CPPUNIT_ASSERT(pNextFrame->IsPageFrame());
+                    auto pPageFrame = dynamic_cast<SwPageFrame*>(pNextFrame);
+                    CPPUNIT_ASSERT(pPageFrame);
+                    SwPageDesc* pPageDesc = pPageFrame->GetPageDesc();
+                    CPPUNIT_ASSERT(pPageDesc);
+                    // Modify the reference style of the given page style.
+                    {
+                        const SwTextFormatColl* pRegisterFormat
+                            = pPageDesc->GetRegisterFormatColl();
+                        CPPUNIT_ASSERT(pRegisterFormat);
+                        SwTextFormatColl* pTextFormat
+                            = 
pDoc->FindTextFormatCollByName(pRegisterFormat->GetName());
+                        CPPUNIT_ASSERT(pTextFormat);
+
+                        const SwAttrSet& rAttrSet = pTextFormat->GetAttrSet();
+                        SvxLineSpacingItem aLineSpacingItem = 
rAttrSet.GetLineSpacing();
+                        aLineSpacingItem.SetLineHeight(nLineHeight);
+                        
aLineSpacingItem.SetLineSpaceRule(SvxLineSpaceRule::Fix);
+                        CPPUNIT_ASSERT_EQUAL(nLineHeight, 
aLineSpacingItem.GetLineHeight());
+                        CPPUNIT_ASSERT_EQUAL(SvxLineSpaceRule::Fix,
+                                             
aLineSpacingItem.GetLineSpaceRule());
+
+                        std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone();
+                        pNewSet->Put(aLineSpacingItem);
+                        pDoc->ChgFormat(*pTextFormat, *pNewSet);
+                    }
+
+                    // Verify the reference style was updated properly.
+                    {
+                        const SwTextFormatColl* pRegisterFormat
+                            = pPageDesc->GetRegisterFormatColl();
+                        CPPUNIT_ASSERT(pRegisterFormat);
+                        const SwAttrSet& rAttrSet = 
pRegisterFormat->GetAttrSet();
+                        const SvxLineSpacingItem& aLineSpacingItem = 
rAttrSet.GetLineSpacing();
+                        CPPUNIT_ASSERT_EQUAL(nLineHeight, 
aLineSpacingItem.GetLineHeight());
+                        CPPUNIT_ASSERT_EQUAL(SvxLineSpaceRule::Fix,
+                                             
aLineSpacingItem.GetLineSpaceRule());
+                    }
+                    break;
+                }
+                pNextFrame = pNextFrame->GetNext();
+                nCurrentPage += 1;
+            };
+            break;
+        }
+        pNextFrame = pNextFrame->GetLower();
+    };
+    calcLayout();
+}
+
 void SwPageLineSpacingTest::checkTextAlignedToBaselineGrid(SwTextFrame* 
pTextFrame,
                                                            const bool bAligned)
 {
@@ -284,13 +393,6 @@ CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, 
testMultiplePages)
     checkTextAlignedToBaselineGrid();
 }
 
-CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, 
testPageLineSpacingDisabledParagraph)
-{
-    createSwDoc("pageLineSpacingDisabledParagraph.fodt");
-
-    checkTextAlignedToBaselineGrid(false);
-}
-
 CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, testDoubleLineSpacing)
 {
     createSwDoc("doubleLineSpacing.fodt");
@@ -356,13 +458,6 @@ CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, 
testPageColumns)
     checkTextAlignedToBaselineGrid();
 }
 
-CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, testTableWithTopAlignment)
-{
-    createSwDoc("tableWithTopAlignment.fodt");
-
-    checkTextAlignedToBaselineGrid();
-}
-
 /* This use case does not work properly (tdf#93785)
 CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, testTextFrame)
 {
@@ -481,6 +576,43 @@ CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, 
testVerticalPageStyle)
     CPPUNIT_ASSERT_EQUAL(aOriginalSize, getTextFrameSize(1, 
u"RightToLeft"_ustr));
 }
 
+CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, testApplyPageLineSpacingOnTable)
+{
+    createSwDoc("tableWithTopAlignment.fodt");
+
+    checkTextAlignedToBaselineGrid();
+
+    applyPageLineSpacing(1, false, "");
+
+    checkTextAlignedToBaselineGrid(false);
+
+    applyPageLineSpacing(1, true, u"Body Text"_ustr);
+
+    checkTextAlignedToBaselineGrid();
+}
+
+CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, 
testActivatePageLineSpacingForParagraphStyle)
+{
+    createSwDoc("pageLineSpacingDisabledParagraph.fodt");
+
+    checkTextAlignedToBaselineGrid(false);
+
+    applyPageLineSpacing(u"Title"_ustr);
+
+    checkTextAlignedToBaselineGrid();
+}
+
+CPPUNIT_TEST_FIXTURE(SwPageLineSpacingTest, testModifyReferenceStyle)
+{
+    createSwDoc("multipleParagraphs.fodt");
+
+    checkTextAlignedToBaselineGrid();
+
+    setLineHeightForReferenceStyle(1, 400);
+
+    checkTextAlignedToBaselineGrid();
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 

Reply via email to