[Libreoffice] Fix RTF export incorrect output with nested tables

Miklos Vajna vmiklos at frugalware.org
Thu Oct 14 03:58:35 PDT 2010


Hi Cedric,

See attached patch, it fixes exporting the

http://cgit.freedesktop.org/~vmiklos/ooo-gsoc/tree/writer/hallenverzeichnis_2003.odt?h=ooo-test-files

test file - before the fix, only the first column was visible in Word.

OK to push?

Thanks.
-------------- next part --------------
From c0e4c1a4c7949a756051a96bab19e5fb0e3b9fae Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos at frugalware.org>
Date: Thu, 14 Oct 2010 12:53:40 +0200
Subject: [PATCH] RTF: stacked fix for nested tables

When the first cell of a table contains an other table, the definition of the
outer table has to be written after the inner table. Introduce a stack to
handle this.
---
 sw/source/filter/ww8/rtfattributeoutput.cxx |   36 +++++++++++++++++++++++---
 sw/source/filter/ww8/rtfattributeoutput.hxx |   15 +++++++++++
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index a2931fe..e7338cd 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -299,8 +299,7 @@ void RtfAttributeOutput::StartParagraph( ww8::WW8TableNodeInfo::Pointer_t pTextN
                 {
                     ww8::WW8TableNodeInfoInner::Pointer_t pInner( pTextNodeInfo->getInnerForDepth( nDepth ) );
 
-                    delete m_pTableWrt, m_pTableWrt = NULL;
-
+                    m_bLastTable = (nDepth == pTextNodeInfo->getDepth());
                     StartTable( pInner );
                     StartTableRow( pInner );
                     StartTableCell( pInner );
@@ -565,6 +564,7 @@ void RtfAttributeOutput::TableInfoCell( ww8::WW8TableNodeInfoInner::Pointer_t /*
         m_aStyles.append(OOO_STRING_SVTOOLS_RTF_ITAP);
         m_aStyles.append((sal_Int32)m_nTableDepth);
     }
+    m_bWroteCellInfo = true;
 }
 
 void RtfAttributeOutput::TableInfoRow( ww8::WW8TableNodeInfoInner::Pointer_t /*pTableTextNodeInfo*/ )
@@ -904,7 +904,8 @@ void RtfAttributeOutput::StartTable( ww8::WW8TableNodeInfoInner::Pointer_t /*pTa
 {
     OSL_TRACE("%s", OSL_THIS_FUNC);
 
-    /* noop */
+    // To trigger calling InitTableHelper()
+    delete m_pTableWrt, m_pTableWrt = NULL;
 }
 
 void RtfAttributeOutput::StartTableRow( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner )
@@ -914,6 +915,9 @@ void RtfAttributeOutput::StartTableRow( ww8::WW8TableNodeInfoInner::Pointer_t pT
 
     TableDefinition(pTableTextNodeInfoInner);
 
+    if (!m_bLastTable)
+        m_aTables.push_back(m_aRowDefs.makeStringAndClear());
+
     // We'll write the table definition for nested tables later
     if ( nCurrentDepth > 1 )
         return;
@@ -940,6 +944,12 @@ void RtfAttributeOutput::EndTableCell( )
 {
     OSL_TRACE("%s, (depth is %d)", OSL_THIS_FUNC, (int)m_nTableDepth);
 
+    if (!m_bWroteCellInfo)
+    {
+        m_aAfterRuns.append(OOO_STRING_SVTOOLS_RTF_INTBL);
+        m_aAfterRuns.append(OOO_STRING_SVTOOLS_RTF_ITAP);
+        m_aAfterRuns.append((sal_Int32)m_nTableDepth);
+    }
     if ( m_nTableDepth > 1 )
         m_aAfterRuns.append(OOO_STRING_SVTOOLS_RTF_NESTCELL);
     else
@@ -947,6 +957,7 @@ void RtfAttributeOutput::EndTableCell( )
 
     m_bTableCellOpen = false;
     m_bTblAfterCell = true;
+    m_bWroteCellInfo = false;
 }
 
 void RtfAttributeOutput::EndTableRow( )
@@ -956,11 +967,24 @@ void RtfAttributeOutput::EndTableRow( )
     if ( m_nTableDepth > 1 )
     {
         m_aAfterRuns.append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_NESTTABLEPROPRS);
-        m_aAfterRuns.append(m_aRowDefs.makeStringAndClear());
+        if (m_aRowDefs.getLength() > 0)
+            m_aAfterRuns.append(m_aRowDefs.makeStringAndClear());
+        else if (m_aTables.size() > 0)
+        {
+            m_aAfterRuns.append(m_aTables.back());
+            m_aTables.pop_back();
+        }
         m_aAfterRuns.append(OOO_STRING_SVTOOLS_RTF_NESTROW "}" "{" OOO_STRING_SVTOOLS_RTF_NONESTTABLES OOO_STRING_SVTOOLS_RTF_PAR "}");
     }
     else
+    {
+        if (m_aTables.size() > 0)
+        {
+            m_aAfterRuns.append(m_aTables.back());
+            m_aTables.pop_back();
+        }
         m_aAfterRuns.append(OOO_STRING_SVTOOLS_RTF_ROW).append(OOO_STRING_SVTOOLS_RTF_PARD);
+    }
 }
 
 void RtfAttributeOutput::EndTable()
@@ -2964,7 +2988,9 @@ RtfAttributeOutput::RtfAttributeOutput( RtfExport &rExport )
     m_bTblAfterCell( false ),
     m_nColBreakNeeded( false ),
     m_bBufferSectionBreaks( false ),
-    m_bBufferSectionHeaders( false )
+    m_bBufferSectionHeaders( false ),
+    m_bLastTable( true ),
+    m_bWroteCellInfo( false )
 {
     OSL_TRACE("%s", OSL_THIS_FUNC);
 }
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index cdbc6c6..c57b4d9 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -539,6 +539,21 @@ private:
     bool m_bBufferSectionHeaders;
     rtl::OStringBuffer m_aSectionHeaders;
 
+    /*
+     * Support for starting multiple tables at the same cell.
+     * If the current table is the last started one.
+     */
+    bool m_bLastTable;
+    /*
+     * List of already started but not yet defined tables (need to be defined
+     * after the nested tables).
+     */
+    std::vector< rtl::OString > m_aTables;
+    /*
+     * If cell info is already output.
+     */
+    bool m_bWroteCellInfo;
+
 public:
     RtfAttributeOutput( RtfExport &rExport );
 
-- 
1.7.2.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20101014/ecb0b3e0/attachment.pgp>


More information about the LibreOffice mailing list