tdf#136754: handle pptx chart backgrounds provided by the themes correctly

It seems that there is a small undocumented quirk in the OOXML spec
regarding pptx files. The first 32 themes are handled as if they would
be specifying a transparent background whereas the spec seems to agree
with the xlsx/docx handling of using a solid background based on the
theme colors.

This corresponds to table 3 in 21.2.3.46 ST_Style of the OOXML spec.

This commit also reverts the fix for tdf#60316.

Change-Id: I4187b5740898435941647056a5820fa47a2b3dba
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187759
Tested-by: Jenkins
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
This commit is contained in:
Markus Mohrhard
2025-07-09 02:53:09 +02:00
parent 88e20bce59
commit 87350de873
6 changed files with 63 additions and 9 deletions

View File

@ -18,6 +18,7 @@
#include <com/sun/star/chart/XAxisXSupplier.hpp>
#include <com/sun/star/chart/DataLabelPlacement.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
class Chart2ImportTest2 : public ChartTest
{
@ -958,6 +959,54 @@ CPPUNIT_TEST_FIXTURE(Chart2ImportTest2, testTdf166428)
CPPUNIT_ASSERT(xDataSeq.is());
}
CPPUNIT_TEST_FIXTURE(Chart2ImportTest2, testTdf60316)
{
loadFromFile(u"pptx/tdf60316.pptx");
// 1st chart
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<beans::XPropertySet> xPropSet = xChartDoc->getPageBackground();
CPPUNIT_ASSERT(xPropSet.is());
drawing::FillStyle eStyle
= xPropSet->getPropertyValue(u"FillStyle"_ustr).get<drawing::FillStyle>();
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"'Automatic' chart background fill in pptx should be loaded as no fill (transparent).",
drawing::FillStyle_NONE, eStyle);
Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram();
Reference<beans::XPropertySet> xWallPropSet = xDiagram->getWall();
eStyle = xWallPropSet->getPropertyValue(u"FillStyle"_ustr).get<drawing::FillStyle>();
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Wall background for styles below 32 shoujld be transparent in pptx",
drawing::FillStyle_NONE, eStyle);
}
CPPUNIT_TEST_FIXTURE(Chart2ImportTest2, testTdf136754)
{
loadFromFile(u"pptx/tdf136754.pptx");
// 1st chart
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<beans::XPropertySet> xPropSet = xChartDoc->getPageBackground();
CPPUNIT_ASSERT(xPropSet.is());
drawing::FillStyle eStyle
= xPropSet->getPropertyValue(u"FillStyle"_ustr).get<drawing::FillStyle>();
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"'Automatic' chart background fill in pptx should be loaded as no fill (transparent).",
drawing::FillStyle_NONE, eStyle);
Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram();
Reference<beans::XPropertySet> xWallPropSet = xDiagram->getWall();
eStyle = xWallPropSet->getPropertyValue(u"FillStyle"_ustr).get<drawing::FillStyle>();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wall background for styles above 32 should be solid in pptx",
drawing::FillStyle_SOLID, eStyle);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Binary file not shown.

View File

@ -636,6 +636,8 @@ public:
const PictureOptionsModel* pPicOptions,
sal_Int32 nSeriesIdx );
void setAutoFill(sal_Int32 nAutoFill);
private:
FillPropertiesPtr mxAutoFill; /// Automatic fill properties.
};
@ -871,11 +873,6 @@ FillFormatter::FillFormatter( ObjectFormatterData& rData, const AutoFormatEntry*
if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
if( const FillProperties* pFillProps = pTheme->getFillStyle( pAutoFormatEntry->mnThemedIdx ) )
*mxAutoFill = *pFillProps;
if (eObjType == OBJECTTYPE_CHARTSPACE)
{
mxAutoFill->moFillType = rData.mrFilter.getGraphicHelper().getDefaultChartAreaFillStyle();
}
}
void FillFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx )
@ -890,6 +887,11 @@ void FillFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRe
aFillProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), 0, getPhColor( nSeriesIdx ) );
}
void FillFormatter::setAutoFill(sal_Int32 nFillStyle)
{
mxAutoFill->moFillType = nFillStyle;
}
namespace {
const TextCharacterProperties* lclGetTextProperties( const ModelRef< TextBody >& rxTextProp )
@ -948,6 +950,12 @@ ObjectTypeFormatter::ObjectTypeFormatter( ObjectFormatterData& rData, const Obje
mrModelObjHelper( rData.maModelObjHelper ),
mrEntry( rEntry )
{
// this seems to be an undocumented quirk in the OOXML spec. Only for pptx files the first 32 theme entries
// force a transparent background
if (rChartSpace.mnStyle <= 32 && (eObjType == OBJECTTYPE_CHARTSPACE || eObjType == OBJECTTYPE_PLOTAREA2D))
{
maFillFormatter.setAutoFill(rData.mrFilter.getGraphicHelper().getDefaultChartAreaFillStyle());
}
}
void ObjectTypeFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx )

View File

@ -162,7 +162,7 @@ ContextHandlerRef PlotAreaContext::onCreateContext( sal_Int32 nElement, [[maybe_
case C_TOKEN( layout ):
return new LayoutContext( *this, mrModel.mxLayout.create() );
case C_TOKEN( spPr ):
return new ShapePropertiesContext( *this, mrModel.mxShapeProp.getOrCreate() );
return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
case C_TOKEN(dTable):
return new DataTableContext( *this, mrModel.mxDataTable.create() );
}

View File

@ -18,8 +18,6 @@
*/
#include <drawingml/chart/plotareamodel.hxx>
#include <drawingml/fillproperties.hxx>
#include <oox/token/tokens.hxx>
namespace oox::drawingml::chart {
@ -40,7 +38,6 @@ WallFloorModel::~WallFloorModel()
PlotAreaModel::PlotAreaModel()
{
mxShapeProp.create().getFillProperties().moFillType = XML_noFill;
}
PlotAreaModel::~PlotAreaModel()