tdf#144362 doc/x export: different columns mean new section
The situation causing this may have become more likely in 7.4.0.
I think that tdf#149313 might have caused a regression in the
unit test that I found that exhibited the problem,
so I am adding another one.
make CppunitTest_sw_ooxmlexport9 CPPUNIT_TEST_NAME=testTdf97648_relativeWidth
make CppunitTest_sw_ooxmlexport9 CPPUNIT_TEST_NAME=testTdf144362
Change-Id: I8e668ac7bfb01a8704634a3e16243be7298bd1ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151731
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf144362.odt b/sw/qa/extras/ooxmlexport/data/tdf144362.odt
new file mode 100644
index 0000000..9c161db
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf144362.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index fc4a1c9..0dbad12 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -529,6 +529,32 @@ DECLARE_OOXMLEXPORT_TEST(testTdf97648_relativeWidth, "tdf97648_relativeWidth.doc
CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::RIGHT, getProperty<sal_Int16>(getShape(3), "HoriOrient"));
CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::LEFT, getProperty<sal_Int16>(getShape(4), "HoriOrient"));
}
uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xSections->getCount());
uno::Reference<beans::XPropertySet> xTextSection(xSections->getByIndex(2), uno::UNO_QUERY);
uno::Reference<text::XTextColumns> xTextColumns
= getProperty<uno::Reference<text::XTextColumns>>(xTextSection, "TextColumns");
CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xTextColumns->getColumnCount());
}
DECLARE_OOXMLEXPORT_TEST(testTdf144362, "tdf144362.odt")
{
uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(),
uno::UNO_QUERY);
// This is difference OK: tdf#107837 extra section added on export to preserve balanced columns.
CPPUNIT_ASSERT_GREATEREQUAL(sal_Int32(2), xSections->getCount());
uno::Reference<beans::XPropertySet> xTextSection(xSections->getByIndex(1), uno::UNO_QUERY);
uno::Reference<text::XTextColumns> xTextColumns
= getProperty<uno::Reference<text::XTextColumns>>(xTextSection, "TextColumns");
CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xTextColumns->getColumnCount());
}
DECLARE_OOXMLEXPORT_TEST(testTdf104061_tableSectionColumns,"tdf104061_tableSectionColumns.docx")
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 8e0bcdd..cf62d9d 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1114,10 +1114,10 @@ sal_uInt16 MSWordSections::CurrentNumberOfColumns( const SwDoc &rDoc ) const
if ( m_aSects.empty() )
return 1;
return NumberOfColumns( rDoc, m_aSects.back() );
return GetFormatCol(rDoc, m_aSects.back()).GetNumCols();
}
sal_uInt16 MSWordSections::NumberOfColumns( const SwDoc &rDoc, const WW8_SepInfo& rInfo )
const SwFormatCol& MSWordSections::GetFormatCol(const SwDoc &rDoc, const WW8_SepInfo& rInfo)
{
const SwPageDesc* pPd = rInfo.pPageDesc;
if ( !pPd )
@@ -1131,9 +1131,7 @@ sal_uInt16 MSWordSections::NumberOfColumns( const SwDoc &rDoc, const WW8_SepInfo
if ( rInfo.pSectionFormat && reinterpret_cast<SwSectionFormat*>(sal_IntPtr(-1)) != rInfo.pSectionFormat )
aSet.Put( rInfo.pSectionFormat->GetFormatAttr( RES_COL ) );
const SwFormatCol& rCol = aSet.Get( RES_COL );
const SwColumns& rColumns = rCol.GetColumns();
return rColumns.size();
return aSet.Get(RES_COL);
}
const WW8_SepInfo* MSWordSections::CurrentSectionInfo()
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 87aa229..7266bb8 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -223,7 +223,7 @@ public:
sal_uInt16 CurrentNumberOfColumns( const SwDoc &rDoc ) const;
/// Number of columns of the provided WW8_SepInfo.
static sal_uInt16 NumberOfColumns( const SwDoc &rDoc, const WW8_SepInfo& rInfo );
static const SwFormatCol& GetFormatCol(const SwDoc &rDoc, const WW8_SepInfo& rInfo);
bool DocumentIsProtected() const { return mbDocumentIsProtected; }
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 4ba85a21..8d7603f 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -602,6 +602,31 @@ void MSWordExportBase::OutputSectionBreaks( const SfxItemSet *pSet, const SwNode
bNewPageDesc |= SetCurrentPageDescFromNode( rNd );
}
}
// If the columns are different in LO's adjacent sections, create a new MS section
if (!bNewPageDesc && pBreak->GetBreak() == SvxBreak::PageBefore
&& Sections().CurrentSectionInfo())
{
const SwSectionFormat* pSectionFormat = MSWordExportBase::GetSectionFormat(rNd);
if (pSectionFormat)
{
const SwFormatCol& rNewSect = pSectionFormat->GetFormatAttr(RES_COL);
const SwFormatCol& rPrevSect
= MSWordSections::GetFormatCol(m_rDoc,
*Sections().CurrentSectionInfo());
if (rNewSect.GetNumCols() != rPrevSect.GetNumCols()
|| !rNewSect.IsOrtho() || !rPrevSect.IsOrtho()
|| rNewSect.GetLineStyle() != rPrevSect.GetLineStyle()
|| rNewSect.GetLineWidth() != rPrevSect.GetLineWidth()
|| rNewSect.GetLineColor() != rPrevSect.GetLineColor()
|| rNewSect.GetLineHeight() != rPrevSect.GetLineHeight()
|| rNewSect.GetLineAdj() != rPrevSect.GetLineAdj())
{
bNewPageDesc = true;
}
}
}
if ( !bNewPageDesc )
AttrOutput().OutputItem( *pBreak );
}