diff options
author | Justin Luth <justin.luth@collabora.com> | 2020-06-29 13:20:00 +0300 |
---|---|---|
committer | Justin Luth <justin_luth@sil.org> | 2020-07-08 17:31:35 +0200 |
commit | 2e8992aea2017e89a6f7ba5f0ef544f29059243b (patch) | |
tree | a91b5e7d68b46618d08e4df683e3c578a70f955f /writerfilter | |
parent | a480b32fb7a381fc17d51c2ccd0e8c4455d38792 (diff) |
tdf#129452 writerfilter: preserve gridSpans longer than currentRow
It is a fairly common thing for table operations to compare
items in the same column (like merged cells for example).
In order to determine column information, each row's (gridBefore
- change-id Ie305477f0e3468a4a923095d76f520d97fe99ffe -
and) merged cells need to be known.
So save that information in the cell data - and don't just throw
it away after the current row has been analyzed. Good grief.
Change-Id: Ibfdac336bbb1f7303c7e585a85c94be37ad6f916
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97433
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableManager.cxx | 42 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableManager.hxx | 1 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TableData.hxx | 19 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TableManager.cxx | 11 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TableManager.hxx | 2 |
5 files changed, 42 insertions, 33 deletions
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx index c16ee820528f..e80bc418ddaf 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx @@ -393,11 +393,6 @@ DomainMapperTableManager::IntVectorPtr const & DomainMapperTableManager::getCurr return m_aTableGrid.back( ); } -DomainMapperTableManager::IntVectorPtr const & DomainMapperTableManager::getCurrentSpans( ) -{ - return m_aGridSpans.back( ); -} - DomainMapperTableManager::IntVectorPtr const & DomainMapperTableManager::getCurrentCellWidths( ) { return m_aCellWidths.back( ); @@ -448,11 +443,9 @@ void DomainMapperTableManager::startLevel( ) } IntVectorPtr pNewGrid = std::make_shared<vector<sal_Int32>>(); - IntVectorPtr pNewSpans = std::make_shared<vector<sal_Int32>>(); IntVectorPtr pNewCellWidths = std::make_shared<vector<sal_Int32>>(); TablePositionHandlerPtr pNewPositionHandler; m_aTableGrid.push_back( pNewGrid ); - m_aGridSpans.push_back( pNewSpans ); m_aCellWidths.push_back( pNewCellWidths ); m_aTablePositions.push_back( pNewPositionHandler ); // empty name will be replaced by the table style name, if it exists @@ -484,7 +477,6 @@ void DomainMapperTableManager::endLevel( ) } m_aTableGrid.pop_back( ); - m_aGridSpans.pop_back( ); // Do the same trick as in startLevel(): pop the value that was pushed too early. std::optional<sal_Int32> oCurrentWidth; @@ -525,9 +517,10 @@ void DomainMapperTableManager::endOfCellAction() TagLogger::getInstance().element("endOFCellAction"); #endif - if (m_aGridSpans.empty()) - throw std::out_of_range("empty spans"); - m_aGridSpans.back()->push_back(m_nGridSpan); + if ( !isInTable() ) + throw std::out_of_range("cell without a table"); + if ( m_nGridSpan > 1 ) + setCurrentGridSpan( m_nGridSpan ); m_nGridSpan = 1; ++m_nCell.back( ); } @@ -568,7 +561,6 @@ void DomainMapperTableManager::endOfRowAction() { // Save the grid infos to have them survive the end/start level IntVectorPtr pTmpTableGrid = m_aTableGrid.back(); - IntVectorPtr pTmpGridSpans = m_aGridSpans.back(); IntVectorPtr pTmpCellWidths = m_aCellWidths.back(); sal_uInt32 nTmpCell = m_nCell.back(); TableParagraphVectorPtr pTableParagraphs = getCurrentParagraphs(); @@ -581,11 +573,9 @@ void DomainMapperTableManager::endOfRowAction() startLevel(); m_aTableGrid.pop_back(); - m_aGridSpans.pop_back(); m_aCellWidths.pop_back(); m_nCell.pop_back(); m_aTableGrid.push_back(pTmpTableGrid); - m_aGridSpans.push_back(pTmpGridSpans); m_aCellWidths.push_back(pTmpCellWidths); m_nCell.push_back(nTmpCell); m_aParagraphsToEndTable.pop( ); @@ -639,23 +629,12 @@ void DomainMapperTableManager::endOfRowAction() #endif } - IntVectorPtr pCurrentSpans = getCurrentSpans( ); - - if ( getCurrentGridBefore() ) - { - //fill missing gridBefore elements with '1' - pCurrentSpans->insert( pCurrentSpans->begin(), getCurrentGridBefore(), 1 ); - } - if ( pCurrentSpans->size() < getCurrentGridBefore() + m_nCell.back() ) - { - //fill missing elements with '1' - pCurrentSpans->insert( pCurrentSpans->end(), getCurrentGridBefore() + m_nCell.back() - pCurrentSpans->size(), 1 ); - } + std::vector<sal_uInt32> rCurrentSpans = getCurrentGridSpans(); #ifdef DBG_UTIL TagLogger::getInstance().startElement("gridSpans"); { - for (const auto& rGridSpan : *pCurrentSpans) + for (const auto& rGridSpan : rCurrentSpans) { TagLogger::getInstance().startElement("gridSpan"); TagLogger::getInstance().attribute("span", rGridSpan); @@ -666,7 +645,7 @@ void DomainMapperTableManager::endOfRowAction() #endif //calculate number of used grids - it has to match the size of m_aTableGrid - size_t nGrids = std::accumulate(pCurrentSpans->begin(), pCurrentSpans->end(), sal::static_int_cast<size_t>(0)); + size_t nGrids = std::accumulate(rCurrentSpans.begin(), rCurrentSpans.end(), sal::static_int_cast<size_t>(0)); // sj: the grid is having no units... it is containing only relative values. // a table with a grid of "1:2:1" looks identical as if the table is having @@ -718,7 +697,7 @@ void DomainMapperTableManager::endOfRowAction() if (nFullWidthRelative == 0) throw o3tl::divide_by_zero(); - ::std::vector< sal_Int32 >::const_iterator aSpansIter = pCurrentSpans->begin( ); + ::std::vector< sal_uInt32 >::const_iterator aSpansIter = rCurrentSpans.begin(); for( size_t nBorder = 0; nBorder < nWidthsBound; ++nBorder ) { double fGridWidth = 0.; @@ -793,9 +772,9 @@ void DomainMapperTableManager::endOfRowAction() // At incomplete table grids, last cell width can be smaller, than its final width. // Correct it based on the last but one column width and their span values. - if ( bIsIncompleteGrid && pCurrentSpans->size()-1 == nWidthsBound ) + if ( bIsIncompleteGrid && rCurrentSpans.size()-1 == nWidthsBound ) { - auto aSpansIter = std::next(pCurrentSpans->begin( ), nWidthsBound - 1); + auto aSpansIter = std::next(rCurrentSpans.begin(), nWidthsBound - 1); sal_Int32 nFixLastCellWidth = (*pCellWidths)[nWidthsBound-1] / *aSpansIter * *std::next(aSpansIter); if (nFixLastCellWidth > (*pCellWidths)[nWidthsBound]) nFullWidthRelative += nFixLastCellWidth - (*pCellWidths)[nWidthsBound]; @@ -830,7 +809,6 @@ void DomainMapperTableManager::endOfRowAction() ++m_nRow; m_nCell.back( ) = 0; getCurrentGrid()->clear(); - pCurrentSpans->clear(); pCellWidths->clear(); m_nGridAfter = 0; diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx index 93e303555d27..b3d44eeb8217 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx @@ -53,7 +53,6 @@ class DomainMapperTableManager : public TableManager std::vector< TablePropertyMapPtr > m_aTmpTableProperties; ///< Temporarily stores the table properties until end of row ::std::vector< IntVectorPtr > m_aTableGrid; - ::std::vector< IntVectorPtr > m_aGridSpans; /// If this is true, then we pushed a width before the next level started, and that should be carried over when starting the next level. bool m_bPushCurrentWidth; /// Individual table cell width values, used only in case the number of cells doesn't match the table grid. diff --git a/writerfilter/source/dmapper/TableData.hxx b/writerfilter/source/dmapper/TableData.hxx index d0e5be774959..e16c890783dd 100644 --- a/writerfilter/source/dmapper/TableData.hxx +++ b/writerfilter/source/dmapper/TableData.hxx @@ -53,11 +53,14 @@ class CellData final : public virtual SvRefBase bool mbOpen; + sal_uInt32 m_nGridSpan; ///< number of grid columns in the parent table's table grid which this cell defines + public: typedef tools::SvRef<CellData> Pointer_t; CellData(css::uno::Reference<css::text::XTextRange> const & start, TablePropertyMapPtr pProps) : mStart(start), mEnd(start), mpProps(pProps), mbOpen(true) + , m_nGridSpan(1) { } @@ -97,6 +100,9 @@ public: const TablePropertyMapPtr& getProperties() const { return mpProps; } bool isOpen() const { return mbOpen; } + + sal_uInt32 getGridSpan() { return m_nGridSpan; } + void setGridSpan( sal_uInt32 nSpan ) { m_nGridSpan = nSpan; } }; /** @@ -236,6 +242,19 @@ public: sal_uInt32 getGridBefore() { return m_nGridBefore; } void setGridBefore(sal_uInt32 nSkipGrids) { m_nGridBefore = nSkipGrids; } + sal_uInt32 getGridSpan(sal_uInt32 i) { return mCells[i]->getGridSpan(); } + std::vector< sal_uInt32 > getGridSpans() + { + std::vector< sal_uInt32 > nRet; + for (auto const& aCell: mCells) + nRet.push_back(aCell->getGridSpan()); + return nRet; + } + void setCurrentGridSpan(sal_uInt32 nSpan) + { + if ( mCells.size() ) + mCells.back()->setGridSpan(nSpan); + } }; /** diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx index 4c257c479475..651922fc3998 100644 --- a/writerfilter/source/dmapper/TableManager.cxx +++ b/writerfilter/source/dmapper/TableManager.cxx @@ -59,6 +59,16 @@ void TableManager::setCurrentGridBefore(sal_uInt32 nSkipGrids) mTableDataStack.top()->getCurrentRow()->setGridBefore(nSkipGrids); } +std::vector<sal_uInt32> TableManager::getCurrentGridSpans() +{ + return mTableDataStack.top()->getCurrentRow()->getGridSpans(); +} + +void TableManager::setCurrentGridSpan(sal_uInt32 nGridSpan) +{ + mTableDataStack.top()->getCurrentRow()->setCurrentGridSpan(nGridSpan); +} + void TableManager::endOfRowAction() {} void TableManager::endOfCellAction() {} @@ -389,6 +399,7 @@ void TableManager::startLevel() pTableData2->addCell(mpUnfinishedRow->getCellStart(i), mpUnfinishedRow->getCellProperties(i)); pTableData2->endCell(mpUnfinishedRow->getCellEnd(i)); + pTableData2->getCurrentRow()->setCurrentGridSpan(mpUnfinishedRow->getGridSpan(i)); } pTableData2->getCurrentRow()->setGridBefore(mpUnfinishedRow->getGridBefore()); mpUnfinishedRow.clear(); diff --git a/writerfilter/source/dmapper/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx index 04b4f7da52af..d1c6ee431bc8 100644 --- a/writerfilter/source/dmapper/TableManager.hxx +++ b/writerfilter/source/dmapper/TableManager.hxx @@ -502,6 +502,8 @@ public: sal_uInt32 getCurrentGridBefore(); void setCurrentGridBefore( sal_uInt32 nSkipGrids ); + std::vector<sal_uInt32> getCurrentGridSpans(); + void setCurrentGridSpan( sal_uInt32 nGridSpan ); void setTableStartsAtCellStart(bool bTableStartsAtCellStart); void setCellLastParaAfterAutospacing(bool bIsAfterAutospacing); |