From 81ce88aa80f8e7cde4fdc5b211e9500a3599643c Mon Sep 17 00:00:00 2001 From: László Németh Date: Mon, 4 May 2020 13:42:14 +0200 Subject: tdf#132514 DOCX import: fix lost table style with footer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Table paragraphs collected for table style processing were mixed when both body text and footer contain tables, i.e. clearing paragraph vector at processing the first table resulted missing paragraph vector and table style processing for the other one. Now tables in footer, also nested tables collect their paragraphs in separated table paragraph vectors. Regression from commit 6c5da2cd7af5c2d90e4d8e9635ba8c9989c87923 (tdf#119054 DOCX: fix not table style based bottom margin). Change-Id: Ib8568d8379cfb7da869120cdc7fe12895252d661 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93415 Tested-by: Jenkins Reviewed-by: László Németh --- .../source/dmapper/DomainMapperTableHandler.cxx | 9 ++++----- .../source/dmapper/DomainMapperTableHandler.hxx | 9 --------- .../source/dmapper/DomainMapperTableManager.cxx | 17 +++++++++++++++++ .../source/dmapper/DomainMapperTableManager.hxx | 3 +++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 2 +- writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 --- writerfilter/source/dmapper/PropertyMap.hxx | 11 +++++++++++ 7 files changed, 36 insertions(+), 18 deletions(-) (limited to 'writerfilter/source') diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 0c73bb60f23a..a3548cde909c 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -1252,6 +1252,7 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab if ( !aAllTableParaProperties.empty() ) { + TableParagraphVectorPtr pTableParagraphs = m_rDMapper_Impl.getTableManager().getCurrentParagraphs(); for (size_t nRow = 0; nRow < m_aTableRanges.size(); ++nRow) { for (size_t nCell = 0; nCell < m_aTableRanges[nRow].size(); ++nCell) @@ -1263,8 +1264,8 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab uno::Reference xTextRangeCompare(rStartPara->getText(), uno::UNO_QUERY); bool bApply = false; // search paragraphs of the cell - std::vector::iterator aIt = m_rDMapper_Impl.m_aParagraphsToEndTable.begin(); - while ( aIt != m_rDMapper_Impl.m_aParagraphsToEndTable.end() ) try + std::vector::iterator aIt = pTableParagraphs->begin(); + while ( aIt != pTableParagraphs->end() ) try { if (!bApply && xTextRangeCompare->compareRegionStarts(rStartPara, aIt->m_rStartParagraph) == 0) bApply = true; @@ -1273,7 +1274,7 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab bool bEndOfApply = (xTextRangeCompare->compareRegionEnds(rEndPara, aIt->m_rEndParagraph) == 0); ApplyParagraphPropertiesFromTableStyle(*aIt, aAllTableParaProperties, aCellProperties[nRow][nCell]); // erase processed paragraph from list of pending paragraphs - aIt = m_rDMapper_Impl.m_aParagraphsToEndTable.erase(aIt); + aIt = pTableParagraphs->erase(aIt); if (bEndOfApply) break; } @@ -1435,8 +1436,6 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab m_aCellProperties.clear(); m_aRowProperties.clear(); m_bHadFootOrEndnote = false; - if (nestedTableLevel <= 1 && m_rDMapper_Impl.m_bConvertedTable) - m_rDMapper_Impl.m_aParagraphsToEndTable.clear(); #ifdef DBG_UTIL TagLogger::getInstance().endElement(); diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx index 142b7817cc37..545f60919c46 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx @@ -55,15 +55,6 @@ struct HorizontallyMergedCell } }; -/// Information about a paragraph to be finished after a table end. -struct TableParagraph -{ - css::uno::Reference m_rStartParagraph; - css::uno::Reference m_rEndParagraph; - PropertyMapPtr m_pPropertyMap; - css::uno::Reference m_rPropertySet; -}; - /// Class to handle events generated by TableManager::resolveCurrentTable(). class DomainMapperTableHandler final : public virtual SvRefBase { diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx index a1bb10e74850..9e7cf46cca40 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx @@ -50,6 +50,7 @@ DomainMapperTableManager::DomainMapperTableManager() : m_bPushCurrentWidth(false), m_bTableSizeTypeInserted(false), m_nLayoutType(0), + m_aParagraphsToEndTable(), m_pTablePropsHandler(new TablePropertiesHandler()) { m_pTablePropsHandler->SetTableManager( this ); @@ -424,6 +425,11 @@ TablePositionHandler* DomainMapperTableManager::getCurrentTableRealPosition() return nullptr; } +TableParagraphVectorPtr DomainMapperTableManager::getCurrentParagraphs( ) +{ + return m_aParagraphsToEndTable.top( ); +} + void DomainMapperTableManager::setIsInShape(bool bIsInShape) { m_bIsInShape = bIsInShape; @@ -440,6 +446,12 @@ void DomainMapperTableManager::startLevel( ) oCurrentWidth = m_aCellWidths.back()->back(); m_aCellWidths.back()->pop_back(); } + std::optional oParagraph; + if (getTableDepthDifference() > 0 && !m_aParagraphsToEndTable.empty() && !m_aParagraphsToEndTable.top()->empty()) + { + oParagraph = m_aParagraphsToEndTable.top()->back(); + m_aParagraphsToEndTable.top()->pop_back(); + } IntVectorPtr pNewGrid = std::make_shared>(); IntVectorPtr pNewSpans = std::make_shared>(); @@ -460,10 +472,14 @@ void DomainMapperTableManager::startLevel( ) m_aGridBefore.push_back( 0 ); m_nTableWidth = 0; m_nLayoutType = 0; + TableParagraphVectorPtr pNewParagraphs = std::make_shared>(); + m_aParagraphsToEndTable.push( pNewParagraphs ); // And push it back to the right level. if (oCurrentWidth) m_aCellWidths.back()->push_back(*oCurrentWidth); + if (oParagraph) + m_aParagraphsToEndTable.top()->push_back(*oParagraph); } void DomainMapperTableManager::endLevel( ) @@ -508,6 +524,7 @@ void DomainMapperTableManager::endLevel( ) // in the endTable method called in endLevel. m_aTablePositions.pop_back(); m_aTableStyleNames.pop_back(); + m_aParagraphsToEndTable.pop(); } void DomainMapperTableManager::endOfCellAction() diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx index 0801e9dd9280..cb298e12a4f2 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx @@ -63,6 +63,8 @@ class DomainMapperTableManager : public TableManager bool m_bTableSizeTypeInserted; /// Table layout algorithm, IOW if we should consider fixed column width or not. sal_uInt32 m_nLayoutType; + /// Collected table paragraphs for table style handling + std::stack< TableParagraphVectorPtr > m_aParagraphsToEndTable; std::unique_ptr m_pTablePropsHandler; PropertyMapPtr m_pStyleProps; @@ -93,6 +95,7 @@ public: 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. void finishTableLook(); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 4ef7b844d58b..f385565c8429 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1786,7 +1786,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con if (m_nTableDepth > 0) { TableParagraph aPending{xParaCursor, xCur, pParaContext, xParaProps}; - m_aParagraphsToEndTable.push_back(aPending); + getTableManager().getCurrentParagraphs()->push_back(aPending); } // hidden empty paragraph with a not hidden shape, set as not hidden diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 33a4eb5fa95f..ddce87060a6e 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -1058,9 +1058,6 @@ public: bool m_bIsActualParagraphFramed; std::vector aFramedRedlines; - /// Table paragraph properties may need style update based on table style - std::vector m_aParagraphsToEndTable; - private: void PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType); // Start a new index section; if needed, finish current paragraph diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx index 6bfc1fed3a04..f3b7f828b5d1 100644 --- a/writerfilter/source/dmapper/PropertyMap.hxx +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -592,6 +592,17 @@ public: typedef tools::SvRef< TablePropertyMap > TablePropertyMapPtr; +/// Information about a paragraph to be finished after a table end. +struct TableParagraph +{ + css::uno::Reference m_rStartParagraph; + css::uno::Reference m_rEndParagraph; + PropertyMapPtr m_pPropertyMap; + css::uno::Reference m_rPropertySet; +}; + +typedef std::shared_ptr< std::vector > TableParagraphVectorPtr; + } // namespace dmapper } // namespace writerfilter -- cgit