diff --git a/sw/qa/extras/ooxmlexport/data/table-style-jc.docx b/sw/qa/extras/ooxmlexport/data/table-style-jc.docx new file mode 100644 index 000000000000..22ddb3d93c07 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/table-style-jc.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport27.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport27.cxx index 0f95241d4078..0f659a284115 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport27.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport27.cxx @@ -13,9 +13,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -257,6 +259,32 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf146973_rtlDateLocale) assertXPathNoAttribute(pXmlDoc, "(//w:r[w:instrText])[1]/w:rPr/w:lang", "val"); } +CPPUNIT_TEST_FIXTURE(Test, testTableAlignmentFromTableStyle) +{ + // The first table takes its alignment from the w:jc of its table style, the second one + // overrides the w:jc of its style with a direct one. + auto verify = [this]() { + uno::Reference xSupplier(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xTables = xSupplier->getTextTables(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : 7 + // i.e. the table was left aligned, the w:jc of the table style having been dropped. + CPPUNIT_ASSERT_EQUAL( + text::HoriOrientation::CENTER, + getProperty(xTables->getByName(u"Table1"_ustr), u"HoriOrient"_ustr)); + CPPUNIT_ASSERT_EQUAL( + text::HoriOrientation::LEFT_AND_WIDTH, + getProperty(xTables->getByName(u"Table2"_ustr), u"HoriOrient"_ustr)); + }; + + createSwDoc("table-style-jc.docx"); + verify(); + saveAndReload(TestFilter::DOCX); + verify(); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx index 7b21d26c650c..49aff0f5c16e 100644 --- a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx @@ -676,7 +676,15 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo } sal_Int32 nHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH; - // Fetch Horizontal Orientation in rFrameProperties if not set in m_aTableProperties + // The table style carries the alignment as a plain property. + if (const std::optional oStyleHoriOrient + = m_aTableProperties->getProperty(PROP_HORI_ORIENT)) + { + sal_Int16 nStyleHoriOrient{}; + if (oStyleHoriOrient->second >>= nStyleHoriOrient) + nHoriOrient = nStyleHoriOrient; + } + // Direct formatting wins over it, then Horizontal Orientation in rFrameProperties. if ( !m_aTableProperties->getValue( TablePropertyMap::HORI_ORIENT, nHoriOrient ) ) lcl_extractHoriOrient( rFrameProperties, nHoriOrient ); m_aTableProperties->Insert( PROP_HORI_ORIENT, uno::Any( sal_Int16(nHoriOrient) ) ); diff --git a/sw/source/writerfilter/dmapper/TblStylePrHandler.cxx b/sw/source/writerfilter/dmapper/TblStylePrHandler.cxx index 3ad0375381af..1b6ec15cde1b 100644 --- a/sw/source/writerfilter/dmapper/TblStylePrHandler.cxx +++ b/sw/source/writerfilter/dmapper/TblStylePrHandler.cxx @@ -22,6 +22,7 @@ #include "CellMarginHandler.hxx" #include "PropertyMap.hxx" #include "MeasureHandler.hxx" +#include "ConversionHelper.hxx" #include #include @@ -161,6 +162,20 @@ void TblStylePrHandler::lcl_sprm(Sprm & rSprm) } } break; + case NS_ooxml::LN_CT_TrPrBase_jc: + case NS_ooxml::LN_CT_TblPrBase_jc: + { + // Table alignment: keep it as a property, the TablePropertyMap value that + // TablePropertiesHandler sets does not survive the copy into a style entry. + // Whole table only, the conditional formats (w:tblStylePr) feed cells. + if ( m_nType == TblStyleType::Unknown || m_nType == TblStyleType::WholeTable ) + { + const Value* pValue = rSprm.getValue(); + m_pProperties->Insert( PROP_HORI_ORIENT, uno::Any( + ConversionHelper::convertTableJustification( pValue ? pValue->getInt() : 0 ) ) ); + } + } + break; case NS_ooxml::LN_CT_TrPrBase_tblHeader: { m_pProperties->Insert( PROP_HEADER_ROW_COUNT, uno::Any(sal_Int32(1)));