sw/qa/extras/layout/data/tdf165094.fodt |  106 ++++++++++++++++++++++++++++++++
 sw/qa/extras/layout/layout5.cxx         |   31 +++++++++
 sw/source/core/layout/flowfrm.cxx       |    5 -
 3 files changed, 138 insertions(+), 4 deletions(-)

New commits:
commit 67308193f6ee8a21b20043fbd3e831a8c455f40a
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon May 26 00:09:06 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon May 26 06:09:17 2025 +0200

    tdf#165094: do not skip empty page because of wrong page descriptor
    
    The problem was, that the layout process created three pages initially,
    with automatic page break before paragraph 26 (that is controlled by
    SwLayHelper::mnMaxParaPerPage and checked in SwLayHelper::CheckInsert),
    and manual page break before the hidden paragraph; then the paragraphs
    26-45 moved back to page 1; and then the content of page 3 attempted
    to move back. Looking for a page to move to (in SwFlowFrame::MoveBwd),
    it found page 2 as the candidate target; but in SwFrame::WrongPageDesc,
    it concluded that the page 2 can't be used (because of different page
    style, or a difference in even/odd/first format). Thus, that page was
    skipped, the content moved to page 1, effectively ignoring the break.
    
    The check in SwFrame::WrongPageDesc, called from SwFlowFrm::MoveBwd,
    was added in commit 84a3db80b4fd66c6854b3135b5f69b61fd828e62 (initial
    import, 2000-09-18). Simultaneously, bCheckPageDescs was set there,
    and the page formats were checked eventually. I think, that skipping
    pages because of wrong page formats is unneeded because of that final
    check; this patch removes the problrmatic conditions.
    
    Change-Id: Ife0b5591c68adb46f7c8fdde0e852e9e326dc38a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185751
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/layout/data/tdf165094.fodt 
b/sw/qa/extras/layout/data/tdf165094.fodt
new file mode 100644
index 000000000000..7060bb9c7e6d
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf165094.fodt
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:font-face-decls>
+  <style:font-face style:name="Liberation Serif" 
svg:font-family="&apos;Liberation Serif&apos;" 
style:font-family-generic="roman" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text">
+   <style:text-properties style:font-name="Liberation Serif" 
fo:font-size="12pt" fo:language="en" fo:country="US"/>
+  </style:style>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard" style:master-page-name="Style1">
+   <style:paragraph-properties style:page-number="5"/>
+   <style:text-properties text:display="none"/>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="210mm" fo:page-height="297mm" 
fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" 
fo:margin-right="2cm"/>
+   <style:header-style>
+    <style:header-footer-properties fo:min-height="1cm" fo:margin-left="0" 
fo:margin-right="0" fo:margin-bottom="5mm"/>
+   </style:header-style>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1">
+   <style:header>
+    <text:p>right</text:p>
+   </style:header>
+   <style:header-left>
+    <text:p>left</text:p>
+   </style:header-left>
+   <style:header-first>
+    <text:p>first</text:p>
+   </style:header-first>
+  </style:master-page>
+  <style:master-page style:name="Style1" style:page-layout-name="pm1">
+   <style:header>
+    <text:p>right (Style1)</text:p>
+   </style:header>
+   <style:header-left>
+    <text:p>left (Style1)</text:p>
+   </style:header-left>
+   <style:header-first>
+    <text:p>first (Style1)</text:p>
+   </style:header-first>
+  </style:master-page>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p>1</text:p>
+   <text:p>2</text:p>
+   <text:p>3</text:p>
+   <text:p>4</text:p>
+   <text:p>5</text:p>
+   <text:p>6</text:p>
+   <text:p>7</text:p>
+   <text:p>8</text:p>
+   <text:p>9</text:p>
+   <text:p>10</text:p>
+   <text:p>11</text:p>
+   <text:p>12</text:p>
+   <text:p>13</text:p>
+   <text:p>14</text:p>
+   <text:p>15</text:p>
+   <text:p>16</text:p>
+   <text:p>17</text:p>
+   <text:p>18</text:p>
+   <text:p>19</text:p>
+   <text:p>20</text:p>
+   <text:p>21</text:p>
+   <text:p>22</text:p>
+   <text:p>23</text:p>
+   <text:p>24</text:p>
+   <text:p>25</text:p>
+   <text:p>26</text:p>
+   <text:p>27</text:p>
+   <text:p>28</text:p>
+   <text:p>29</text:p>
+   <text:p>30</text:p>
+   <text:p>31</text:p>
+   <text:p>32</text:p>
+   <text:p>33</text:p>
+   <text:p>34</text:p>
+   <text:p>35</text:p>
+   <text:p>36</text:p>
+   <text:p>37</text:p>
+   <text:p>38</text:p>
+   <text:p>39</text:p>
+   <text:p>40</text:p>
+   <text:p>41</text:p>
+   <text:p>42</text:p>
+   <text:p>43</text:p>
+   <text:p>44</text:p>
+   <text:p>45</text:p>
+   <text:p text:style-name="P1">hidden paragraph with page break with page 
style and number</text:p>
+   <table:table>
+    <table:table-column/>
+    <table:table-row>
+     <table:table-cell>
+       <text:p>table (must be after page break, on page with style Style1 and 
number 5)</text:p>
+     </table:table-cell>
+    </table:table-row>
+   </table:table>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/layout/layout5.cxx b/sw/qa/extras/layout/layout5.cxx
index 03f403db7aba..ce88823321a9 100644
--- a/sw/qa/extras/layout/layout5.cxx
+++ b/sw/qa/extras/layout/layout5.cxx
@@ -1708,6 +1708,37 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter5, testTdf166652)
     assertXPath(pXmlDoc, "//cell[2]/txt[11]/infos/bounds", "height", u"552");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter5, testTdf165094)
