From 378b97e8f071485ee1086b66f1ab94fedb8b8d49 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 13 Jun 2017 09:05:06 +0200 Subject: tdf#107618 DOCX export: fix missing header when doc ends with section See commit b6e62dc0dc2b284c825f1182a67bb2f9259a30ce (tdf#106492 DOCX export: fix duplicated section break at doc end, 2017-03-21) for the context, this is one more case where it's not OK to suppress the two section breaks at the end of a document, since the suppressed section break is the one that provides the headers / footers. (cherry picked from commit 2a73e7d88c19cab69733a4f6433d8576856285ac) Change-Id: I4abd7895436e4d2e08fd7b7ff4aabbac8d65f7fb Reviewed-on: https://gerrit.libreoffice.org/38742 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- sw/qa/extras/ooxmlexport/data/tdf107618.doc | Bin 0 -> 28160 bytes sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 7 +++++ sw/source/filter/ww8/docxattributeoutput.cxx | 41 ++++++++++++++++++++------- 3 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf107618.doc diff --git a/sw/qa/extras/ooxmlexport/data/tdf107618.doc b/sw/qa/extras/ooxmlexport/data/tdf107618.doc new file mode 100644 index 000000000000..8a6972f45b8e Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf107618.doc differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 38582f9f93f0..d63a6183c5ba 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -581,6 +581,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf107684, "tdf107684.odt") assertXPath(pXmlDoc, "//w:style[@w:styleId='Heading1']/w:pPr/w:outlineLvl", 1); } +DECLARE_OOXMLEXPORT_TEST(testTdf107618, "tdf107618.doc") +{ + // This was false, header was lost on export. + uno::Reference xPageStyle(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(true, getProperty(xPageStyle, "HeaderIsOn")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 89597ef3baf6..b42aa62f47db 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -118,6 +118,7 @@ #include #include #include +#include #include #include #include @@ -5495,25 +5496,43 @@ void DocxAttributeOutput::SectionBreak( sal_uInt8 nC, const WW8_SepInfo* pSectio // DocxExport::WriteMainText(), don't duplicate that here. SwNodeIndex aCurrentNode(m_rExport.m_pCurPam->GetNode()); SwNodeIndex aLastNode(m_rExport.m_pDoc->GetNodes().GetEndOfContent(), -1); + bool bEmit = aCurrentNode != aLastNode; - // Need to still emit an empty section at the end of the - // document in case balanced columns are wanted, since the last - // section in Word is always balanced. - sal_uInt16 nColumns = 1; - bool bBalance = false; - if (const SwSectionFormat* pFormat = pSectionInfo->pSectionFormat) + if (!bEmit) { - if (pFormat != reinterpret_cast(sal_IntPtr(-1))) + // Need to still emit an empty section at the end of the + // document in case balanced columns are wanted, since the last + // section in Word is always balanced. + sal_uInt16 nColumns = 1; + bool bBalance = false; + if (const SwSectionFormat* pFormat = pSectionInfo->pSectionFormat) { - nColumns = pFormat->GetCol().GetNumCols(); - const SwFormatNoBalancedColumns& rNoBalanced = pFormat->GetBalancedColumns(); - bBalance = !rNoBalanced.GetValue(); + if (pFormat != reinterpret_cast(sal_IntPtr(-1))) + { + nColumns = pFormat->GetCol().GetNumCols(); + const SwFormatNoBalancedColumns& rNoBalanced = pFormat->GetBalancedColumns(); + bBalance = !rNoBalanced.GetValue(); + } + } + bEmit = (nColumns > 1 && bBalance); + } + + if (!bEmit) + { + // Also need to emit if the page desc contains a header or + // footer, otherwise we go with the properties of the + // section (and not the page style), which never has + // headers/footers. + if (const SwPageDesc* pPageDesc = pSectionInfo->pPageDesc) + { + const auto& rMaster = pPageDesc->GetMaster(); + bEmit = rMaster.GetHeader().IsActive() || rMaster.GetFooter().IsActive(); } } // don't add section properties if this will be the first // paragraph in the document - if ( !m_bParagraphOpened && !m_bIsFirstParagraph && (aCurrentNode != aLastNode || (nColumns > 1 && bBalance))) + if ( !m_bParagraphOpened && !m_bIsFirstParagraph && bEmit ) { // Create a dummy paragraph if needed m_pSerializer->startElementNS( XML_w, XML_p, FSEND ); -- cgit v1.2.3