diff options
author | Mark Hung <marklh9@gmail.com> | 2017-02-14 00:06:00 +0800 |
---|---|---|
committer | Mark Hung <marklh9@gmail.com> | 2017-02-17 11:02:17 +0000 |
commit | a20e6213ed40cd0ba6c0f144f2a954f008fdc372 (patch) | |
tree | 1a5038931d7c25d07d5c2c1a90615addf9210da8 | |
parent | 1ce132b5b41e218520cc51506665ee0bc625b24b (diff) |
tdf105423: make sure column edges are increasing
Replacing column edges based on its index doesn't work
because each row might have different number of columns.
Change-Id: Ib17d41d7e0daab9090670c4a9aba45d79e447622
Reviewed-on: https://gerrit.libreoffice.org/34309
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mark Hung <marklh9@gmail.com>
-rw-r--r-- | svx/source/table/tablertfimporter.cxx | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/svx/source/table/tablertfimporter.cxx b/svx/source/table/tablertfimporter.cxx index 3dc19aec3b41..0053fc4b3daa 100644 --- a/svx/source/table/tablertfimporter.cxx +++ b/svx/source/table/tablertfimporter.cxx @@ -87,6 +87,7 @@ public: void NewCellRow(); void InsertCell( ImportInfo* pInfo ); + void InsertColumnEdge( sal_Int32 nEdge ); void FillTable(); @@ -107,9 +108,10 @@ private: sal_Int32 mnColCnt; sal_Int32 mnRowCnt; - sal_Int32 mnColMax; + sal_Int32 mnLastEdge; std::vector< sal_Int32 > maColumnEdges; + std::vector< sal_Int32 >::iterator maLastEdge; std::vector< RTFColumnVectorPtr > maRows; RTFCellDefault* mpInsDefault; @@ -132,7 +134,6 @@ SdrTableRTFParser::SdrTableRTFParser( SdrTableObj& rTableObj ) , mnStartPara( 0 ) , mnColCnt( 0 ) , mnRowCnt( 0 ) -, mnColMax( 0 ) , mpActDefault( nullptr ) , mpDefMerge( nullptr ) , mxTable( rTableObj.getTable() ) @@ -225,16 +226,27 @@ void SdrTableRTFParser::InsertCell( ImportInfo* pInfo ) mnStartPara = pInfo->aSelection.nEndPara - 1; } +void SdrTableRTFParser::InsertColumnEdge( sal_Int32 nEdge ) +{ + auto aNextEdge = std::lower_bound( maLastEdge, maColumnEdges.end(), nEdge ); + + if ( aNextEdge == maColumnEdges.end() || nEdge != *aNextEdge ) + { + maLastEdge = maColumnEdges.insert( aNextEdge , nEdge ); + mnLastEdge = nEdge; + } +} + void SdrTableRTFParser::FillTable() { try { sal_Int32 nColCount = mxTable->getColumnCount(); Reference< XTableColumns > xCols( mxTable->getColumns(), UNO_QUERY_THROW ); - - if( nColCount < mnColMax ) + sal_Int32 nColMax = maColumnEdges.size(); + if( nColCount < nColMax ) { - xCols->insertByIndex( nColCount, mnColMax - nColCount ); + xCols->insertByIndex( nColCount, nColMax - nColCount ); nColCount = mxTable->getColumnCount(); } @@ -334,6 +346,8 @@ void SdrTableRTFParser::ProcToken( ImportInfo* pInfo ) maDefaultList.clear(); mpDefMerge = nullptr; mnLastToken = pInfo->nToken; + maLastEdge = maColumnEdges.begin(); + mnLastEdge = 0; } break; case RTF_CLMGF: // The first cell of cells to be merged @@ -359,15 +373,14 @@ void SdrTableRTFParser::ProcToken( ImportInfo* pInfo ) mpInsDefault->mnCol = mnColCnt; maDefaultList.push_back( std::shared_ptr< RTFCellDefault >( mpInsDefault ) ); - if( (sal_Int32)maColumnEdges.size() <= mnColCnt ) - maColumnEdges.resize( mnColCnt + 1 ); const sal_Int32 nSize = TwipsToHundMM( pInfo->nTokenValue ); - maColumnEdges[mnColCnt] = std::max( maColumnEdges[mnColCnt], nSize ); + if ( nSize > mnLastEdge ) + InsertColumnEdge( nSize ); mpInsDefault = new RTFCellDefault( &mrItemPool ); - if ( ++mnColCnt > mnColMax ) - mnColMax = mnColCnt; + mnColCnt++; + mnLastToken = pInfo->nToken; } break; |