[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - writerfilter/qa writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Oct 27 15:35:38 UTC 2020


 writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx |   18 ++++++++++---
 writerfilter/qa/cppunittests/dmapper/data/alt-chunk.docx   |binary
 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 +++-
 6 files changed, 48 insertions(+), 7 deletions(-)

New commits:
commit d67222fcc614127ced2c66c2aa718d41478f6141
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Oct 26 17:52:42 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Oct 27 16:35:01 2020 +0100

    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.
    
    (cherry picked from commit 32c322e9d037b29ded2297b400a2c596c042f1fa)
    
    Conflicts:
            writerfilter/source/dmapper/DomainMapper_Impl.hxx
    
    Change-Id: Id3955f2b35a139692254c4ac1233e96eef2620e9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104886
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
index 16d8b1f3b4b0..2944d596c14f 100644
--- a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
@@ -90,16 +90,28 @@ CPPUNIT_TEST_FIXTURE(Test, testAltChunk)
                                                                   uno::UNO_QUERY);
     uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
     uno::Reference<text::XTextRange> xPara;
+    uno::Reference<beans::XPropertySet> xParaProps;
     xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(OUString("Outer para 1"), xPara->getString());
+    xParaProps.set(xPara, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("outer, before sect break"), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
+                         xParaProps->getPropertyValue("PageStyleName").get<OUString>());
     xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(OUString("Outer para 2"), xPara->getString());
+    xParaProps.set(xPara, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("outer, after sect break"), xPara->getString());
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: Converted1
+    // - Actual  : Standard
+    // i.e. the page break between the first and the second paragraph was missing.
+    CPPUNIT_ASSERT_EQUAL(OUString("Converted1"),
+                         xParaProps->getPropertyValue("PageStyleName").get<OUString>());
 
     // Without the accompanying fix in place, this test would have failed with a
     // container.NoSuchElementException, as the document had only 2 paragraphs, all the "inner"
     // content was lost.
     xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(OUString("Inner para 1"), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString("inner doc, first para"), xPara->getString());
 }
 }
 
diff --git a/writerfilter/qa/cppunittests/dmapper/data/alt-chunk.docx b/writerfilter/qa/cppunittests/dmapper/data/alt-chunk.docx
index 3348cfd0c04c..40d071ff40a6 100644
Binary files a/writerfilter/qa/cppunittests/dmapper/data/alt-chunk.docx and b/writerfilter/qa/cppunittests/dmapper/data/alt-chunk.docx differ
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 4071a05dafe7..351bc391622d 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1036,7 +1036,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:
@@ -2040,9 +2040,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 edb2e348e438..5439c51ec767 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -249,7 +249,9 @@ DomainMapper_Impl::DomainMapper_Impl(
         m_aAnnotationPositions(),
         m_aSmartTagHandler(m_xComponentContext, m_xTextDocument),
         m_xInsertTextRange(rMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference<text::XTextRange>())),
+        m_xAltChunkStartingRange(rMediaDesc.getUnpackedValueOrDefault("AltChunkStartingRange", uno::Reference<text::XTextRange>())),
         m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)),
+        m_bIsAltChunk(rMediaDesc.getUnpackedValueOrDefault("AltChunkMode", false)),
         m_bIsReadGlossaries(rMediaDesc.getUnpackedValueOrDefault("ReadGlossaries", false)),
         m_bInTableStyleRunProps(false),
         m_nTableDepth(0),
@@ -292,6 +294,11 @@ DomainMapper_Impl::DomainMapper_Impl(
     m_pSdtHelper = new SdtHelper(*this);
 
     m_aRedlines.push(std::vector<RedlineParamsPtr>());
+
+    if (m_bIsAltChunk)
+    {
+        m_bIsFirstSection = false;
+    }
 }
 
 
@@ -2687,10 +2694,18 @@ void DomainMapper_Impl::HandleAltChunk(const OUString& rStreamName)
         uno::Reference<io::XStream> xInputStream = new utl::OStreamWrapper(aMemory);
         // Not handling AltChunk during paste for now.
         uno::Reference<text::XTextRange> xInsertTextRange = GetCurrentXText()->getEnd();
+        uno::Reference<text::XTextRange> xSectionStartingRange;
+        SectionPropertyMap* pSectionContext = GetSectionContext();
+        if (pSectionContext)
+        {
+            xSectionStartingRange = pSectionContext->GetStartingRange();
+        }
         uno::Sequence<beans::PropertyValue> 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 588f6f121dfb..1c2dd23d6969 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -561,8 +561,10 @@ private:
 
 public:
     css::uno::Reference<css::text::XTextRange> m_xInsertTextRange;
+    css::uno::Reference<css::text::XTextRange> m_xAltChunkStartingRange;
 private:
     bool const m_bIsNewDoc;
+    bool m_bIsAltChunk = false;
     bool const m_bIsReadGlossaries;
 public:
     DomainMapper_Impl(
@@ -939,6 +941,8 @@ public:
     /// If we're importing into a new document, or just pasting to an existing one.
     bool IsNewDoc() { return m_bIsNewDoc;}
 
+    bool IsAltChunk() const { return m_bIsAltChunk;}
+
     /// If we're importing autotext.
     bool IsReadGlossaries() { return m_bIsReadGlossaries;}
 
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 82de1085db86..a13c6f1f5df9 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -1673,7 +1673,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.


More information about the Libreoffice-commits mailing list