summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-11-15 09:23:20 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-11-15 10:41:16 +0100
commite6968f0485cfb2f6c941d11c438386e14a47095d (patch)
treedbd45c7e4ea1bf08a46e771b12d11a74bad00cbd
parent8c45639a19b277eaaeb1be3798574f91aac5b022 (diff)
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 <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--oox/qa/unit/data/chart-theme-override.pptxbin0 -> 37016 bytes
-rw-r--r--oox/qa/unit/drawingml.cxx29
-rw-r--r--oox/source/drawingml/shape.cxx22
3 files changed, 47 insertions, 4 deletions
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
--- /dev/null
+++ b/oox/qa/unit/data/chart-theme-override.pptx
Binary files differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
index c7ba5ac61730..57e02545eb62 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -27,6 +27,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>
@@ -368,6 +369,34 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf142605_CurveSize)
CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(5699), aBoundRect.Y, 1);
}
+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 bc72e01dead6..69bf775ee5da 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -1921,14 +1921,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
@@ -1952,6 +1960,12 @@ void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >&
}
}
+
+ if (!aThemeOverrideFragmentPath.isEmpty() && pPowerPointImport)
+ {
+ // Restore the original theme.
+ pPowerPointImport->getActualSlidePersist()->setTheme(pTheme);
+ }
}
catch( Exception& )
{