cool#16218 writerfilter: apply the table alignment a table style sets

A table that took its alignment only from the w:jc of its table style
imported left aligned.

TablePropertiesHandler keeps the alignment in TablePropertyMap's
setValue() channel, which only another TablePropertyMap copies. The
style path hands the properties to the plain PropertyMap of the style
entry, so the value was dropped there, and endTableGetTableStyle() then
wrote the left default over the style.

Store the alignment as a plain property as well, for the whole table
part of a style only, and start from it in endTableGetTableStyle() so
direct formatting and the floating table frame properties still win.

Signed-off-by: Gülşah Köse <gulsah.kose@collabora.com>
Change-Id: I31ca48f77ba3388e950ff8edcd0d61a71055c853
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/12632
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit b04ae23b97badfc8b617a9c2b8a492cfab754657)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211103
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Gülşah Köse
2026-09-18 13:56:19 +02:00
committed by Xisco Fauli
parent e80f162935
commit 388360bb07
4 changed files with 52 additions and 1 deletions
Binary file not shown.
@@ -13,9 +13,11 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/text/HoriOrientation.hpp>
#include <com/sun/star/text/XTextContent.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/XTextFieldsSupplier.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
#include <pam.hxx>
@@ -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<text::XTextTablesSupplier> xSupplier(mxComponent, uno::UNO_QUERY_THROW);
uno::Reference<container::XNameAccess> 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<sal_Int16>(xTables->getByName(u"Table1"_ustr), u"HoriOrient"_ustr));
CPPUNIT_ASSERT_EQUAL(
text::HoriOrientation::LEFT_AND_WIDTH,
getProperty<sal_Int16>(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();
@@ -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<PropertyMap::Property> 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) ) );
@@ -22,6 +22,7 @@
#include "CellMarginHandler.hxx"
#include "PropertyMap.hxx"
#include "MeasureHandler.hxx"
#include "ConversionHelper.hxx"
#include <ooxml/resourceids.hxx>
#include <comphelper/sequence.hxx>
@@ -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)));