[Libreoffice-commits] .: Branch 'libreoffice-3-5' - writerfilter/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Thu Jan 5 15:55:22 PST 2012


 writerfilter/source/dmapper/DomainMapperTableManager.cxx |   38 +++++++++++++--
 writerfilter/source/dmapper/DomainMapperTableManager.hxx |    3 -
 writerfilter/source/dmapper/DomainMapper_Impl.hxx        |    2 
 writerfilter/source/rtftok/rtfdocumentimpl.cxx           |   11 ----
 writerfilter/source/rtftok/rtfdocumentimpl.hxx           |    2 
 5 files changed, 38 insertions(+), 18 deletions(-)

New commits:
commit 4b6f8b09e6823dfb237a4b9ea5c2abc21ccf030a
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Fri Jan 6 00:36:18 2012 +0100

    fdo#44053 fix RTF import of implicit horizontal table cell merges
    
    (cherry picked from commit 01292f171cc851ba092510f10a97cd293670829e)

diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
index 3bfb463..31d46bd 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
@@ -48,7 +48,7 @@ using namespace ::com::sun::star;
 using namespace ::std;
 
 
-DomainMapperTableManager::DomainMapperTableManager(bool bOOXML) :
+DomainMapperTableManager::DomainMapperTableManager(bool bOOXML, bool bImplicitMerges) :
     m_nRow(0),
     m_nCell(0),
     m_nGridSpan(1),
@@ -56,6 +56,7 @@ DomainMapperTableManager::DomainMapperTableManager(bool bOOXML) :
     m_nHeaderRepeat(0),
     m_nTableWidth(0),
     m_bOOXML( bOOXML ),
+    m_bImplicitMerges(bImplicitMerges),
     m_pTablePropsHandler( new TablePropertiesHandler( bOOXML ) )
 {
     m_pTablePropsHandler->SetTableManager( this );
@@ -437,12 +438,12 @@ void DomainMapperTableManager::endOfRowAction()
     for( ; aGridSpanIter != pCurrentSpans->end(); ++aGridSpanIter)
         nGrids += *aGridSpanIter;
 
+    //determine table width
+    double nFullWidth = m_nTableWidth;
+    //the positions have to be distibuted in a range of 10000
+    const double nFullWidthRelative = 10000.;
     if( pTableGrid->size() == nGrids )
     {
-        //determine table width
-        double nFullWidth = m_nTableWidth;
-        //the positions have to be distibuted in a range of 10000
-        const double nFullWidthRelative = 10000.;
         uno::Sequence< text::TableColumnSeparator > aSeparators( m_nCell - 1 );
         text::TableColumnSeparator* pSeparators = aSeparators.getArray();
         sal_Int16 nLastRelPos = 0;
@@ -476,6 +477,33 @@ void DomainMapperTableManager::endOfRowAction()
 #endif
         insertRowProps(pPropMap);
     }
+    else if (m_bImplicitMerges)
+    {
+        // More grid than cells definitions? Then take the last ones.
+        // This feature is used by the RTF implicit horizontal cell merges.
+        uno::Sequence< text::TableColumnSeparator > aSeparators(m_nCell - 1);
+        text::TableColumnSeparator* pSeparators = aSeparators.getArray();
+
+        sal_Int16 nSum = 0;
+        sal_uInt32 nPos = 0;
+        // Ignoring the i=0 case means we assume that the width of the last cell matches the table width
+        for (int i = m_nCell; i > 1; i--)
+        {
+            nSum += (*pTableGrid.get())[pTableGrid->size() - i]; // Size of the current cell
+            pSeparators[nPos].Position = nSum * nFullWidthRelative / nFullWidth; // Relative position
+            pSeparators[nPos].IsVisible = sal_True;
+            nPos++;
+        }
+
+        TablePropertyMapPtr pPropMap( new TablePropertyMap );
+        pPropMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, false, uno::makeAny( aSeparators ) );
+#ifdef DEBUG_DOMAINMAPPER
+        dmapper_logger->startElement("rowProperties");
+        pPropMap->dumpXml( dmapper_logger );
+        dmapper_logger->endElement();
+#endif
+        insertRowProps(pPropMap);
+    }
 
     ++m_nRow;
     m_nCell = 0;
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx
index 6b20f02..67aeb74 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.hxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx
@@ -50,6 +50,7 @@ class DomainMapperTableManager : public DomainMapperTableManager_Base_t
     sal_Int32       m_nHeaderRepeat; //counter of repeated headers - if == -1 then the repeating stops
     sal_Int32       m_nTableWidth; //might be set directly or has to be calculated from the column positions
     bool            m_bOOXML;
+    bool            m_bImplicitMerges;
     ::rtl::OUString m_sTableStyleName;
     PropertyMapPtr  m_pTableStyleTextProperies;
 
@@ -63,7 +64,7 @@ class DomainMapperTableManager : public DomainMapperTableManager_Base_t
 
 public:
 
-    DomainMapperTableManager(bool bOOXML);
+    DomainMapperTableManager(bool bOOXML, bool bImplicitMerges);
     virtual ~DomainMapperTableManager();
 
     // use this method to avoid adding the properties for the table
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index d7d0546..c4899cb 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -546,7 +546,7 @@ public:
     void appendTableManager( )
     {
         boost::shared_ptr< DomainMapperTableManager > pMngr(
-                new DomainMapperTableManager( m_eDocumentType == DOCUMENT_OOXML || m_eDocumentType == DOCUMENT_RTF ) );
+                new DomainMapperTableManager( m_eDocumentType == DOCUMENT_OOXML || m_eDocumentType == DOCUMENT_RTF, m_eDocumentType == DOCUMENT_RTF ) );
         m_aTableManagers.push( pMngr );
     }
 
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 3a3469e..02a6cef 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -262,7 +262,6 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
     m_aFontIndexes(),
     m_aColorTable(),
     m_bFirstRun(true),
-    m_bFirstRow(true),
     m_bNeedPap(true),
     m_bNeedCr(false),
     m_bNeedPar(true),
@@ -454,8 +453,6 @@ void RTFDocumentImpl::parBreak()
 
     // If we are not in a table, then the next table row will be the first one.
     RTFValue::Pointer_t pValue = m_aStates.top().aParagraphSprms.find(NS_sprm::LN_PFInTable);
-    if (!pValue.get())
-        m_bFirstRow = true;
 
     // start new one
     Mapper().startParagraphGroup();
@@ -1365,7 +1362,6 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
         case RTF_ROW:
         case RTF_NESTROW:
             {
-                m_bFirstRow = false;
                 if (m_aStates.top().nCells)
                 {
                     // Make a backup before we start popping elements
@@ -2288,11 +2284,8 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
             {
                 int nCellX = nParam - m_aStates.top().nCellX;
                 m_aStates.top().nCellX = nParam;
-                if (m_bFirstRow)
-                {
-                    RTFValue::Pointer_t pXValue(new RTFValue(nCellX));
-                    m_aStates.top().aTableRowSprms->push_back(make_pair(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue));
-                }
+                RTFValue::Pointer_t pXValue(new RTFValue(nCellX));
+                m_aStates.top().aTableRowSprms->push_back(make_pair(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue));
                 m_aStates.top().nCells++;
 
                 // Push cell properties.
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 8013677..5e6fc68 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -370,8 +370,6 @@ namespace writerfilter {
                 /// Color index <-> RGB color value map
                 std::vector<sal_uInt32> m_aColorTable;
                 bool m_bFirstRun;
-                /// If this is the first row in a table - there we send cell widths.
-                bool m_bFirstRow;
                 /// If paragraph properties should be emitted on next run.
                 bool m_bNeedPap;
                 /// If we need to emit a CR at the end of substream.


More information about the Libreoffice-commits mailing list