+{
+    // Given a document that:
+    // 1. Has 45 leading paragraphs (more than SwLayHelper::mnMaxParaPerPage);
+    // 2. Has the next paragraph hidden;
+    // 2.1. That hidden paragraph has "page break before with page style";
+    // 2.2. That page style is different than page style used before;
+    // 2.3. That hidden paragraph has "with page number", and the number is 
odd (previous page is
+    //      also odd) - this is actually an alternative to 2.2;
+    // 3. Then immediately goes a table.
+    createSwDoc("tdf165094.fodt");
+    auto pXmlDoc = parseLayoutDump();
+
+    // Check that the page break is created, with correct settings
+
+    assertXPath(pXmlDoc, "//page", 3);
+
+    assertXPath(pXmlDoc, "//page[1]", "formatName", u"Default Page Style");
+    assertXPath(pXmlDoc, "//page[1]/page_info", "virtNum", u"1");
+    assertXPath(pXmlDoc, "//page[1]/body/txt", 45);
+
+    assertXPath(pXmlDoc, "//page[2]/page_info", "virtNum", u"2");
+    assertXPath(pXmlDoc, "//page[2]/infos/bounds", "height", u"0"); // hidden
+    assertXPath(pXmlDoc, "//page[2]/body", 0);
+
+    assertXPath(pXmlDoc, "//page[3]", "formatName", u"Style1");
+    assertXPath(pXmlDoc, "//page[3]/page_info", "virtNum", u"5");
+    assertXPath(pXmlDoc, "//page[3]/body/txt[1]/infos/bounds", "height", 
u"0"); // hidden
+    assertXPath(pXmlDoc, "//page[3]/body/tab", 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/flowfrm.cxx 
b/sw/source/core/layout/flowfrm.cxx
index ead94615e359..2dd081245a96 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -1049,10 +1049,7 @@ bool SwFrame::WrongPageDesc( SwPageFrame* pNew )
               << (isRightPage ? pDesc->GetRightFormat(bFirst) : 
pDesc->GetLeftFormat(bFirst)) << " "
               << (isRightPage ? pDesc->GetLeftFormat(bFirst) : 
pDesc->GetRightFormat(bFirst)) );
 
-    return (pNew->GetPageDesc() != pDesc)   //  own desc ?
-        || (pNew->GetFormat() !=
-              (isRightPage ? pDesc->GetRightFormat(bFirst) : 
pDesc->GetLeftFormat(bFirst)))
-        || (pNewDesc && pNewDesc == pDesc);
+    return (pNewDesc && pNewDesc == pDesc);
 }
 
 /// Returns the next layout leaf in which we can move the frame.

Reply via email to