From adcf656bb56e09fbb638a44b0cccc96f8cfced7f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 13 Mar 2019 17:51:07 +0100 Subject: [PATCH] DOCX import: fix unexpected page break on autotext insert at end of doc The problem was that the page style was set on the first paragraph, which means a page break on the UI. So if you used a multi-paragraph autotext twice (insert autotext, press enter, insert autotext again) then you ended up with 2 pages instead of just 1. Fix the problem by tracking when we are in autotext import mode, and similar to pasting, don't set the page style in autotext import mode. Change-Id: I4fc551b3c1b999687eb80242e261f186fd1b6f13 Reviewed-on: https://gerrit.libreoffice.org/69214 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/extras/uiwriter/uiwriter.cxx | 10 +++++++++- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 1 + writerfilter/source/dmapper/DomainMapper_Impl.hxx | 4 ++++ writerfilter/source/dmapper/PropertyMap.cxx | 11 +++++++---- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 0ba342215005..92cc2394bd83 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -1024,7 +1024,15 @@ void SwUiWriterTest::testDOCXAutoTextMultiple() // first line SwNode& rNode = aStart.GetNode(); - CPPUNIT_ASSERT_EQUAL(OUString("Another "), rNode.GetTextNode()->GetText()); + CPPUNIT_ASSERT(rNode.IsTextNode()); + SwTextNode& rTextNode = *rNode.GetTextNode(); + CPPUNIT_ASSERT_EQUAL(OUString("Another "), rTextNode.GetText()); + + // Make sure that autotext does not set a custom page style, leading to an unexpected page break + // on insertion. + // Without the accompanying fix in place, this test would have failed: the text node had an + // attribute set containing a page style item. + CPPUNIT_ASSERT(!rTextNode.HasSwAttrSet() || !rTextNode.GetSwAttrSet().HasItem(RES_PAGEDESC)); // last line SwNodeIndex aLast(*aDocEnd.GetNode().EndOfSectionNode(), -1); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index f0e13f5c54d8..57ff25205490 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -239,6 +239,7 @@ DomainMapper_Impl::DomainMapper_Impl( m_aSmartTagHandler(m_xComponentContext, m_xTextDocument), m_xInsertTextRange(rMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference())), m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)), + m_bIsReadGlossaries(rMediaDesc.getUnpackedValueOrDefault("ReadGlossaries", false)), m_bInTableStyleRunProps(false), m_nTableDepth(0), m_nTableCellDepth(0), diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 1bcde463a34c..aabc939cbcff 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -548,6 +548,7 @@ public: css::uno::Reference m_xInsertTextRange; private: bool const m_bIsNewDoc; + bool const m_bIsReadGlossaries; public: DomainMapper_Impl( DomainMapper& rDMapper, @@ -916,6 +917,9 @@ public: /// If we're importing into a new document, or just pasting to an existing one. bool IsNewDoc() { return m_bIsNewDoc;} + /// If we're importing autotext. + bool IsReadGlossaries() { return m_bIsReadGlossaries;} + /// If we're inside , inside bool m_bInTableStyleRunProps; diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index cd74eee85cd3..09e82725fd98 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -1642,10 +1642,13 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) if ( xRangeProperties.is() && rDM_Impl.IsNewDoc() ) { - xRangeProperties->setPropertyValue( - getPropertyName( PROP_PAGE_DESC_NAME ), - uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName - : m_sFollowPageStyleName ) ); + // 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. + if (!rDM_Impl.IsReadGlossaries()) + xRangeProperties->setPropertyValue( + getPropertyName( PROP_PAGE_DESC_NAME ), + uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName + : m_sFollowPageStyleName ) ); if (0 <= m_nPageNumber) {