chart2/qa/extras/chart2import2.cxx             |   49 +++++++++++++++++++++++++
 chart2/qa/extras/data/pptx/tdf136754.pptx      |binary
 chart2/qa/extras/data/pptx/tdf60316.pptx       |binary
 oox/source/drawingml/chart/objectformatter.cxx |   18 ++++++---
 oox/source/drawingml/chart/plotareacontext.cxx |    2 -
 oox/source/drawingml/chart/plotareamodel.cxx   |    3 -
 6 files changed, 63 insertions(+), 9 deletions(-)

New commits:
commit 87350de8737ca91ba71b356ca9f33fea99e74591
Author:     Markus Mohrhard <markus.mohrh...@googlemail.com>
AuthorDate: Wed Jul 9 02:53:09 2025 +0200
Commit:     Markus Mohrhard <markus.mohrh...@googlemail.com>
CommitDate: Sun Jul 13 10:09:22 2025 +0200

    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.mohrh...@googlemail.com>

diff --git a/chart2/qa/extras/chart2import2.cxx 
b/chart2/qa/extras/chart2import2.cxx
index c7d349758846..b3260f94f46e 100644
--- a/chart2/qa/extras/chart2import2.cxx
+++ b/chart2/qa/extras/chart2import2.cxx
@@ -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: */
diff --git a/chart2/qa/extras/data/pptx/tdf136754.pptx 
b/chart2/qa/extras/data/pptx/tdf136754.pptx
new file mode 100644
index 000000000000..48927e54eba7
Binary files /dev/null and b/chart2/qa/extras/data/pptx/tdf136754.pptx differ
diff --git a/chart2/qa/extras/data/pptx/tdf60316.pptx 
b/chart2/qa/extras/data/pptx/tdf60316.pptx
index d1da03e5fa46..638d7e371b39 100644
Binary files a/chart2/qa/extras/data/pptx/tdf60316.pptx and 
b/chart2/qa/extras/data/pptx/tdf60316.pptx differ
diff --git a/oox/source/drawingml/chart/objectformatter.cxx 
b/oox/source/drawingml/chart/objectformatter.cxx
index 0d746ab783f8..698da92fe8bf 100644
--- a/oox/source/drawingml/chart/objectformatter.cxx
+++ b/oox/source/drawingml/chart/objectformatter.cxx
@@ -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 )
diff --git a/oox/source/drawingml/chart/plotareacontext.cxx 
b/oox/source/drawingml/chart/plotareacontext.cxx
index 00a6a47bde3b..731c23368933 100644
--- a/oox/source/drawingml/chart/plotareacontext.cxx
+++ b/oox/source/drawingml/chart/plotareacontext.cxx
@@ -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() );
             }
diff --git a/oox/source/drawingml/chart/plotareamodel.cxx 
b/oox/source/drawingml/chart/plotareamodel.cxx
index cb4f6383ddfa..cdc3af7f8fef 100644
--- a/oox/source/drawingml/chart/plotareamodel.cxx
+++ b/oox/source/drawingml/chart/plotareamodel.cxx
@@ -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()

Reply via email to