[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - sw/qa writerfilter/source

Luboš Luňák l.lunak at collabora.com
Fri May 30 02:19:04 PDT 2014


 sw/qa/extras/ooxmlimport/data/bnc875718.docx      |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx          |   23 ++++++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   14 +++++++++----
 3 files changed, 33 insertions(+), 4 deletions(-)

New commits:
commit a04f9501508a6b93d2f5d38a17ff77efd7a8421a
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sat May 24 00:36:06 2014 +0200

    discard more header/footer stuff when discarding headers/footers (bnc#875718)
    
    782adba4d436c65cdf85d48f28486321873b15ed discards unneeded headers/footers,
    but only the text, not e.g. frames or fields. The test document therefore
    ends up with a frame with a page number inside the body text, because the text
    in the footer it should be anchored to was discarded. This commit fixes
    this by discarding more (although probably the whole header/footer
    shouldn't even be parsed to begin with).
    
    The test from b349d2483e1fe64316d87b55d0b3b4c8f2293e2e actually checked
    for this incorrect frame, so change that (the whole test is suspicious, as
    the end result is quite far away from what the original doc looks like).
    
    (cherry picked from commit 5510f563502168defa4ccfc54214d781a7c92868)
    Signed-off-by: Andras Timar <andras.timar at collabora.com>
    
    Conflicts:
    	sw/qa/extras/ooxmlexport/ooxmlexport.cxx
    	sw/qa/extras/ooxmlimport/ooxmlimport.cxx
    
    Change-Id: I2e7192e00237db1f030d0524c5667fe92c9e496b

diff --git a/sw/qa/extras/ooxmlimport/data/bnc875718.docx b/sw/qa/extras/ooxmlimport/data/bnc875718.docx
new file mode 100644
index 0000000..878a46f
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/bnc875718.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 6c2f3a7..7f7078c 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1654,6 +1654,29 @@ DECLARE_OOXMLIMPORT_TEST(testFdo55381, "fdo55381.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int16(4), xCursor->getPage());
 }
 
+DECLARE_OOXMLIMPORT_TEST(testBnc875718, "bnc875718.docx")
+{
+    // The frame in the footer must not accidentally end up in the document body.
+    // The easiest way for this to test I've found is checking that
+    // xray ThisComponent.TextFrames.GetByIndex( index ).Anchor.Text.ImplementationName
+    // is not SwXBodyText but rather SwXHeadFootText
+    uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
+    for( int i = 0;
+         i < xIndexAccess->getCount();
+         ++i )
+    {
+        uno::Reference<text::XTextFrame> frame(xIndexAccess->getByIndex( i ), uno::UNO_QUERY);
+        uno::Reference<text::XTextRange> range(frame->getAnchor(), uno::UNO_QUERY);
+        uno::Reference<lang::XServiceInfo> text(range->getText(), uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL( OUString( "SwXHeadFootText" ), text->getImplementationName());
+    }
+    // Also check that the footer contents are not in the body text.
+    uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
+    uno::Reference<text::XText> text(textDocument->getText(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL( OUString( "Text\n" ), text->getString());
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 7f61328..2e6538a 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2293,6 +2293,8 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::FindOrCreateFieldMaster
   -----------------------------------------------------------------------*/
 void DomainMapper_Impl::PushFieldContext()
 {
+    if(m_bDiscardHeaderFooter)
+        return;
 #ifdef DEBUG_DOMAINMAPPER
     dmapper_logger->element("pushFieldContext");
 #endif
@@ -2980,6 +2982,8 @@ void DomainMapper_Impl::handleToc
   -----------------------------------------------------------------------*/
 void DomainMapper_Impl::CloseFieldCommand()
 {
+    if(m_bDiscardHeaderFooter)
+        return;
 #ifdef DEBUG_DOMAINMAPPER
     dmapper_logger->element("closeFieldCommand");
 #endif
@@ -3660,6 +3664,8 @@ void DomainMapper_Impl::SetFieldFFData(FFDataHandler::Pointer_t pFFDataHandler)
   -----------------------------------------------------------------------*/
 void DomainMapper_Impl::PopFieldContext()
 {
+    if(m_bDiscardHeaderFooter)
+        return;
 #ifdef DEBUG_DOMAINMAPPER
     dmapper_logger->element("popFieldContext");
 #endif
@@ -3955,7 +3961,7 @@ void DomainMapper_Impl::RegisterFrameConversion(
 bool DomainMapper_Impl::ExecuteFrameConversion()
 {
     bool bRet = false;
-    if( m_xFrameStartRange.is() && m_xFrameEndRange.is() )
+    if( m_xFrameStartRange.is() && m_xFrameEndRange.is() && !m_bDiscardHeaderFooter )
     {
         bRet = true;
         try
@@ -3971,10 +3977,10 @@ bool DomainMapper_Impl::ExecuteFrameConversion()
             SAL_WARN( "writerfilter", "Exception caught when converting to frame: " + rEx.Message );
             bRet = false;
         }
-        m_xFrameStartRange = 0;
-        m_xFrameEndRange = 0;
-        m_aFrameProperties.realloc( 0 );
     }
+    m_xFrameStartRange = 0;
+    m_xFrameEndRange = 0;
+    m_aFrameProperties.realloc( 0 );
     return bRet;
 }
 


More information about the Libreoffice-commits mailing list