From 659c0227a50d298780d72902314e03df8824bc06 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 16 May 2017 15:26:53 +0200 Subject: tdf#107889 DOCX import: consider page breaks for multi-page floattables This is the DOCX equivalent of commit 6aba29576df7a2a40e54040d4dd09d94d6594741 (tdf#107773 DOC import: consider page breaks for multi-page floattables, 2017-05-11): a specific case where it's clearly superior to import a multi-page floating table as a multi-page one, rather than a floating one. Change-Id: I71a92d2b10e52e505665831caacad2948d22b4e1 Reviewed-on: https://gerrit.libreoffice.org/37683 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- .../source/dmapper/DomainMapperTableHandler.cxx | 3 +++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 2 ++ writerfilter/source/dmapper/DomainMapper_Impl.hxx | 5 +++++ writerfilter/source/dmapper/PropertyMap.cxx | 18 ++++++++++++------ writerfilter/source/dmapper/PropertyMap.hxx | 2 +- 5 files changed, 23 insertions(+), 7 deletions(-) (limited to 'writerfilter') diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 7ed678863e37..db2c4fa4d5c9 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -1178,6 +1178,9 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab xTextAppendAndConvert->convertToTextFrame(xStart, xEnd, comphelper::containerToSequence(aFrameProperties)); } } + + // We're right after a table conversion. + m_rDMapper_Impl.m_bConvertedTable = true; } m_aTableProperties.reset(); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index af1991b67e44..fc076998fa9b 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1227,6 +1227,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap ) xTextRange = xTextAppend->finishParagraph( comphelper::containerToSequence(aProperties) ); m_xPreviousParagraph.set(xTextRange, uno::UNO_QUERY); + // We're no longer right after a table conversion. + m_bConvertedTable = false; if (xCursor.is()) { diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index b43d310db917..65274fcc7d46 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -308,6 +308,8 @@ struct FloatingTableInfo css::uno::Reference m_xEnd; css::uno::Sequence m_aFrameProperties; sal_Int32 m_nTableWidth; + /// Break type of the section that contains this table. + sal_Int32 m_nBreakType = -1; FloatingTableInfo(css::uno::Reference const& xStart, css::uno::Reference const& xEnd, @@ -753,6 +755,9 @@ public: DeletableTabStop m_aCurrentTabStop; + /// If we're right after the end of a table. + bool m_bConvertedTable = false; + bool IsOOXMLImport() const { return m_eDocumentType == SourceDocumentType::OOXML; } bool IsRTFImport() const { return m_eDocumentType == SourceDocumentType::RTF; } diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 8e308940e7e0..3df7c864cd55 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -1021,12 +1021,17 @@ void SectionPropertyMap::HandleMarginsHeaderFooter( bool bFirstPage, DomainMappe PrepareHeaderFooterProperties( bFirstPage ); } -bool SectionPropertyMap::FloatingTableConversion( FloatingTableInfo& rInfo ) +bool SectionPropertyMap::FloatingTableConversion( DomainMapper_Impl& rDM_Impl, FloatingTableInfo& rInfo ) { // Note that this is just a list of heuristics till sw core can have a // table that is floating and can span over multiple pages at the same // time. + // If there is an explicit section break right after a table, then there + // will be no wrapping anyway. + if (rDM_Impl.m_bConvertedTable && !rDM_Impl.GetIsLastSectionGroup() && rInfo.m_nBreakType == NS_ooxml::LN_Value_ST_SectionMark_nextPage) + return false; + sal_Int32 nPageWidth = GetPageWidth(); sal_Int32 nTextAreaWidth = nPageWidth - GetLeftMargin() - GetRightMargin(); // Count the layout width of the table. @@ -1113,12 +1118,17 @@ void SectionPropertyMap::InheritOrFinalizePageStyles( DomainMapper_Impl& rDM_Imp void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) { + // The default section type is nextPage. + if ( m_nBreakType == -1 ) + m_nBreakType = NS_ooxml::LN_Value_ST_SectionMark_nextPage; + // Text area width is known at the end of a section: decide if tables should be converted or not. std::vector& rPendingFloatingTables = rDM_Impl.m_aPendingFloatingTables; uno::Reference xBodyText( rDM_Impl.GetBodyText(), uno::UNO_QUERY ); for ( FloatingTableInfo & rInfo : rPendingFloatingTables ) { - if ( FloatingTableConversion( rInfo ) ) + rInfo.m_nBreakType = m_nBreakType; + if ( FloatingTableConversion( rDM_Impl, rInfo ) ) xBodyText->convertToTextFrame( rInfo.m_xStart, rInfo.m_xEnd, rInfo.m_aFrameProperties ); } rPendingFloatingTables.clear(); @@ -1151,10 +1161,6 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) } } - // The default section type is nextPage. - if ( m_nBreakType == -1 ) - m_nBreakType = NS_ooxml::LN_Value_ST_SectionMark_nextPage; - // depending on the break type no page styles should be created // Continuous sections usually create only a section, and not a new page style const bool bTreatAsContinuous = m_nBreakType == NS_ooxml::LN_Value_ST_SectionMark_nextPage diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx index a45bef692b70..96883755159f 100644 --- a/writerfilter/source/dmapper/PropertyMap.hxx +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -284,7 +284,7 @@ private: sal_uInt32 nLineWidth ); // Determines if conversion of a given floating table is wanted or not. - bool FloatingTableConversion( FloatingTableInfo& rInfo ); + bool FloatingTableConversion( DomainMapper_Impl& rDM_Impl, FloatingTableInfo& rInfo ); public: enum PageType -- cgit stro/mimo/mimo-6-3 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff