[Libreoffice-commits] core.git: sw/qa sw/source

Tamas Bunth tamas.bunth at collabora.co.uk
Tue Nov 28 08:29:55 UTC 2017


 sw/qa/extras/ooxmlexport/data/tdf44832_section_new_header.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx                    |   10 ++
 sw/source/filter/ww8/docxexport.cxx                           |   34 +++++++---
 sw/source/filter/ww8/docxexport.hxx                           |    2 
 4 files changed, 36 insertions(+), 10 deletions(-)

New commits:
commit 6aa1df5a627697e6adaee70adcef2c5b50cfcbf7
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date:   Thu Nov 16 15:43:36 2017 +0100

    tdf#41650 DOCX export: insert empty header/footer
    
    Insert an empty header (or footer) to section which follows a section
    with a header in it.
    
    It is needed, because in case a section does not contain a header
    definition, Word will use the preceding section's rule.
    
    It causes problem if a document contains two page styles: one has
    header (or footer), the other does not. In that case after saving to
    docx it will end up in two sections. (only if it's not a plausable title
    page)
    
    Change-Id: I5add284d0cf1544923885e7205d9a2ac4e3cc9af
    Reviewed-on: https://gerrit.libreoffice.org/44832
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
    Tested-by: Tamás Bunth <btomi96 at gmail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf44832_section_new_header.odt b/sw/qa/extras/ooxmlexport/data/tdf44832_section_new_header.odt
new file mode 100644
index 000000000000..9db311db1f2a
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf44832_section_new_header.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index 116b3f05bb2b..40081112629d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -99,6 +99,16 @@ DECLARE_OOXMLEXPORT_TEST(testTdf67207_MERGEFIELD, "mailmerge.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.text.fieldmaster.DataBase.Name"), sValue);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf44832_testSectionWithDifferentHeader, "tdf44832_section_new_header.odt")
+{
+    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+
+    if(!pXmlDoc)
+        return;
+
+    assertXPath(pXmlDoc, "/w:document/w:body/w:sectPr/w:headerReference", 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 78b116ab920f..03a225fd9792 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -255,7 +255,7 @@ bool DocxExport::DisallowInheritingOutlineNumbering( const SwFormat& rFormat )
 }
 
 void DocxExport::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
-        const SwFrameFormat& rFormat, const SwFrameFormat& rLeftFormat, const SwFrameFormat& rFirstPageFormat, sal_uInt8 /*nBreakCode*/ )
+        const SwFrameFormat& rFormat, const SwFrameFormat& rLeftFormat, const SwFrameFormat& rFirstPageFormat, sal_uInt8 nBreakCode )
 {
     m_nHeadersFootersInSection = 1;
     // Turn ON flag for 'Writing Headers \ Footers'
@@ -263,23 +263,36 @@ void DocxExport::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
 
     // headers
     if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_EVEN )
-        WriteHeaderFooter( rLeftFormat, true, "even" );
+        WriteHeaderFooter( &rLeftFormat, true, "even" );
 
     if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
-        WriteHeaderFooter( rFormat, true, "default" );
+        WriteHeaderFooter( &rFormat, true, "default" );
 
     if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_FIRST )
-        WriteHeaderFooter( rFirstPageFormat, true, "first" );
+        WriteHeaderFooter( &rFirstPageFormat, true, "first" );
+
+    if( (nHeadFootFlags & (nsHdFtFlags::WW8_HEADER_EVEN
+                         | nsHdFtFlags::WW8_HEADER_ODD
+                         | nsHdFtFlags::WW8_HEADER_FIRST)) == 0
+            && m_bHasHdr && nBreakCode == 2 ) // 2: nexPage
+        WriteHeaderFooter( nullptr, true, "default" );
+
 
     // footers
     if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_EVEN )
-        WriteHeaderFooter( rLeftFormat, false, "even" );
+        WriteHeaderFooter( &rLeftFormat, false, "even" );
 
     if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
-        WriteHeaderFooter( rFormat, false, "default" );
+        WriteHeaderFooter( &rFormat, false, "default" );
 
     if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_FIRST )
-        WriteHeaderFooter( rFirstPageFormat, false, "first" );
+        WriteHeaderFooter( &rFirstPageFormat, false, "first" );
+
+    if( (nHeadFootFlags & (nsHdFtFlags::WW8_FOOTER_EVEN
+                         | nsHdFtFlags::WW8_FOOTER_ODD
+                         | nsHdFtFlags::WW8_FOOTER_FIRST)) == 0
+            && m_bHasFtr && nBreakCode == 2 ) // 2: nexPage
+        WriteHeaderFooter( nullptr, false, "default");
 
     if ( nHeadFootFlags & ( nsHdFtFlags::WW8_FOOTER_EVEN | nsHdFtFlags::WW8_HEADER_EVEN ))
         m_aSettings.evenAndOddHeaders = true;
@@ -760,7 +773,7 @@ void DocxExport::WriteNumbering()
     m_pAttrOutput->SetSerializer( m_pDocumentFS );
 }
 
-void DocxExport::WriteHeaderFooter( const SwFormat& rFormat, bool bHeader, const char* pType )
+void DocxExport::WriteHeaderFooter( const SwFormat* pFormat, bool bHeader, const char* pType )
 {
     // setup the xml stream
     OUString aRelId;
@@ -806,7 +819,10 @@ void DocxExport::WriteHeaderFooter( const SwFormat& rFormat, bool bHeader, const
     //So clearing the alternate content graphic cache.
     m_pAttrOutput->PushRelIdCache();
     // do the work
-    WriteHeaderFooterText( rFormat, bHeader );
+    if( pFormat == nullptr )
+        AttrOutput().EmptyParagraph();
+    else
+        WriteHeaderFooterText( *pFormat, bHeader );
     m_pAttrOutput->PopRelIdCache();
     m_pAttrOutput->popFromTableExportContext(aTableExportContext);
     m_pAttrOutput->EndParaSdtBlock();
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index b553ba3f2601..65cf02fe2a1d 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -228,7 +228,7 @@ private:
     virtual void WriteNumbering() override;
 
     /// Write reference to a header/footer + the actual xml containing the text.
-    void WriteHeaderFooter( const SwFormat& rFormat, bool bHeader, const char* pType );
+    void WriteHeaderFooter( const SwFormat* pFormat, bool bHeader, const char* pType );
 
     /// Write word/fontTable.xml.
     void WriteFonts();


More information about the Libreoffice-commits mailing list