summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-02-06 14:47:08 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-02-06 18:59:25 +0100
commit26f2a9e1a10a22e864e71ee7c94934821703e021 (patch)
treedc3d5da741c3398d58e9dacc1d90b4af2a9f0244 /sw
parent11fba17eed630973cb5a9df6a8bde7488320cb30 (diff)
DOCX export: fix handling of section starts that originally had headers
Both the DOC import (in wwSectionManager::InsertSegments()) and DOCX import (in SectionPropertyMap::CloseSectionGroup()) have a mechanism to try to attach changed headers/footers from a continuous section break somewhere, so they are not lost. This means that even if the rendering of such documents is OK, explicit code is needed to undo the effect of the importer at export time, or those headers will be lost. Start doing this for the DOCX export case when the headers/footers are placed at the "previous-in-practice" paragraph, more cases (handled at the import side) can be added later. Change-Id: Ic2304a74919d18da3ba9cb4afe301e0247a50dc2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88103 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport14.cxx7
-rw-r--r--sw/source/filter/ww8/wrtw8sty.cxx80
2 files changed, 86 insertions, 1 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index d9d952bf5b4d..9fe75ca0f2e8 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -446,7 +446,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf128290, "tdf128290.odt")
assertXPath(pXml, "/w:document/w:body/w:tbl/w:tblPr/w:tblLayout", "type", "fixed");
}
-DECLARE_OOXMLIMPORT_TEST(testContSectBreakHeaderFooter, "cont-sect-break-header-footer.docx")
+DECLARE_OOXMLEXPORT_TEST(testContSectBreakHeaderFooter, "cont-sect-break-header-footer.docx")
{
// Load a document with a continuous section break on page 2.
CPPUNIT_ASSERT_EQUAL(OUString("First page header, section 1"),
@@ -470,6 +470,11 @@ DECLARE_OOXMLIMPORT_TEST(testContSectBreakHeaderFooter, "cont-sect-break-header-
// the own footer text.
CPPUNIT_ASSERT_EQUAL(OUString("Footer, section 3"),
parseDump("/root/page[3]/footer/txt/text()"));
+
+ // Without the export fix in place, the import-export-import test would have failed with:
+ // - Expected: Header, section 2
+ // - Actual : First page header, section 2
+ // i.e. both the header and the footer on page 3 was wrong.
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 5b580122e3d9..d13e9b384a1b 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -29,6 +29,7 @@
#include <svx/svdotext.hxx>
#include <svx/svdouno.hxx>
#include <editeng/lrspitem.hxx>
+#include <editeng/fhgtitem.hxx>
#include <doc.hxx>
#include "wrtww8.hxx"
#include <docary.hxx>
@@ -55,6 +56,7 @@
#include <redline.hxx>
#include <msfilter.hxx>
#include <swmodule.hxx>
+#include <charatr.hxx>
#include "sprmids.hxx"
@@ -1517,6 +1519,76 @@ void WW8Export::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
pSepx->OutHeaderFooter( *this, false, rFirstPageFormat, nCpPos, nHeadFootFlags, WW8_FOOTER_FIRST, nBreakCode );
}
+namespace
+{
+/**
+ * Find a node near the section start that has a page break, it may have a follow header/footer for
+ * us.
+ */
+bool WriteNextStyleHeaderFooter(sal_uInt8 nBreakCode, sal_uInt8 nHeadFootFlags,
+ const SwPageDesc* pPd, const WW8_SepInfo& rSepInfo)
+{
+ if (nBreakCode != 0)
+ {
+ // Not a continuous section break.
+ return false;
+ }
+
+ if (nHeadFootFlags != 0)
+ {
+ // Would write some header/footer anyway.
+ return false;
+ }
+
+ if (!pPd->GetFollow())
+ {
+ // Page style has no follow style.
+ return false;
+ }
+
+ // We start a continuous section break without headers/footers. Possibly the importer had
+ // headers/footers for this section break and put them to the closest page break's page style's
+ // next page style. See "find a node in the section that has a page break" in writerfilter/.
+ // Try the last-in-practice paragraph of the previous section.
+ const SwSectionFormat* pSection = rSepInfo.pSectionFormat;
+ if (pSection == reinterpret_cast<SwSectionFormat*>(sal_IntPtr(-1)))
+ {
+ return false;
+ }
+
+ const SwNodeIndex* pSectionStart = pSection->GetContent().GetContentIdx();
+ if (!pSectionStart)
+ {
+ return false;
+ }
+
+ SwPaM aPaM(*pSectionStart);
+ aPaM.Move(fnMoveBackward);
+ if (!aPaM.GetNode().IsTextNode())
+ {
+ return false;
+ }
+
+ SwTextNode* pTextNode = aPaM.GetNode().GetTextNode();
+ const SwAttrSet* pParaProps = &pTextNode->GetSwAttrSet();
+ sal_uInt32 nCharHeight = pParaProps->GetSize().GetHeight();
+ if (nCharHeight > 20)
+ {
+ return false;
+ }
+
+ aPaM.Move(fnMoveBackward);
+ if (!aPaM.GetNode().IsTextNode())
+ {
+ return false;
+ }
+
+ pTextNode = aPaM.GetNode().GetTextNode();
+ pParaProps = &pTextNode->GetSwAttrSet();
+ return pParaProps->HasItem(RES_PAGEDESC);
+}
+}
+
void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAttrDesc* pA )
{
const SwPageDesc* pPd = rSepInfo.pPageDesc;
@@ -1768,6 +1840,14 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
const SwTextNode *pOldPageRoot = GetHdFtPageRoot();
SetHdFtPageRoot( rSepInfo.pPDNd ? rSepInfo.pPDNd->GetTextNode() : nullptr );
+ if (GetExportFormat() == ExportFormat::DOCX
+ && WriteNextStyleHeaderFooter(nBreakCode, nHeadFootFlags, pPd, rSepInfo))
+ {
+ pPdFormat = &pPd->GetFollow()->GetMaster();
+ MSWordSections::SetHeaderFlag(nHeadFootFlags, *pPdFormat, WW8_HEADER_ODD);
+ MSWordSections::SetFooterFlag(nHeadFootFlags, *pPdFormat, WW8_FOOTER_ODD);
+ }
+
WriteHeadersFooters( nHeadFootFlags, *pPdFormat, *pPdLeftFormat, *pPdFirstPgFormat, nBreakCode );
SetHdFtPageRoot( pOldPageRoot );