summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-02-07 16:06:19 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-02-10 11:51:10 +0100
commit42ba6d0ebab69c5e307e8c2390f005eca8aaca1d (patch)
tree3b064e23d34844aa48db8ab7c263a7302d596a36 /sw
parent00e1597c9a8a3451ae4d67ac0d1257c5ccac6a16 (diff)
DOCX export: fix handling of section starts that originally had page margins
This is similar to commit 26f2a9e1a10a22e864e71ee7c94934821703e021 (DOCX export: fix handling of section starts that originally had headers, 2020-02-06), except here the top margin has to taken from that follow page style, not the header. Without this, it can happen that the page number in the original Writer doc model and the exported Word result do not match. This required reworking WriteNextStyleHeaderFooter(), which assumed that the header/footer status is already calculated by the time its called. But the page margin code runs earlier, so we need to make that decision earlier, even when the header/footer status is not yet calculated. (cherry picked from commit f0decd9c932b50eddeecd49a6ee44182e78be938) Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport14.cxx Change-Id: Ife7396603702d2048d544aa46f96acfa337a041a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88359 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport13.cxx12
-rw-r--r--sw/source/filter/ww8/wrtw8sty.cxx28
2 files changed, 28 insertions, 12 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 769815485b48..06dc369d14bb 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -396,6 +396,18 @@ DECLARE_OOXMLEXPORT_TEST(testContSectBreakHeaderFooter, "cont-sect-break-header-
// - Expected: Header, section 2
// - Actual : First page header, section 2
// i.e. both the header and the footer on page 3 was wrong.
+
+ // Additional problem: top margin on page 3 was wrong.
+ if (mbExported)
+ {
+ xmlDocPtr pXml = parseExport("word/document.xml");
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 2200
+ // - Actual : 2574
+ // i.e. the top margin on page 3 was too large and now matches the value from the input
+ // document.
+ assertXPath(pXml, "/w:document/w:body/w:sectPr/w:pgMar", "top", "2200");
+ }
}
CPPUNIT_TEST_FIXTURE(SwModelTestBase, testZeroLineSpacing)
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 4c2901c0c0c0..2768429ea5a5 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1510,11 +1510,11 @@ void WW8Export::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
namespace
{
/**
- * Find a node near the section start that has a page break, it may have a follow header/footer for
- * us.
+ * Determines if the continuous section break we start should use page style properties (header,
+ * footer, margins) from the next page style of the previous section.
*/
-bool WriteNextStyleHeaderFooter(sal_uInt8 nBreakCode, sal_uInt8 nHeadFootFlags,
- const SwPageDesc* pPd, const WW8_SepInfo& rSepInfo)
+bool UsePrevSectionNextStyle(sal_uInt8 nBreakCode, const SwPageDesc* pPd,
+ const WW8_SepInfo& rSepInfo)
{
if (nBreakCode != 0)
{
@@ -1522,12 +1522,6 @@ bool WriteNextStyleHeaderFooter(sal_uInt8 nBreakCode, sal_uInt8 nHeadFootFlags,
return false;
}
- if (nHeadFootFlags != 0)
- {
- // Would write some header/footer anyway.
- return false;
- }
-
if (!pPd->GetFollow())
{
// Page style has no follow style.
@@ -1611,6 +1605,7 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
bool bOutPgDscSet = true, bLeftRightPgChain = false, bOutputStyleItemSet = false;
bool bEnsureHeaderFooterWritten = rSepInfo.pSectionFormat && rSepInfo.bIsFirstParagraph;
const SwFrameFormat* pPdFormat = &pPd->GetMaster();
+ bool bUsePrevSectionNextStyle = false;
if ( rSepInfo.pSectionFormat )
{
// if pSectionFormat is set, then there is a SectionNode
@@ -1636,6 +1631,15 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
// produce Itemset, which inherits PgDesk-Attr-Set:
// as child also the parent is searched if 'deep'-OutputItemSet
const SfxItemSet* pPdSet = &pPdFormat->GetAttrSet();
+
+ bUsePrevSectionNextStyle = GetExportFormat() == ExportFormat::DOCX
+ && UsePrevSectionNextStyle(nBreakCode, pPd, rSepInfo);
+ if (bUsePrevSectionNextStyle)
+ {
+ // Take page margins from the previous section's next style.
+ pPdSet = &pPd->GetFollow()->GetMaster().GetAttrSet();
+ }
+
SfxItemSet aSet( *pPdSet->GetPool(), pPdSet->GetRanges() );
aSet.SetParent( pPdSet );
@@ -1828,9 +1832,9 @@ 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))
+ if (bUsePrevSectionNextStyle && nHeadFootFlags == 0)
{
+ // Take headers/footers from the previous section's next style.
pPdFormat = &pPd->GetFollow()->GetMaster();
MSWordSections::SetHeaderFlag(nHeadFootFlags, *pPdFormat, WW8_HEADER_ODD);
MSWordSections::SetFooterFlag(nHeadFootFlags, *pPdFormat, WW8_FOOTER_ODD);