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 b95adc80a01b9caf97ade47a4cdb15a210ddd5eb Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Nov 15 09:23:20 2021 +0100 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Nov 16 10:55:04 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. (cherry picked from commit e6968f0485cfb2f6c941d11c438386e14a47095d) Change-Id: I22b70c8c82e8e8520179c628f566d7f6663c887f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125269 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> 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 e1c665e22e86..a72f84d76b32 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 6e8ae072af56..c2e97c5b947b 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -1919,14 +1919,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 @@ -1950,6 +1958,12 @@ void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& } } + + if (!aThemeOverrideFragmentPath.isEmpty() && pPowerPointImport) + { + // Restore the original theme. + pPowerPointImport->getActualSlidePersist()->setTheme(pTheme); + } } catch( Exception& ) {