sw/qa/filter/ww8/data/floattable-hidden-anchor.doc |binary
 sw/qa/filter/ww8/ww8.cxx                           |   16 ++++++++++++++++
 sw/source/filter/ww8/ww8par6.cxx                   |   16 ++++++++++++++++
 3 files changed, 32 insertions(+)

New commits:
commit 79ddca4def81198e3eee42eca8aca42fef964c80
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Jul 5 08:33:06 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Jul 5 11:56:01 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.
    
    Change-Id: I3a7411e6fcc318740bcbd4b0cde9f34134f384a1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154017
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

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 253317c0deac..20c1b993caa8 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -342,6 +342,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 fbcf566a0897..6619d775bdb8 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -3371,6 +3371,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