From 2ad32b39af2e00ef253a2ef99e033feef416808f Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Mon, 29 Jun 2020 12:33:07 +0300 Subject: tdf#129452 writerfilter: preserve gridBefore longer than currentRow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is a fairly common thing for table operations to need to compare items in the same column (like merged cells for example). In order to determine column information, each row's gridBefore (and merged cells) need to be known. So save that information in the row data - and don't just throw it away after the current row has been analyzed. Good grief. Change-Id: Ie305477f0e3468a4a923095d76f520d97fe99ffe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97432 Tested-by: Jenkins Tested-by: László Németh Reviewed-by: Justin Luth Reviewed-by: László Németh --- .../source/dmapper/DomainMapperTableManager.cxx | 26 ++++++---------------- .../source/dmapper/DomainMapperTableManager.hxx | 2 -- writerfilter/source/dmapper/TableData.hxx | 11 ++++++++- writerfilter/source/dmapper/TableManager.cxx | 11 +++++++++ writerfilter/source/dmapper/TableManager.hxx | 2 ++ 5 files changed, 30 insertions(+), 22 deletions(-) (limited to 'writerfilter') diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx index 2d75c971b85a..c16ee820528f 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx @@ -40,7 +40,6 @@ DomainMapperTableManager::DomainMapperTableManager() : m_nRow(0), m_nCell(), m_nGridSpan(1), - m_aGridBefore(), m_nGridAfter(0), m_nHeaderRepeat(0), m_nTableWidth(0), @@ -354,7 +353,7 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm) } break; case NS_ooxml::LN_CT_TrPrBase_gridBefore: - m_aGridBefore.back( ) = nIntValue; + setCurrentGridBefore( nIntValue ); break; case NS_ooxml::LN_CT_TrPrBase_gridAfter: m_nGridAfter = nIntValue; @@ -394,11 +393,6 @@ DomainMapperTableManager::IntVectorPtr const & DomainMapperTableManager::getCurr return m_aTableGrid.back( ); } -sal_uInt32 DomainMapperTableManager::getCurrentGridBefore( ) -{ - return m_aGridBefore.back( ); -} - DomainMapperTableManager::IntVectorPtr const & DomainMapperTableManager::getCurrentSpans( ) { return m_aGridSpans.back( ); @@ -469,7 +463,6 @@ void DomainMapperTableManager::startLevel( ) m_aTmpPosition.push_back( pTmpPosition ); m_aTmpTableProperties.push_back( pTmpProperties ); m_nCell.push_back( 0 ); - m_aGridBefore.push_back( 0 ); m_nTableWidth = 0; m_nLayoutType = 0; TableParagraphVectorPtr pNewParagraphs = std::make_shared>(); @@ -503,7 +496,6 @@ void DomainMapperTableManager::endLevel( ) m_aCellWidths.back()->push_back(*oCurrentWidth); m_nCell.pop_back( ); - m_aGridBefore.pop_back( ); m_nTableWidth = 0; m_nLayoutType = 0; @@ -579,7 +571,6 @@ void DomainMapperTableManager::endOfRowAction() IntVectorPtr pTmpGridSpans = m_aGridSpans.back(); IntVectorPtr pTmpCellWidths = m_aCellWidths.back(); sal_uInt32 nTmpCell = m_nCell.back(); - sal_uInt32 nTmpGridBefore = m_aGridBefore.back(); TableParagraphVectorPtr pTableParagraphs = getCurrentParagraphs(); // endLevel and startLevel are taking care of the non finished row @@ -593,12 +584,10 @@ void DomainMapperTableManager::endOfRowAction() m_aGridSpans.pop_back(); m_aCellWidths.pop_back(); m_nCell.pop_back(); - m_aGridBefore.pop_back(); m_aTableGrid.push_back(pTmpTableGrid); m_aGridSpans.push_back(pTmpGridSpans); m_aCellWidths.push_back(pTmpCellWidths); m_nCell.push_back(nTmpCell); - m_aGridBefore.push_back(nTmpGridBefore); m_aParagraphsToEndTable.pop( ); m_aParagraphsToEndTable.push( pTableParagraphs ); } @@ -652,15 +641,15 @@ void DomainMapperTableManager::endOfRowAction() IntVectorPtr pCurrentSpans = getCurrentSpans( ); - if( m_aGridBefore.back() > 0 ) + if ( getCurrentGridBefore() ) { //fill missing gridBefore elements with '1' - pCurrentSpans->insert( pCurrentSpans->begin( ), m_aGridBefore.back(), 1 ); + pCurrentSpans->insert( pCurrentSpans->begin(), getCurrentGridBefore(), 1 ); } - if( pCurrentSpans->size() < m_aGridBefore.back() + m_nCell.back( )) + if ( pCurrentSpans->size() < getCurrentGridBefore() + m_nCell.back() ) { //fill missing elements with '1' - pCurrentSpans->insert( pCurrentSpans->end( ), m_aGridBefore.back() + m_nCell.back( ) - pCurrentSpans->size(), 1 ); + pCurrentSpans->insert( pCurrentSpans->end(), getCurrentGridBefore() + m_nCell.back() - pCurrentSpans->size(), 1 ); } #ifdef DBG_UTIL @@ -718,12 +707,12 @@ void DomainMapperTableManager::endOfRowAction() } } } - uno::Sequence< text::TableColumnSeparator > aSeparators( m_aGridBefore.back() + m_nCell.back( ) - 1 ); + uno::Sequence< text::TableColumnSeparator > aSeparators( getCurrentGridBefore() + m_nCell.back() - 1 ); text::TableColumnSeparator* pSeparators = aSeparators.getArray(); double nLastRelPos = 0.0; sal_uInt32 nBorderGridIndex = 0; - size_t nWidthsBound = m_aGridBefore.back() + m_nCell.back() - 1; + size_t nWidthsBound = getCurrentGridBefore() + m_nCell.back() - 1; if (nWidthsBound) { if (nFullWidthRelative == 0) @@ -840,7 +829,6 @@ void DomainMapperTableManager::endOfRowAction() ++m_nRow; m_nCell.back( ) = 0; - m_aGridBefore.back( ) = 0; getCurrentGrid()->clear(); pCurrentSpans->clear(); pCellWidths->clear(); diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx index 50d5f2ff25ca..93e303555d27 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx @@ -40,7 +40,6 @@ class DomainMapperTableManager : public TableManager sal_uInt32 m_nRow; ::std::vector< sal_uInt32 > m_nCell; sal_uInt32 m_nGridSpan; - ::std::vector< sal_uInt32 > m_aGridBefore; ///< number of grid columns in the parent table's table grid which must be skipped before the contents of this table row are added to the parent table sal_uInt32 m_nGridAfter; ///< number of grid columns in the parent table's table grid which shall be left after the last cell in the table row 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 @@ -94,7 +93,6 @@ public: IntVectorPtr const & getCurrentGrid( ); IntVectorPtr const & getCurrentSpans( ); IntVectorPtr const & getCurrentCellWidths( ); - sal_uInt32 getCurrentGridBefore( ); TableParagraphVectorPtr getCurrentParagraphs( ); /// Turn the attributes collected so far in m_aTableLook into a property and clear the container. diff --git a/writerfilter/source/dmapper/TableData.hxx b/writerfilter/source/dmapper/TableData.hxx index 3140a00d71aa..d0e5be774959 100644 --- a/writerfilter/source/dmapper/TableData.hxx +++ b/writerfilter/source/dmapper/TableData.hxx @@ -116,13 +116,19 @@ class RowData final : public virtual SvRefBase */ mutable TablePropertyMapPtr mpProperties; + sal_uInt32 m_nGridBefore; ///< number of grid columns in the parent table's table grid which must be skipped before the contents of this table row are added to the parent table + public: typedef tools::SvRef Pointer_t; - RowData() {} + RowData() + : m_nGridBefore(0) + { + } RowData(const RowData& rRowData) : SvRefBase(), mCells(rRowData.mCells), mpProperties(rRowData.mpProperties) + , m_nGridBefore(rRowData.m_nGridBefore) { } @@ -227,6 +233,9 @@ public: { return mpProperties; } + + sal_uInt32 getGridBefore() { return m_nGridBefore; } + void setGridBefore(sal_uInt32 nSkipGrids) { m_nGridBefore = nSkipGrids; } }; /** diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx index 50e948b00eba..4c257c479475 100644 --- a/writerfilter/source/dmapper/TableManager.cxx +++ b/writerfilter/source/dmapper/TableManager.cxx @@ -49,6 +49,16 @@ void TableManager::openCell(const css::uno::Reference& rH bool TableManager::isIgnore() const { return isRowEnd(); } +sal_uInt32 TableManager::getCurrentGridBefore() +{ + return mTableDataStack.top()->getCurrentRow()->getGridBefore(); +} + +void TableManager::setCurrentGridBefore(sal_uInt32 nSkipGrids) +{ + mTableDataStack.top()->getCurrentRow()->setGridBefore(nSkipGrids); +} + void TableManager::endOfRowAction() {} void TableManager::endOfCellAction() {} @@ -380,6 +390,7 @@ void TableManager::startLevel() mpUnfinishedRow->getCellProperties(i)); pTableData2->endCell(mpUnfinishedRow->getCellEnd(i)); } + pTableData2->getCurrentRow()->setGridBefore(mpUnfinishedRow->getGridBefore()); mpUnfinishedRow.clear(); } diff --git a/writerfilter/source/dmapper/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx index 5e18becab606..04b4f7da52af 100644 --- a/writerfilter/source/dmapper/TableManager.hxx +++ b/writerfilter/source/dmapper/TableManager.hxx @@ -500,6 +500,8 @@ public: */ bool isIgnore() const; + sal_uInt32 getCurrentGridBefore(); + void setCurrentGridBefore( sal_uInt32 nSkipGrids ); void setTableStartsAtCellStart(bool bTableStartsAtCellStart); void setCellLastParaAfterAutospacing(bool bIsAfterAutospacing); -- cgit