sw/qa/extras/ooxmlexport/ooxmlexport14.cxx               |    9 ++++-
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |   26 +++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

New commits:
commit 41f4e472a6bb76976164e5a6e975b111d954cd95
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Jul 6 08:13:40 2023 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Jul 11 11:34:38 2023 +0200

    tdf#156059 sw floattable: fix lost 0 bottom margin of anchor in ftn from 
DOCX
    
    The bottom margin of floating table anchor paragraph in the footnotes
    was non-zero, which meant that the document had 2 pages in Writer, but
    only 1 in Word.
    
    What happened here is that commit
    d1ac8df139a2a65db45d1970ccc0b80e17d827f6 (tdf#146346 DOCX import: fix
    table margins in footnotes, 2022-05-03) fixed this, but only for the
    case when the floating table conversion was delayed and not in the
    instant conversion case. Then later commit
    c50bf5a5daaae3d40f89ea0784a75a8a571c208d (sw floattable: remove no
    longer needed DOCX import heuristics, 2023-04-12) made all floating
    table conversions instant, so the problem was re-introduced.
    
    Fix the problem by now fixing the problem in
    DomainMapperTableHandler::endTable(), restoring code that was removed
    from SectionPropertyMap::CloseSectionGroup().
    
    There was a disabled testcase for this, so just enable that.
    
    (cherry picked from commit 9ac864159b241d2093e86f664ab6f4b76c69196d)
    
    Change-Id: Ifb7c8fe2bdc70625d3e334cea0893b8e563664ea
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154238
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 5cc20d556853..805c75d5daf5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -1356,8 +1356,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf146346, "tdf146346.docx")
     assertXPath(pXmlDoc, "/root/page[1]//anchored/fly", 8);
     assertXPath(pXmlDoc, "/root/page[1]//anchored/fly/tab", 8);
 
-    // FIXME no second page (regression since multi-page floating tables?)
-    //assertXPath(pXmlDoc, "/root/page[2]", 0);
+    // No second page.
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 0
+    // - Actual  : 1
+    // i.e. unwanted lower margin in the floating table's anchor paragraph in 
the footnote created a
+    // second page.
+    assertXPath(pXmlDoc, "/root/page[2]", 0);
 }
 #endif
 
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx 
b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 53c7c161743d..635f9ab94a93 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -1620,6 +1620,32 @@ void DomainMapperTableHandler::endTable(unsigned int 
nestedTableLevel, bool bTab
                 uno::Reference<text::XTextContent> xContent = 
xTextAppendAndConvert->convertToTextFrame(xStart, xEnd, 
comphelper::containerToSequence(aFrameProperties));
                 xFrameAnchor.set(xContent->getAnchor(), uno::UNO_QUERY);
 
+                bool bConvertToFloatingInFootnote = false;
+                if (xContent.is() && xContent->getAnchor().is())
+                {
+                    uno::Reference<lang::XServiceInfo> 
xText(xContent->getAnchor()->getText(), uno::UNO_QUERY);
+                    if (xText.is())
+                    {
+                        bConvertToFloatingInFootnote = 
xText->supportsService("com.sun.star.text.Footnote");
+                    }
+                }
+
+                // paragraph of the anchoring point of the floating table 
needs zero top and bottom
+                // margins, if the table was a not floating table in the 
footnote, otherwise
+                // docDefault margins could result bigger vertical spaces 
around the table
+                if ( bConvertToFloatingInFootnote && xContent.is() )
+                {
+                    uno::Reference<beans::XPropertySet> xParagraph(
+                                    xContent->getAnchor(), uno::UNO_QUERY);
+                    if ( xParagraph.is() )
+                    {
+                        xParagraph->setPropertyValue("ParaTopMargin",
+                                    uno::Any(static_cast<sal_Int32>(0)));
+                        xParagraph->setPropertyValue("ParaBottomMargin",
+                                    uno::Any(static_cast<sal_Int32>(0)));
+                    }
+                }
+
                 AfterConvertToTextFrame(m_rDMapper_Impl, aFramedRedlines, 
redPos, redLen, redCell, redTable);
             }
 

Reply via email to