diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-03-23 20:06:49 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-07-01 08:46:48 +0200 |
commit | 54272b950525fd6462006cb3624635e17b6008ae (patch) | |
tree | 4823efb2c0abefe83a43a23c38ef94353fec0e9d | |
parent | 1e93905e5136149d09b5c591e0fe2366d759f429 (diff) |
sd theme: add PPTX export for shape fill color
Do this only in case there are no effects on the color, as that is not
yet handled.
Note that the theme color was already stored in the grab-bag, so this is
primarily interesting in case the theme color was changed or the source
format was ODP.
(cherry picked from commit 37c41f2c445ecf519f4137c23fb36f3942328b6b)
Conflicts:
oox/qa/unit/export.cxx
Change-Id: Ia4995be68d5f243875632eec4aaf8afbb8f4d5cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136677
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | include/oox/export/drawingml.hxx | 1 | ||||
-rw-r--r-- | oox/qa/unit/data/refer-to-theme-shape-fill.odp | bin | 0 -> 15506 bytes | |||
-rw-r--r-- | oox/qa/unit/export.cxx | 19 | ||||
-rw-r--r-- | oox/source/export/drawingml.cxx | 28 |
4 files changed, 47 insertions, 1 deletions
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx index b15bf9d81aba..f2ef8c910da0 100644 --- a/include/oox/export/drawingml.hxx +++ b/include/oox/export/drawingml.hxx @@ -230,6 +230,7 @@ public: void WriteConnectorConnections( EscherConnectorListEntry& rConnectorEntry, sal_Int32 nStartID, sal_Int32 nEndID ); bool WriteCharColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet); + bool WriteFillColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet); void WriteSolidFill( ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT ); void WriteSolidFill( const OUString& sSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT ); diff --git a/oox/qa/unit/data/refer-to-theme-shape-fill.odp b/oox/qa/unit/data/refer-to-theme-shape-fill.odp Binary files differnew file mode 100644 index 000000000000..b12772e111e3 --- /dev/null +++ b/oox/qa/unit/data/refer-to-theme-shape-fill.odp diff --git a/oox/qa/unit/export.cxx b/oox/qa/unit/export.cxx index 960df6dd43e7..009e63d23e85 100644 --- a/oox/qa/unit/export.cxx +++ b/oox/qa/unit/export.cxx @@ -612,6 +612,25 @@ CPPUNIT_TEST_FIXTURE(Test, testReferToTheme) "75000"); assertXPath(pXmlDoc, "//p:sp[3]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr/a:lumOff", 0); } + +CPPUNIT_TEST_FIXTURE(Test, testReferToThemeShapeFill) +{ + // Given an ODP file that contains references to a theme for shape fill: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "refer-to-theme-shape-fill.odp"; + + // When saving that document: + loadAndSave(aURL, "Impress Office Open XML"); + + // Then make sure the shape fill color is a scheme color: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. the <a:schemeClr> element was not written. Note that this was already working from PPTX + // files via grab-bags, so this test intentionally uses an ODP file as input. + std::unique_ptr<SvStream> pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr", "val", "accent1"); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 46098e9d04a3..23d67eb1c713 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -555,7 +555,10 @@ void DrawingML::WriteSolidFill( const Reference< XPropertySet >& rXPropSet ) else if ( nFillColor != nOriginalColor ) { // the user has set a different color for the shape - WriteSolidFill( ::Color(ColorTransparency, nFillColor & 0xffffff), nAlpha ); + if (aTransformations.hasElements() || !WriteFillColor(rXPropSet)) + { + WriteSolidFill(::Color(ColorTransparency, nFillColor & 0xffffff), nAlpha); + } } else if ( !sColorFillScheme.isEmpty() ) { @@ -570,6 +573,29 @@ void DrawingML::WriteSolidFill( const Reference< XPropertySet >& rXPropSet ) } } +bool DrawingML::WriteFillColor(const uno::Reference<beans::XPropertySet>& xPropertySet) +{ + if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("FillColorTheme")) + { + return false; + } + + sal_Int32 nFillColorTheme = -1; + xPropertySet->getPropertyValue("FillColorTheme") >>= nFillColorTheme; + if (nFillColorTheme < 0 || nFillColorTheme > 11) + { + return false; + } + + const char* pColorName = g_aPredefinedClrNames[nFillColorTheme]; + + mpFS->startElementNS(XML_a, XML_solidFill); + mpFS->singleElementNS(XML_a, XML_schemeClr, XML_val, pColorName); + mpFS->endElementNS(XML_a, XML_solidFill); + + return true; +} + void DrawingML::WriteGradientStop(sal_uInt16 nStop, ::Color nColor, sal_Int32 nAlpha) { mpFS->startElementNS(XML_a, XML_gs, XML_pos, OString::number(nStop * 1000)); |