From f10ab3425f02a4caea22b2bdbf60a731bd059419 Mon Sep 17 00:00:00 2001 From: Eilidh McAdam Date: Wed, 18 Mar 2015 01:33:43 +0000 Subject: tdf#78606: Write DOCX header even if section is first paragraph Header flags are now set prior to export if a section is the first thing in the document (ODF -> DOCX). Change-Id: I84ba61c11da78a012938163d986ee5fcd301d405 Reviewed-on: https://gerrit.libreoffice.org/15369 Reviewed-by: Miklos Vajna Tested-by: Miklos Vajna --- sw/source/filter/ww8/docxattributeoutput.hxx | 1 + sw/source/filter/ww8/docxexport.cxx | 2 +- sw/source/filter/ww8/wrtw8sty.cxx | 7 ++++--- sw/source/filter/ww8/wrtww8.hxx | 12 ++++++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 3acde5bfcacf..70f5cc37fe90 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -974,6 +974,7 @@ public: void GetSdtEndBefore(const SdrObject* pSdrObj); void SetStartedParaSdt(bool bStartedParaSdt); bool IsStartedParaSdt(); + bool IsFirstParagraph() { return m_bIsFirstParagraph; } /// Stores the table export state to the passed context and resets own state. void pushToTableExportContext(DocxTableExportContext& rContext); diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 24900660220b..cb48a7f28a2e 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -460,7 +460,7 @@ void DocxExport::ExportDocument_Impl() void DocxExport::AppendSection( const SwPageDesc *pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum ) { AttrOutput().SectionBreak( msword::PageBreak, m_pSections->CurrentSectionInfo() ); - m_pSections->AppendSection( pPageDesc, pFmt, nLnNum ); + m_pSections->AppendSection( pPageDesc, pFmt, nLnNum, m_pAttrOutput->IsFirstParagraph() ); } void DocxExport::OutputEndNode( const SwEndNode& rEndNode ) diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index d3c0488c4870..1b4a5d972c13 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -1157,12 +1157,12 @@ const WW8_SepInfo* MSWordSections::CurrentSectionInfo() } void MSWordSections::AppendSection( const SwPageDesc* pPd, - const SwSectionFmt* pSectionFmt, sal_uLong nLnNumRestartNo ) + const SwSectionFmt* pSectionFmt, sal_uLong nLnNumRestartNo, bool bIsFirstParagraph ) { if (HeaderFooterWritten()) { return; // #i117955# prevent new sections in endnotes } - aSects.push_back( WW8_SepInfo( pPd, pSectionFmt, nLnNumRestartNo ) ); + aSects.push_back( WW8_SepInfo( pPd, pSectionFmt, nLnNumRestartNo, boost::none, NULL, bIsFirstParagraph ) ); NeedsDocumentProtected( aSects.back() ); } @@ -1828,7 +1828,8 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt ? &pPd->GetFollow()->GetMaster() : &pPd->GetLeft(); - if ( nBreakCode != 0 ) + // Ensure that headers are written if section is first paragraph + if ( nBreakCode != 0 || ( rSepInfo.pSectionFmt && rSepInfo.bIsFirstParagraph )) { if ( titlePage ) { diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index 1a35a6521234..372789beca76 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -164,16 +164,19 @@ struct WW8_SepInfo const SwTxtNode* pNumNd; sal_uLong nLnNumRestartNo; ::boost::optional oPgRestartNo; + bool bIsFirstParagraph; WW8_SepInfo() - : pPageDesc(0), pSectionFmt(0), pPDNd(0), pNumNd(0), nLnNumRestartNo(0) + : pPageDesc(0), pSectionFmt(0), pPDNd(0), pNumNd(0), nLnNumRestartNo(0), bIsFirstParagraph(false) {} WW8_SepInfo( const SwPageDesc* pPD, const SwSectionFmt* pFmt, - sal_uLong nLnRestart, ::boost::optional oPgRestart = boost::none, const SwNode* pNd = NULL ) + sal_uLong nLnRestart, ::boost::optional oPgRestart = boost::none, + const SwNode* pNd = NULL, bool bIsFirstPara = false ) : pPageDesc( pPD ), pSectionFmt( pFmt ), pPDNd( pNd ), pNumNd( 0 ), - nLnNumRestartNo( nLnRestart ), oPgRestartNo( oPgRestart ) + nLnNumRestartNo( nLnRestart ), oPgRestartNo( oPgRestart ), + bIsFirstParagraph( bIsFirstPara ) {} bool IsProtected() const; @@ -202,7 +205,8 @@ public: void AppendSection( const SwPageDesc* pPd, const SwSectionFmt* pSectionFmt = 0, - sal_uLong nLnNumRestartNo = 0 ); + sal_uLong nLnNumRestartNo = 0, + bool bIsFirstParagraph = false ); void AppendSection( const SwFmtPageDesc& rPd, const SwNode& rNd, const SwSectionFmt* pSectionFmt, -- cgit v1.2.3