sw/CppunitTest_sw_ooxmlexport25.mk                              |   18 +++
 sw/Module_sw.mk                                                 |    1 
 sw/qa/extras/ooxmlexport/data/tdf166544_noTopMargin_fields.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport25.cxx                      |   49 
++++++++++
 sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx            |    2 
 5 files changed, 70 insertions(+)

New commits:
commit a993c7849f0cc43c05ea8a505e38b44badc7539c
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Thu May 15 17:10:54 2025 -0400
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri May 16 09:09:13 2025 +0200

    tdf#166544 writerfilter page break: field-end counts as a character run
    
    For compat14, page breaks that are not the first run
    do not apply the top margin after the page break.
    That makes sense. The top margin has already been applied
    before the break.
    
    The end marker of a field (ToC, legacy text form field, hyperlinks...)
    must be treated as one of these character runs,
    since MS Word doesn't apply the top margn in these instances.
    
    The bug report contains examples for ToC and formfield,
    so I used the hyperlink example as my unit test.
    
    make CppunitTest_sw_ooxmlexport25 \
        CPPUNIT_TEST_NAME=testTdf166544_noTopMargin_fields
    
    Change-Id: Ia3efced0d301c2345667937521beb8e7c895d326
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185375
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185378
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/CppunitTest_sw_ooxmlexport25.mk 
b/sw/CppunitTest_sw_ooxmlexport25.mk
new file mode 100644
index 000000000000..a02541c92ad5
--- /dev/null
+++ b/sw/CppunitTest_sw_ooxmlexport25.mk
@@ -0,0 +1,18 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call sw_ooxmlexport_test,25))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_ooxmlexport25,\
+    officecfg/registry \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 19fecbe6d9cf..71117fd246af 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -100,6 +100,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_ooxmlexport20 \
     CppunitTest_sw_ooxmlexport21 \
     CppunitTest_sw_ooxmlexport22 \
+    CppunitTest_sw_ooxmlexport25 \
     CppunitTest_sw_ooxmlexport_template \
     CppunitTest_sw_ooxmlfieldexport \
     CppunitTest_sw_ooxmllinks \
diff --git a/sw/qa/extras/ooxmlexport/data/tdf166544_noTopMargin_fields.docx 
b/sw/qa/extras/ooxmlexport/data/tdf166544_noTopMargin_fields.docx
new file mode 100644
index 000000000000..3070ef81977c
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf166544_noTopMargin_fields.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
new file mode 100644
index 000000000000..cf48755a7765
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <com/sun/star/beans/XPropertyState.hpp>
+
+#include <comphelper/configuration.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <officecfg/Office/Common.hxx>
+
+#include <pam.hxx>
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+#include <IDocumentSettingAccess.hxx>
+
+namespace
+{
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase(u"/sw/qa/extras/ooxmlexport/data/"_ustr, u"Office 
Open XML Text"_ustr)
+    {
+    }
+};
+
+DECLARE_OOXMLEXPORT_TEST(testTdf166544_noTopMargin_fields, 
"tdf166544_noTopMargin_fields.docx")
+{
+    // given a document with a hyperlink field containing a page break
+    auto pXmlDoc = parseLayoutDump();
+
+    // The top margin is applied before the page break - since the page break 
follows the field end
+    sal_Int32 nHeight = getXPath(pXmlDoc, "//page[2]//txt/infos/bounds", 
"height").toInt32();
+    // Without the fix, the text height (showing a large top margin) was 569
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(269), nHeight);
+}
+
+} // end of anonymous namespace
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index 12180b0988f2..743b9bdcf8a5 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -9107,6 +9107,8 @@ void DomainMapper_Impl::PopFieldContext()
                         }
                     }
                 }
+
+                SetIsFirstRun(false); // the end marker counts as a run - 
affecting page breaks
             }
             catch(const lang::IllegalArgumentException&)
             {

Reply via email to