diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-05-28 11:22:44 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-05-31 13:43:48 +0200 |
commit | ac662268e2a90e73651775090a74370973f3c57f (patch) | |
tree | a4180af66dd6e9aa371305e185d8c6fa70271657 | |
parent | 49d0f4968290cbfc76e0c8bbda648404d0f8f64f (diff) |
tdf#107837 DOCX export: fix balanced multi-col section at doc end
For one, commit f6eb92406bd366c557bc07810649e7ab3d1db614 (fdo#77812
:FILESAVE :DOCX : Extra Section Break gets added in file, 2014-04-29)
made the mistake of always preventing an empty section at the end of the
document, while having that is a feature for the case of balanced Writer
sections with multiple columns. Word can't have balanced columns at the
end of the document otherwise.
For another, commit b6e62dc0dc2b284c825f1182a67bb2f9259a30ce (tdf#106492
DOCX export: fix duplicated section break at doc end, 2017-03-21) made
the same mistake when it wanted to eliminate an unexpected additional
section break.
Fix these by restricting these changes to the case when we don't hit the
"multiple columns + they are balanced" situation.
Change-Id: I742097eb813da6d94a9669328c6a049da7a491ee
Reviewed-on: https://gerrit.libreoffice.org/38104
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
(cherry picked from commit 2d13a00bfa17dd610979b5d89b4f159f2e548d3d)
Reviewed-on: https://gerrit.libreoffice.org/38265
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf107837.odt | bin | 0 -> 9059 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 8 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 18 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.cxx | 5 |
4 files changed, 29 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf107837.odt b/sw/qa/extras/ooxmlexport/data/tdf107837.odt Binary files differnew file mode 100644 index 000000000000..a31a70c523ca --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf107837.odt diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 2aff1fb23ed1..999adbcedf3c 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -498,6 +498,14 @@ DECLARE_OOXMLEXPORT_TEST(testTdf107889, "tdf107889.docx") CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), xDrawPage->getCount()); } +DECLARE_OOXMLEXPORT_TEST(testTdf107837, "tdf107837.odt") +{ + uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTextSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY); + // This was true, a balanced section from ODF turned into a non-balanced one after OOXML roundtrip. + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xTextSections->getByIndex(0), "DontBalanceTextColumns")); +} + 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 f82667c6ed2c..8153ebd2f28b 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -117,6 +117,7 @@ #include <fmtautofmt.hxx> #include <docsh.hxx> #include <docary.hxx> +#include <fmtclbl.hxx> #include <IDocumentSettingAccess.hxx> #include <IDocumentStylePoolAccess.hxx> #include <IDocumentRedlineAccess.hxx> @@ -5495,9 +5496,24 @@ void DocxAttributeOutput::SectionBreak( sal_uInt8 nC, const WW8_SepInfo* pSectio SwNodeIndex aCurrentNode(m_rExport.m_pCurPam->GetNode()); SwNodeIndex aLastNode(m_rExport.m_pDoc->GetNodes().GetEndOfContent(), -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) + { + if (pFormat != reinterpret_cast<SwSectionFormat*>(sal_IntPtr(-1))) + { + nColumns = pFormat->GetCol().GetNumCols(); + const SwFormatNoBalancedColumns& rNoBalanced = pFormat->GetBalancedColumns(); + bBalance = !rNoBalanced.GetValue(); + } + } + // don't add section properties if this will be the first // paragraph in the document - if ( !m_bParagraphOpened && !m_bIsFirstParagraph && aCurrentNode != aLastNode) + if ( !m_bParagraphOpened && !m_bIsFirstParagraph && (aCurrentNode != aLastNode || (nColumns > 1 && bBalance))) { // Create a dummy paragraph if needed m_pSerializer->startElementNS( XML_w, XML_p, FSEND ); diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 0bbc2216f024..e90e31dd2ebb 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -118,6 +118,7 @@ #include "numrule.hxx" #include "fmtclds.hxx" #include "rdfhelper.hxx" +#include "fmtclbl.hxx" using namespace css; using namespace sw::util; @@ -2709,7 +2710,9 @@ void MSWordExportBase::WriteText() const SwFrameFormat* pPgFormat = rSect.GetFormat(); const SwFormatCol& rCol = pPgFormat->GetCol(); sal_uInt16 nColumnCount = rCol.GetNumCols(); - if(nColumnCount > 1) + const SwFormatNoBalancedColumns& rNoBalanced = pPgFormat->GetBalancedColumns(); + // Prevent the additional section break only for non-balanced columns. + if (nColumnCount > 1 && rNoBalanced.GetValue()) { bNeedExportBreakHere = false; } |