oox/qa/unit/data/chart-theme-override.pptx |binary
 oox/qa/unit/drawingml.cxx                  |   29 +++++++++++++++++++++++++++++
 oox/source/drawingml/shape.cxx             |   22 ++++++++++++++++++----
 3 files changed, 47 insertions(+), 4 deletions(-)

New commits:
commit 7046830506bd51db897289bf59f48342015ad7df
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Nov 15 09:23:20 2021 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Nov 16 10:08:58 2021 +0100

    tdf#127512: PPTX import: fix handling of theme overrides in the chart import
    
    A problem since commit 08818d8a45e034ad825c7fafbb76766f106f1d1d
    (bnc#882383: Do not ignore themeOverride for charts in .pptx,
    2014-07-04), an override for one chart should not affect later drawingML
    objects.
    
    Change-Id: I22b70c8c82e8e8520179c628f566d7f6663c887f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125218
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125223

diff --git a/oox/qa/unit/data/chart-theme-override.pptx 
b/oox/qa/unit/data/chart-theme-override.pptx
new file mode 100644
index 000000000000..85243b678bdf
Binary files /dev/null and b/oox/qa/unit/data/chart-theme-override.pptx differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
index c8dc0d9cc1fb..b909204778b2 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
 #include <com/sun/star/style/ParagraphAdjust.hpp>
 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
 
 #include <unotools/mediadescriptor.hxx>
 #include <unotools/tempfile.hxx>
@@ -345,6 +346,34 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, 
testGroupShapeSmartArt)
     CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), xSmartArt->getCount());
 }
 
+CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testChartThemeOverride)
+{
+    // Given a document with 2 slides, slide1 has a chart with a theme 
override and slide2 has a
+    // shape:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"chart-theme-override.pptx";
+
+    // When loading that document:
+    load(aURL);
+
+    // Then make sure that the slide 2 shape's text color is blue, not red:
+    uno::Reference<drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> 
xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(1),
+                                                 uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xShape(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xPara(xText->createEnumeration()->nextElement(),
+                                                        uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> 
xPortion(xPara->createEnumeration()->nextElement(),
+                                                 uno::UNO_QUERY);
+    sal_Int32 nActual{ 0 };
+    xPortion->getPropertyValue("CharColor") >>= nActual;
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 4485828 (0x4472c4)
+    // - Actual  : 16711680 (0xff0000)
+    // i.e. the text color was red, not blue.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4472C4), nActual);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index d9ee434dcb79..8ec9eb43a691 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -1929,14 +1929,22 @@ void Shape::finalizeXShape( XmlFilterBase& rFilter, 
const Reference< XShapes >&
                 rFilter.importFragment( pChartSpaceFragment );
                 ::oox::ppt::PowerPointImport *pPowerPointImport =
                     dynamic_cast< ::oox::ppt::PowerPointImport* >(&rFilter);
+
+                // The original theme.
+                ThemePtr pTheme;
+
                 if (!aThemeOverrideFragmentPath.isEmpty() && pPowerPointImport)
                 {
+                    // Handle theme override.
                     uno::Reference< xml::sax::XFastSAXSerializable > xDoc(
                             
rFilter.importFragment(aThemeOverrideFragmentPath), uno::UNO_QUERY_THROW);
-                    ThemePtr pTheme = 
pPowerPointImport->getActualSlidePersist()->getTheme();
-                    rFilter.importFragment(new ThemeOverrideFragmentHandler(
-                                rFilter, aThemeOverrideFragmentPath, *pTheme), 
xDoc);
-                    
pPowerPointImport->getActualSlidePersist()->setTheme(pTheme);
+                    pTheme = 
pPowerPointImport->getActualSlidePersist()->getTheme();
+                    auto pThemeOverride = std::make_shared<Theme>(*pTheme);
+                    rFilter.importFragment(
+                        new ThemeOverrideFragmentHandler(rFilter, 
aThemeOverrideFragmentPath,
+                                                         *pThemeOverride),
+                        xDoc);
+                    
pPowerPointImport->getActualSlidePersist()->setTheme(pThemeOverride);
                 }
 
                 // convert imported chart model to chart document
@@ -1960,6 +1968,12 @@ void Shape::finalizeXShape( XmlFilterBase& rFilter, 
const Reference< XShapes >&
                     }
 
                 }
+
+                if (!aThemeOverrideFragmentPath.isEmpty() && pPowerPointImport)
+                {
+                    // Restore the original theme.
+                    
pPowerPointImport->getActualSlidePersist()->setTheme(pTheme);
+                }
             }
             catch( Exception& )
             {

Reply via email to