summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorDaniel Arato (NISZ) <arato.daniel@nisz.hu>2021-02-05 12:07:48 +0100
committerLászló Németh <nemeth@numbertext.org>2021-05-04 19:14:22 +0200
commit88e6a1bfeac86e0c89d2ff08c908c2b5ae061177 (patch)
tree1a5ffede7763cdf7d7770ab4a8e4e787c5d7ac69 /sw/source
parent30512746c182b52f37f9a818d4e206c98e715cb7 (diff)
tdf#69635 DOCX: export hidden (shared) headers/footers
Exporting to .docx used to lose all header and footer content that was not visible in the document at the moment of saving. This commit forces the DocxExport class to output all headers and footers even when the "Same content on left and right pages" option is turned on. Change-Id: I6a52f216f1e1b386d887ec614198766670b5bce3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113158 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/filter/ww8/docxexport.cxx9
-rw-r--r--sw/source/filter/ww8/docxexport.hxx3
-rw-r--r--sw/source/filter/ww8/rtfexport.cxx10
-rw-r--r--sw/source/filter/ww8/rtfexport.hxx6
-rw-r--r--sw/source/filter/ww8/wrtw8sty.cxx95
-rw-r--r--sw/source/filter/ww8/wrtww8.hxx8
6 files changed, 106 insertions, 25 deletions
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 6527696bce29..0590fea71d35 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -247,12 +247,13 @@ 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& rLeftHeaderFormat, const SwFrameFormat& rLeftFooterFormat, const SwFrameFormat& rFirstPageFormat,
+ sal_uInt8 nBreakCode, bool bEvenAndOddHeaders )
{
m_nHeadersFootersInSection = 1;
// document setting indicating the requirement of EVEN and ODD for both headers and footers
- if ( nHeadFootFlags & ( nsHdFtFlags::WW8_FOOTER_EVEN | nsHdFtFlags::WW8_HEADER_EVEN ))
+ if ( nHeadFootFlags & ( nsHdFtFlags::WW8_FOOTER_EVEN | nsHdFtFlags::WW8_HEADER_EVEN ) && bEvenAndOddHeaders )
m_aSettings.evenAndOddHeaders = true;
// Turn ON flag for 'Writing Headers \ Footers'
@@ -260,7 +261,7 @@ void DocxExport::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
// headers
if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_EVEN )
- WriteHeaderFooter( &rLeftFormat, true, "even" );
+ WriteHeaderFooter( &rLeftHeaderFormat, true, "even" );
else if ( m_aSettings.evenAndOddHeaders )
{
if ( nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD )
@@ -284,7 +285,7 @@ void DocxExport::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
// footers
if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_EVEN )
- WriteHeaderFooter( &rLeftFormat, false, "even" );
+ WriteHeaderFooter( &rLeftFooterFormat, false, "even" );
else if ( m_aSettings.evenAndOddHeaders )
{
if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD )
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index 381de49a7ef4..bc96ba187100 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -160,7 +160,8 @@ public:
/// Output the actual headers and footers.
virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
- const SwFrameFormat& rFormat, const SwFrameFormat& rLeftFormat, const SwFrameFormat& rFirstPageFormat, sal_uInt8 nBreakCode ) override;
+ const SwFrameFormat& rFormat, const SwFrameFormat& rLeftHeaderFormat, const SwFrameFormat& rLeftFooterFormat, const SwFrameFormat& rFirstPageFormat,
+ sal_uInt8 nBreakCode, bool bEvenAndOddHeaders ) override;
/// Write the field
virtual void OutputField( const SwField* pField, ww::eField eFieldType,
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index ca3247ba3498..4b4712a7bf09 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -286,12 +286,14 @@ void RtfExport::WriteRevTab()
}
void RtfExport::WriteHeadersFooters(sal_uInt8 nHeadFootFlags, const SwFrameFormat& rFormat,
- const SwFrameFormat& rLeftFormat,
- const SwFrameFormat& rFirstPageFormat, sal_uInt8 /*nBreakCode*/)
+ const SwFrameFormat& rLeftHeaderFormat,
+ const SwFrameFormat& rLeftFooterFormat,
+ const SwFrameFormat& rFirstPageFormat, sal_uInt8 /*nBreakCode*/,
+ bool /*bEvenAndOddHeaders*/)
{
// headers
if (nHeadFootFlags & nsHdFtFlags::WW8_HEADER_EVEN)
- WriteHeaderFooter(rLeftFormat, true, OOO_STRING_SVTOOLS_RTF_HEADERL);
+ WriteHeaderFooter(rLeftHeaderFormat, true, OOO_STRING_SVTOOLS_RTF_HEADERL);
if (nHeadFootFlags & nsHdFtFlags::WW8_HEADER_ODD)
WriteHeaderFooter(rFormat, true, OOO_STRING_SVTOOLS_RTF_HEADER);
@@ -301,7 +303,7 @@ void RtfExport::WriteHeadersFooters(sal_uInt8 nHeadFootFlags, const SwFrameForma
// footers
if (nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_EVEN)
- WriteHeaderFooter(rLeftFormat, false, OOO_STRING_SVTOOLS_RTF_FOOTERL);
+ WriteHeaderFooter(rLeftFooterFormat, false, OOO_STRING_SVTOOLS_RTF_FOOTERL);
if (nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_ODD)
WriteHeaderFooter(rFormat, false, OOO_STRING_SVTOOLS_RTF_FOOTER);
diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx
index 83b9a34a9e76..9b33c1304659 100644
--- a/sw/source/filter/ww8/rtfexport.hxx
+++ b/sw/source/filter/ww8/rtfexport.hxx
@@ -94,8 +94,10 @@ public:
/// Output the actual headers and footers.
void WriteHeadersFooters(sal_uInt8 nHeadFootFlags, const SwFrameFormat& rFormat,
- const SwFrameFormat& rLeftFormat,
- const SwFrameFormat& rFirstPageFormat, sal_uInt8 nBreakCode) override;
+ const SwFrameFormat& rLeftHeaderFormat,
+ const SwFrameFormat& rLeftFooterFormat,
+ const SwFrameFormat& rFirstPageFormat, sal_uInt8 nBreakCode,
+ bool bEvenAndOddHeaders) override;
/// Write the field
void OutputField(const SwField* pField, ww::eField eFieldType, const OUString& rFieldCmd,
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 282bd90efab9..08e54ab628cf 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1501,7 +1501,7 @@ void WW8AttributeOutput::TextVerticalAdjustment( const drawing::TextVerticalAdju
}
void WW8Export::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
- const SwFrameFormat& rFormat, const SwFrameFormat& rLeftFormat, const SwFrameFormat& rFirstPageFormat, sal_uInt8 nBreakCode )
+ const SwFrameFormat& rFormat, const SwFrameFormat& rLeftHeaderFormat, const SwFrameFormat& rLeftFooterFormat, const SwFrameFormat& rFirstPageFormat, sal_uInt8 nBreakCode, bool /*bEvenAndOddHeaders*/ )
{
sal_uLong nCpPos = Fc2Cp( Strm().Tell() );
@@ -1509,7 +1509,7 @@ void WW8Export::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
if ( !(nHeadFootFlags & WW8_HEADER_EVEN) && pDop->fFacingPages )
pSepx->OutHeaderFooter( *this, true, rFormat, nCpPos, nHeadFootFlags, WW8_HEADER_ODD, nBreakCode );
else
- pSepx->OutHeaderFooter( *this, true, rLeftFormat, nCpPos, nHeadFootFlags, WW8_HEADER_EVEN, nBreakCode );
+ pSepx->OutHeaderFooter( *this, true, rLeftHeaderFormat, nCpPos, nHeadFootFlags, WW8_HEADER_EVEN, nBreakCode );
IncrementHdFtIndex();
pSepx->OutHeaderFooter( *this, true, rFormat, nCpPos, nHeadFootFlags, WW8_HEADER_ODD, nBreakCode );
@@ -1517,7 +1517,7 @@ void WW8Export::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
if ( !(nHeadFootFlags & WW8_FOOTER_EVEN) && pDop->fFacingPages )
pSepx->OutHeaderFooter( *this, false, rFormat, nCpPos, nHeadFootFlags, WW8_FOOTER_ODD, nBreakCode );
else
- pSepx->OutHeaderFooter( *this, false, rLeftFormat, nCpPos, nHeadFootFlags, WW8_FOOTER_EVEN, nBreakCode );
+ pSepx->OutHeaderFooter( *this, false, rLeftFooterFormat, nCpPos, nHeadFootFlags, WW8_FOOTER_EVEN, nBreakCode );
IncrementHdFtIndex();
pSepx->OutHeaderFooter( *this, false, rFormat, nCpPos, nHeadFootFlags, WW8_FOOTER_ODD, nBreakCode );
@@ -1821,10 +1821,59 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
// Header or Footer
sal_uInt8 nHeadFootFlags = 0;
-
- const SwFrameFormat* pPdLeftFormat = bLeftRightPgChain
- ? &pPd->GetFollow()->GetFirstLeft()
- : &pPd->GetLeft();
+ // Should we output a w:evenAndOddHeaders tag or not?
+ // N.B.: despite its name this tag affects _both_ headers and footers!
+ bool bEvenAndOddHeaders = true;
+ bool bEvenAndOddFooters = true;
+
+ const SwFrameFormat* pPdLeftHeaderFormat = nullptr;
+ const SwFrameFormat* pPdLeftFooterFormat = nullptr;
+ if (bLeftRightPgChain)
+ {
+ const SwFrameFormat* pHeaderFormat = pPd->GetStashedFrameFormat(true, true, true);
+ const SwFrameFormat* pFooterFormat = pPd->GetStashedFrameFormat(false, true, true);
+ if (pHeaderFormat)
+ {
+ pPdLeftHeaderFormat = pHeaderFormat;
+ bEvenAndOddHeaders = false;
+ }
+ else
+ {
+ pPdLeftHeaderFormat = &pPd->GetFollow()->GetFirstLeft();
+ }
+ if (pFooterFormat)
+ {
+ pPdLeftFooterFormat = pFooterFormat;
+ bEvenAndOddFooters = false;
+ }
+ else
+ {
+ pPdLeftFooterFormat = &pPd->GetFollow()->GetFirstLeft();
+ }
+ }
+ else
+ {
+ const SwFrameFormat* pHeaderFormat = pPd->GetStashedFrameFormat(true, true, false);
+ const SwFrameFormat* pFooterFormat = pPd->GetStashedFrameFormat(false, true, false);
+ if (pHeaderFormat)
+ {
+ pPdLeftHeaderFormat = pHeaderFormat;
+ bEvenAndOddHeaders = false;
+ }
+ else
+ {
+ pPdLeftHeaderFormat = &pPd->GetLeft();
+ }
+ if (pFooterFormat)
+ {
+ pPdLeftFooterFormat = pFooterFormat;
+ bEvenAndOddFooters = false;
+ }
+ else
+ {
+ pPdLeftFooterFormat = &pPd->GetLeft();
+ }
+ }
// Ensure that headers are written if section is first paragraph
if ( nBreakCode != 0 || bEnsureHeaderFooterWritten )
@@ -1835,14 +1884,40 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdFirstPgFormat, WW8_HEADER_FIRST );
MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdFirstPgFormat, WW8_FOOTER_FIRST );
}
+ else
+ {
+ if ( pPd->GetStashedFrameFormat(true, true, true) && pPdLeftHeaderFormat && pPdLeftHeaderFormat->GetHeader().GetHeaderFormat() )
+ {
+ MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdLeftHeaderFormat, WW8_HEADER_FIRST );
+ }
+ if ( pPd->GetStashedFrameFormat(false, true, true) && pPdLeftFooterFormat && pPdLeftFooterFormat->GetFooter().GetFooterFormat() )
+ {
+ MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdLeftFooterFormat, WW8_FOOTER_FIRST );
+ }
+ }
+
MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdFormat, WW8_HEADER_ODD );
MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdFormat, WW8_FOOTER_ODD );
if ( !pPd->IsHeaderShared() || bLeftRightPgChain )
- MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdLeftFormat, WW8_HEADER_EVEN );
+ {
+ MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdLeftHeaderFormat, WW8_HEADER_EVEN );
+ }
+ else if ( pPd->IsHeaderShared() && pPd->GetStashedFrameFormat(true, true, false) && pPdLeftHeaderFormat && pPdLeftHeaderFormat->GetHeader().GetHeaderFormat() )
+ {
+ MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdLeftHeaderFormat, WW8_HEADER_EVEN );
+ bEvenAndOddHeaders = false;
+ }
if ( !pPd->IsFooterShared() || bLeftRightPgChain )
- MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdLeftFormat, WW8_FOOTER_EVEN );
+ {
+ MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdLeftFooterFormat, WW8_FOOTER_EVEN );
+ }
+ else if ( pPd->IsFooterShared() && pPd->GetStashedFrameFormat(false, true, false) && pPdLeftFooterFormat && pPdLeftFooterFormat->GetFooter().GetFooterFormat() )
+ {
+ MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdLeftFooterFormat, WW8_FOOTER_EVEN );
+ bEvenAndOddFooters = false;
+ }
}
// binary filters only
@@ -1873,7 +1948,7 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
MSWordSections::SetFooterFlag(nHeadFootFlags, *pPdFormat, WW8_FOOTER_ODD);
}
- WriteHeadersFooters( nHeadFootFlags, *pPdFormat, *pPdLeftFormat, *pPdFirstPgFormat, nBreakCode );
+ WriteHeadersFooters( nHeadFootFlags, *pPdFormat, *pPdLeftHeaderFormat, *pPdLeftFooterFormat, *pPdFirstPgFormat, nBreakCode, bEvenAndOddHeaders && bEvenAndOddFooters );
SetHdFtPageRoot( pOldPageRoot );
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index d5835a289492..c18a221fad00 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -784,8 +784,8 @@ public:
/// Output the actual headers and footers.
virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
- const SwFrameFormat& rFormat, const SwFrameFormat& rLeftFormat, const SwFrameFormat& rFirstPageFormat,
- sal_uInt8 nBreakCode) = 0;
+ const SwFrameFormat& rFormat, const SwFrameFormat& rLeftHeaderFormat, const SwFrameFormat& rLeftFooterFormat, const SwFrameFormat& rFirstPageFormat,
+ sal_uInt8 nBreakCode, bool bEvenAndOddHeaders) = 0;
/// Write the field
virtual void OutputField( const SwField* pField, ww::eField eFieldType,
@@ -1187,8 +1187,8 @@ public:
/// Output the actual headers and footers.
virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
- const SwFrameFormat& rFormat, const SwFrameFormat& rLeftFormat, const SwFrameFormat& rFirstPageFormat,
- sal_uInt8 nBreakCode) override;
+ const SwFrameFormat& rFormat, const SwFrameFormat& rLeftHeaderFormat, const SwFrameFormat& rLeftFooterFormat, const SwFrameFormat& rFirstPageFormat,
+ sal_uInt8 nBreakCode, bool bEvenAndOddHeaders) override;
virtual ExportFormat GetExportFormat() const override { return ExportFormat::DOC; }