sw/qa/extras/rtfimport/data/tdf160553.rtf       |   20 +++++
 sw/qa/extras/rtfimport/rtfimport.cxx            |    8 ++
 sw/source/writerfilter/dmapper/DomainMapper.cxx |   84 ++++++++++++------------
 3 files changed, 71 insertions(+), 41 deletions(-)

New commits:
commit c6803b18d85e8cbd2e76ff0d46e7f4ff2e312916
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Mon Mar 25 16:01:48 2024 +0300
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Fri Oct 25 15:26:29 2024 +0200

    tdf#160553: writerfilter: RTF import: fix problem with first table in 
section
    
    Handles section properties between tables.
    JUnit test included
    
    Change-Id: I1db8b80749d18c0e73112e4fd1d13d6331aa7291
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165286
    Reviewed-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/rtfimport/data/tdf160553.rtf 
b/sw/qa/extras/rtfimport/data/tdf160553.rtf
new file mode 100755
index 000000000000..2e7b26db4e70
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/tdf160553.rtf
@@ -0,0 +1,20 @@
+{ tf1
+
+
+       rowd +\intbl 1+\intbl 2+        rowd + ow
+\pard HELLO\par
+
+\sect\sectd
+
+       rowd +\intbl 1+\intbl 2+        rowd + ow
+\pard
+
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx 
b/sw/qa/extras/rtfimport/rtfimport.cxx
index 4ff36a7f7988..25a93bd2db23 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1942,6 +1942,14 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf152839)
     uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable->getCellNames().getLength());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, test160553Tdf)
+{
+    createSwDoc("tdf160553.rtf");
+    // new section should create second page
+    CPPUNIT_ASSERT_EQUAL(2, getPages());
+}
+
 // tests should only be added to rtfIMPORT *if* they fail round-tripping in 
rtfEXPORT
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper.cxx
index d99ac0c37cb4..8fee3500a043 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx
@@ -1488,6 +1488,49 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const 
PropertyMapPtr& rContext )
         }
         return;
     }
+    case NS_ooxml::LN_tblStart:
+    {
+        if (rContext)
+        {
+            /*
+             * Hack for Importing Section Properties
+             * LO is not able to import section properties if first element in 
the
+             * section is a table. So in case first element is a table add a 
dummy para
+             * and remove it again when lcl_endSectionGroup is called
+             */
+            if (m_pImpl->m_StreamStateStack.top().nTableDepth == 0
+                && m_pImpl->GetIsFirstParagraphInSection()
+                    && !m_pImpl->GetIsDummyParaAddedForTableInSection() && 
!m_pImpl->GetIsTextFrameInserted()
+                    && !m_pImpl->GetIsPreviousParagraphFramed() && 
!IsInHeaderFooter())
+            {
+                m_pImpl->AddDummyParaForTableInSection();
+            }
+
+            // if first paragraph style in table has break-before-page, 
transfer that setting to the table itself.
+            if (m_pImpl->m_StreamStateStack.top().nTableDepth == 0)
+            {
+                const uno::Any aBreakType(style::BreakType_PAGE_BEFORE);
+                const PropertyMapPtr pParagraphProps = 
m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH);
+                if( pParagraphProps && 
pParagraphProps->isSet(PROP_PARA_STYLE_NAME) )
+                {
+                    StyleSheetEntryPtr pStyle;
+                    OUString sStyleName;
+                    pParagraphProps->getProperty(PROP_PARA_STYLE_NAME)->second 
>>= sStyleName;
+                    if( !sStyleName.isEmpty() && GetStyleSheetTable() )
+                        pStyle = 
GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( sStyleName );
+
+                    if( pStyle && pStyle->m_pProperties
+                        && pStyle->m_pProperties->isSet(PROP_BREAK_TYPE)
+                        && 
pStyle->m_pProperties->getProperty(PROP_BREAK_TYPE)->second == aBreakType )
+                    {
+                        pParagraphProps->Insert(PROP_BREAK_TYPE, aBreakType);
+                    }
+                }
+            }
+        }
+        m_pImpl->m_StreamStateStack.top().nTableDepth++;
+        return;
+    }
     default:
         break;
     }
@@ -3394,47 +3437,6 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const 
PropertyMapPtr& rContext )
         }
     }
     break;
-    case NS_ooxml::LN_tblStart:
-    {
-        /*
-         * Hack for Importing Section Properties
-         * LO is not able to import section properties if first element in the
-         * section is a table. So in case first element is a table add a dummy 
para
-         * and remove it again when lcl_endSectionGroup is called
-         */
-        if (m_pImpl->m_StreamStateStack.top().nTableDepth == 0
-            && m_pImpl->GetIsFirstParagraphInSection()
-                && !m_pImpl->GetIsDummyParaAddedForTableInSection() && 
!m_pImpl->GetIsTextFrameInserted()
-                && !m_pImpl->GetIsPreviousParagraphFramed() && 
!IsInHeaderFooter())
-        {
-            m_pImpl->AddDummyParaForTableInSection();
-        }
-
-        // if first paragraph style in table has break-before-page, transfer 
that setting to the table itself.
-        if (m_pImpl->m_StreamStateStack.top().nTableDepth == 0)
-        {
-            const uno::Any aBreakType(style::BreakType_PAGE_BEFORE);
-            const PropertyMapPtr pParagraphProps = 
m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH);
-            if( pParagraphProps && 
pParagraphProps->isSet(PROP_PARA_STYLE_NAME) )
-            {
-                StyleSheetEntryPtr pStyle;
-                OUString sStyleName;
-                pParagraphProps->getProperty(PROP_PARA_STYLE_NAME)->second >>= 
sStyleName;
-                if( !sStyleName.isEmpty() && GetStyleSheetTable() )
-                    pStyle = 
GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( sStyleName );
-
-                if( pStyle && pStyle->m_pProperties
-                    && pStyle->m_pProperties->isSet(PROP_BREAK_TYPE)
-                    && 
pStyle->m_pProperties->getProperty(PROP_BREAK_TYPE)->second == aBreakType )
-                {
-                    pParagraphProps->Insert(PROP_BREAK_TYPE, aBreakType);
-                }
-            }
-        }
-
-        m_pImpl->m_StreamStateStack.top().nTableDepth++;
-    }
-    break;
     case NS_ooxml::LN_tblEnd:
         m_pImpl->m_StreamStateStack.top().nTableDepth--;
     break;

Reply via email to