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/source/dmapper/DomainMapperTableManager.cxx | |
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/source/dmapper/DomainMapperTableManager.cxx')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableManager.cxx | 42 |
1 files changed, 10 insertions, 32 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; |