sw/qa/extras/layout/layout.cxx                     |    1 +
 sw/qa/filter/ww8/data/floattable-hidden-anchor.doc |binary
 sw/qa/filter/ww8/ww8.cxx                           |   16 ++++++++++++++++
 sw/source/filter/ww8/ww8par6.cxx                   |   16 ++++++++++++++++
 4 files changed, 33 insertions(+)

New commits:
commit 47261441fc0fc3f0218cfbb43585b683c3fcc3af
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Jul 5 08:33:06 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Jul 6 14:51:31 2023 +0200

    sw floattable: fix lost floating table right before a table from DOC
    
    The bugdoc has a floating table, anchored in a paragraph that is hidden
    via character formatting. The bugdoc also has a normal table. This leads
    to 1 table in Writer, but 2 tables in Word.
    
    We already have code that tries to make sure floating tables have a
    suitable anchor, see the code in WW8TabDesc::CreateSwTable(), but that
    checks for the case when the next node after a floating table would be
    table (and not text), instead of the hidden character property.
    
    Fix the problem by not creating the hidden char attribute in the first
    place in SwWW8ImplReader::SetToggleAttr() in case the pool item would be
    inserted at the paragraph start and we just inserted a floating table,
    which makes the 2nd table visible in Writer as well.
    
    This is for DOC, interesting when Word converts this document to DOCX,
    then the hidden attribute is removed, so there this is not really needed.
    
    (cherry picked from commit 79ddca4def81198e3eee42eca8aca42fef964c80)
    
    Change-Id: I3a7411e6fcc318740bcbd4b0cde9f34134f384a1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154090
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 021114bd070e..cdca8e858d29 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -3493,6 +3493,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf109137)
         { "FilterName", uno::Any(OUString("writer8")) },
     }));
     xStorable->storeToURL(maTempFile.GetURL(), aDescriptor);
+    mxComponent->dispose();
     mxComponent = loadFromDesktop(maTempFile.GetURL(), 
"com.sun.star.text.TextDocument");
     xmlDocUniquePtr pXmlDoc = parseLayoutDump();
     // This was 0, the blue rectangle moved from the 1st to the 2nd page.
diff --git a/sw/qa/filter/ww8/data/floattable-hidden-anchor.doc 
b/sw/qa/filter/ww8/data/floattable-hidden-anchor.doc
new file mode 100644
index 000000000000..3e8feb876964
Binary files /dev/null and b/sw/qa/filter/ww8/data/floattable-hidden-anchor.doc 
differ
diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index 67d97c72ebe4..7d4c4c2f730a 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -317,6 +317,22 @@ CPPUNIT_TEST_FIXTURE(Test, testDOCfDontBreakWrappedTables)
     // set.
     CPPUNIT_ASSERT(bDontBreakWrappedTables);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testDOCFloatingTableHiddenAnchor)
+{
+    // Given a document with a normal table and a floating table with a hidden 
anchor:
+    createSwDoc("floattable-hidden-anchor.doc");
+
+    // When laying out that document:
+    xmlDocUniquePtr pLayout = parseLayoutDump();
+
+    // Then make sure that both tables are visible:
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 2
+    // - Actual  : 1
+    // i.e. the floating table was lost.
+    assertXPath(pLayout, "//tab", 2);
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 718df35b73a8..e2972105c560 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -3351,6 +3351,22 @@ void SwWW8ImplReader::SetToggleAttr(sal_uInt8 nAttrId, 
bool bOn)
                                              : SvxCaseMap::NotMapped, 
RES_CHRATR_CASEMAP ) );
             break;
         case 7:
+            if (m_pPaM->GetPoint()->GetContentIndex() == 0 && 
m_xFormatOfJustInsertedApo)
+            {
+                // We just inserted a frame and we're at the next paragraph 
start.
+                SwFrameFormat* pFormat = 
m_xFormatOfJustInsertedApo->GetFormat();
+                if (pFormat)
+                {
+                    SwNode* pAnchorNode = pFormat->GetAnchor().GetAnchorNode();
+                    if (pAnchorNode && *pAnchorNode == 
m_pPaM->GetPoint()->GetNode())
+                    {
+                        // The anchor paragraph would be hidden, leading to 
hiding the frame as
+                        // well, prevent that.
+                        break;
+                    }
+                }
+            }
+
             NewAttr(SvxCharHiddenItem(bOn, RES_CHRATR_HIDDEN));
             break;
         case 8:

Reply via email to