sw/qa/extras/layout/data/wideBoxInFootnote.fodt |   24 ++++++++++++++++++++
 sw/qa/extras/layout/layout3.cxx                 |   28 ++++++++++++++++++++++++
 sw/source/core/text/itrform2.cxx                |    2 +
 3 files changed, 54 insertions(+)

New commits:
commit 46cf6d3f899fbab7524085597483feeb6f5d6cd9
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Apr 13 23:50:07 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Apr 14 19:34:28 2023 +0200

    tdf#138124: do not reset IsFootnoteDone status in line layout
    
    Similar to IsNumDone
    
    Change-Id: I64c713148b613ca1db4a30cde13bec5a6744accc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150378
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/layout/data/wideBoxInFootnote.fodt 
b/sw/qa/extras/layout/data/wideBoxInFootnote.fodt
new file mode 100644
index 000000000000..f63eaa6fa621
--- /dev/null
+++ b/sw/qa/extras/layout/data/wideBoxInFootnote.fodt
@@ -0,0 +1,24 @@
+<?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:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Footnote">
+   <style:paragraph-properties fo:orphans="2"/>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="21cm" fo:page-height="297mm" 
style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" 
fo:margin-left="2cm" fo:margin-right="2cm"/>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p><text:note 
text:note-class="footnote"><text:note-citation>1</text:note-citation>
+     <text:note-body>
+      <text:p text:style-name="P1"><draw:rect text:anchor-type="as-char" 
svg:width="18cm" svg:height="3mm"/></text:p>
+     </text:note-body>
+    </text:note></text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index 62cb65e2ccd3..824e51b4c710 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -1574,6 +1574,34 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testTdf54465_ColumnsWithFootnoteDoNotOccup
     assertXPath(pXmlDoc, "/root/page", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf138124)
+{
+    // When the only portion after the footnote number is a FlyCnt, and it 
doesn't fit into
+    // the page width, it should be moved to the next line without the 
footnote number, and
+    // not loop, nor OOM, nor fail assertions.
+
+    createSwDoc("wideBoxInFootnote.fodt");
+    Scheduler::ProcessEventsToIdle();
+
+    // Without the fix in place, the layout would loop, creating new 
FootnoteNum portions
+    // indefinitely, until OOM.
+    // If the footnote paragraph had no orphan control, then the loop would 
finally end,
+    // but an assertion in SwTextPainter::DrawTextLine would fail during paint.
+
+    xmlDocUniquePtr pXml = parseLayoutDump();
+    assertXPath(pXml, "/root/page", 1);
+    assertXPath(pXml, "/root/page/ftncont/ftn/txt/anchored", 1);
+
+    // And finally, if there were no assertion in SwTextPainter::DrawTextLine, 
it would have
+    // produced multiple lines with FootnoteNum portions, failing the 
following check like
+    // - Expected: 1
+    // - Actual  : 49
+
+    assertXPath(pXml,
+                
"/root/page/ftncont/ftn/txt//SwFieldPortion[@type='PortionType::FootnoteNum']", 
1);
+    assertXPath(pXml, 
"/root/page/ftncont/ftn/txt//SwLinePortion[@type='PortionType::FlyCnt']", 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index a6a8229721d0..f4cbe364ebe6 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1914,6 +1914,7 @@ TextFrameIndex SwTextFormatter::FormatLine(TextFrameIndex 
const nStartPos)
 
         // These values must not be reset by FormatReset();
         const bool bOldNumDone = GetInfo().IsNumDone();
+        const bool bOldFootnoteDone = GetInfo().IsFootnoteDone();
         const bool bOldArrowDone = GetInfo().IsArrowDone();
         const bool bOldErgoDone = GetInfo().IsErgoDone();
 
@@ -1921,6 +1922,7 @@ TextFrameIndex SwTextFormatter::FormatLine(TextFrameIndex 
const nStartPos)
         FormatReset( GetInfo() );
 
         GetInfo().SetNumDone( bOldNumDone );
+        GetInfo().SetFootnoteDone(bOldFootnoteDone);
         GetInfo().SetArrowDone( bOldArrowDone );
         GetInfo().SetErgoDone( bOldErgoDone );
 

Reply via email to