From 32c322e9d037b29ded2297b400a2c596c042f1fa Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 26 Oct 2020 17:52:42 +0100 Subject: DOCX import, altChunk: fix missing page break Somewhat similar to copy&paste, the altChunk mechanism drops styles from the inner document by default. A surprising consequence of that is sections in the inner document have the default page size. This leads to a page break when the content of the outer document ends and the content of the inner document starts. Fix the importer to support this: 1) Ignore the page size and number in DomainMapper::lcl_attribute(). 2) Pass the start of the current section to the sub-importer, so that it can insert the starting page break at the right place. Change-Id: Id3955f2b35a139692254c4ac1233e96eef2620e9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104821 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- writerfilter/source/dmapper/DomainMapper.cxx | 12 +++++++++--- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 15 +++++++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.hxx | 4 ++++ writerfilter/source/dmapper/PropertyMap.cxx | 6 +++++- 4 files changed, 33 insertions(+), 4 deletions(-) (limited to 'writerfilter/source') diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 938b1f41a106..b489115d4980 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -1065,7 +1065,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) m_pImpl->m_oBackgroundColor = nIntValue; break; case NS_ooxml::LN_CT_PageNumber_start: - if (pSectionContext != nullptr) + if (pSectionContext != nullptr && !m_pImpl->IsAltChunk()) pSectionContext->SetPageNumber(nIntValue); break; case NS_ooxml::LN_CT_PageNumber_fmt: @@ -2138,9 +2138,15 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); if(pSectionContext) { - pSectionContext->Insert( PROP_HEIGHT, uno::makeAny( CT_PageSz.h ) ); + if (!m_pImpl->IsAltChunk()) + { + pSectionContext->Insert(PROP_HEIGHT, uno::makeAny(CT_PageSz.h)); + } pSectionContext->Insert( PROP_IS_LANDSCAPE, uno::makeAny( CT_PageSz.orient )); - pSectionContext->Insert( PROP_WIDTH, uno::makeAny( CT_PageSz.w ) ); + if (!m_pImpl->IsAltChunk()) + { + pSectionContext->Insert(PROP_WIDTH, uno::makeAny(CT_PageSz.w)); + } } break; diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index d37a6c68fb05..a43e396ba461 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -308,7 +308,9 @@ DomainMapper_Impl::DomainMapper_Impl( m_aAnnotationPositions(), m_aSmartTagHandler(m_xComponentContext, m_xTextDocument), m_xInsertTextRange(rMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference())), + m_xAltChunkStartingRange(rMediaDesc.getUnpackedValueOrDefault("AltChunkStartingRange", uno::Reference())), m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)), + m_bIsAltChunk(rMediaDesc.getUnpackedValueOrDefault("AltChunkMode", false)), m_bIsReadGlossaries(rMediaDesc.getUnpackedValueOrDefault("ReadGlossaries", false)), m_nTableDepth(0), m_nTableCellDepth(0), @@ -352,6 +354,11 @@ DomainMapper_Impl::DomainMapper_Impl( m_pSdtHelper = new SdtHelper(*this); m_aRedlines.push(std::vector()); + + if (m_bIsAltChunk) + { + m_bIsFirstSection = false; + } } @@ -3277,10 +3284,18 @@ void DomainMapper_Impl::HandleAltChunk(const OUString& rStreamName) uno::Reference xInputStream = new utl::OStreamWrapper(aMemory); // Not handling AltChunk during paste for now. uno::Reference xInsertTextRange = GetCurrentXText()->getEnd(); + uno::Reference xSectionStartingRange; + SectionPropertyMap* pSectionContext = GetSectionContext(); + if (pSectionContext) + { + xSectionStartingRange = pSectionContext->GetStartingRange(); + } uno::Sequence aDescriptor(comphelper::InitPropertySequence({ { "InputStream", uno::Any(xInputStream) }, { "InsertMode", uno::Any(true) }, { "TextInsertModeRange", uno::Any(xInsertTextRange) }, + { "AltChunkMode", uno::Any(true) }, + { "AltChunkStartingRange", uno::Any(xSectionStartingRange) }, })); // Do the actual import. diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 50b5561076ef..bb7a7d4877b0 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -585,8 +585,10 @@ private: public: css::uno::Reference m_xInsertTextRange; + css::uno::Reference m_xAltChunkStartingRange; private: bool m_bIsNewDoc; + bool m_bIsAltChunk = false; bool m_bIsReadGlossaries; public: DomainMapper_Impl( @@ -1000,6 +1002,8 @@ public: /// If we're importing into a new document, or just pasting to an existing one. bool IsNewDoc() const { return m_bIsNewDoc;} + bool IsAltChunk() const { return m_bIsAltChunk;} + /// If we're importing autotext. bool IsReadGlossaries() const { return m_bIsReadGlossaries;} diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 5877e676917b..c4dadd35dc74 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -1828,7 +1828,11 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) evenOddStyle->setPropertyValue( getPropertyName( PROP_PAGE_STYLE_LAYOUT ), uno::makeAny( style::PageStyleLayout_RIGHT ) ); } - if ( xRangeProperties.is() && rDM_Impl.IsNewDoc() ) + if (rDM_Impl.m_xAltChunkStartingRange.is()) + { + xRangeProperties.set(rDM_Impl.m_xAltChunkStartingRange, uno::UNO_QUERY); + } + if (xRangeProperties.is() && (rDM_Impl.IsNewDoc() || rDM_Impl.IsAltChunk())) { // Avoid setting page style in case of autotext: so inserting the autotext at the // end of the document does not introduce an unwanted page break. -- cgit v1.2.3