[Libreoffice-commits] core.git: svx/source

Mark Hung marklh9 at gmail.com
Fri Feb 17 11:21:50 UTC 2017


 svx/source/table/tablertfimporter.cxx |   34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

New commits:
commit 291538bac9b0d9e1afe69c244ffa9e3f4b203761
Author: Mark Hung <marklh9 at gmail.com>
Date:   Tue Feb 14 00:41:38 2017 +0800

    tdf#105423 merge cells based on its column edge.
    
    As we have split the row into columns based on all
    possible edges from different rows in the original
    table, we need to decide how many columns in the new
    table is coverted by the cell from original table,
    by chcking its edge and merging covered cells.
    
    Change-Id: Idfd2347765bf658aff90121d24d2154ba28956da
    Reviewed-on: https://gerrit.libreoffice.org/34311
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mark Hung <marklh9 at gmail.com>

diff --git a/svx/source/table/tablertfimporter.cxx b/svx/source/table/tablertfimporter.cxx
index 992fbf1..c78b120 100644
--- a/svx/source/table/tablertfimporter.cxx
+++ b/svx/source/table/tablertfimporter.cxx
@@ -22,6 +22,7 @@
 #include <vector>
 
 #include <com/sun/star/table/XTable.hpp>
+#include <com/sun/star/table/XMergeableCellRange.hpp>
 
 #include <tools/stream.hxx>
 #include <svtools/rtftoken.h>
@@ -51,8 +52,9 @@ struct RTFCellDefault
 {
     SfxItemSet          maItemSet;
     sal_Int32           mnColSpan;   // MergeCell if >1, merged cells if 0
+    sal_Int32           mnCellX;
 
-    explicit RTFCellDefault( SfxItemPool* pPool ) : maItemSet( *pPool ), mnColSpan(1) {}
+    explicit RTFCellDefault( SfxItemPool* pPool ) : maItemSet( *pPool ), mnColSpan(1), mnCellX(0) {}
 };
 
 typedef std::vector< std::shared_ptr< RTFCellDefault > > RTFCellDefaultVector;
@@ -62,8 +64,9 @@ struct RTFCellInfo
     SfxItemSet          maItemSet;
     sal_Int32           mnStartPara;
     sal_Int32           mnParaCount;
+    sal_Int32           mnCellX;
 
-    explicit RTFCellInfo( SfxItemPool& rPool ) : maItemSet(  rPool ), mnStartPara(0), mnParaCount(0) {}
+    explicit RTFCellInfo( SfxItemPool& rPool ) : maItemSet(  rPool ), mnStartPara(0), mnParaCount(0), mnCellX(0) {}
 };
 
 typedef std::shared_ptr< RTFCellInfo > RTFCellInfoPtr;
@@ -208,6 +211,7 @@ void SdrTableRTFParser::InsertCell( ImportInfo* pInfo )
 
     xCellInfo->mnStartPara = mnStartPara;
     xCellInfo->mnParaCount = pInfo->aSelection.nEndPara - 1 - mnStartPara;
+    xCellInfo->mnCellX = mpActDefault->mnCellX;
 
     if( !maRows.empty() )
     {
@@ -263,9 +267,11 @@ void SdrTableRTFParser::FillTable()
         for( sal_Int32 nRow = 0; nRow < (sal_Int32)maRows.size(); nRow++ )
         {
             RTFColumnVectorPtr xColumn( maRows[nRow] );
-            for( nCol = 0; nCol < (sal_Int32)xColumn->size(); nCol++ )
+            nCol = 0;
+            auto aEdge = maColumnEdges.begin();
+            for( sal_Int32 nIdx = 0; nCol < nColMax && nIdx < (sal_Int32)xColumn->size(); nIdx++ )
             {
-                RTFCellInfoPtr xCellInfo( (*xColumn)[nCol] );
+                RTFCellInfoPtr xCellInfo( (*xColumn)[nIdx] );
 
                 CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 if( xCell.is() && xCellInfo.get() )
@@ -282,6 +288,21 @@ void SdrTableRTFParser::FillTable()
                         rOutliner.SetText( *pTextObject );
                         mrTableObj.NbcSetOutlinerParaObjectForText( rOutliner.CreateParaObject(), xCell.get() );
                     }
+                    aEdge = std::lower_bound( aEdge, maColumnEdges.end(), xCellInfo->mnCellX );
+                    sal_Int32 nLastCol = nCol;
+                    if ( aEdge != maColumnEdges.end() )
+                    {
+                        nLastCol = std::distance( maColumnEdges.begin(), aEdge);
+                        ++aEdge;
+                    }
+
+                    if ( nLastCol > nCol )
+                    {
+                         Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( nCol, nRow, nLastCol, nRow ) ), UNO_QUERY_THROW );
+                         if( xRange->isMergeable() )
+                             xRange->merge();
+                    }
+                    nCol = nLastCol + 1;
                 }
             }
         }
@@ -368,6 +389,11 @@ void SdrTableRTFParser::ProcToken( ImportInfo* pInfo )
             if ( nSize > mnLastEdge )
                 InsertColumnEdge( nSize );
 
+            mpInsDefault->mnCellX = nSize;
+            // Record cellx in the first merged cell.
+            if ( mpDefMerge && mpInsDefault->mnColSpan == 0 )
+                mpDefMerge->mnCellX = nSize;
+
             mpInsDefault = new RTFCellDefault( &mrItemPool );
 
             mnLastToken = pInfo->nToken;


More information about the Libreoffice-commits mailing list