summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2017-11-16 15:43:36 +0100
committerTamás Bunth <btomi96@gmail.com>2017-11-28 09:29:25 +0100
commit6aa1df5a627697e6adaee70adcef2c5b50cfcbf7 (patch)
tree1b10c436dfc7677466bfd69a9983257dfe139ff6 /sw
parent746b26525b09274832ab17358be843a703129b30 (diff)
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@gmail.com> Tested-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf44832_section_new_header.odtbin0 -> 19830 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport11.cxx10
-rw-r--r--sw/source/filter/ww8/docxexport.cxx34
-rw-r--r--sw/source/filter/ww8/docxexport.hxx2
4 files changed, 36 insertions, 10 deletions
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
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf44832_section_new_header.odt
Binary files 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();