include/oox/export/drawingml.hxx               |    1 
 oox/qa/unit/data/refer-to-theme-shape-fill.odp |binary
 oox/qa/unit/export.cxx                         |   19 ++++++++++++++++
 oox/source/export/drawingml.cxx                |   28 ++++++++++++++++++++++++-
 4 files changed, 47 insertions(+), 1 deletion(-)

New commits:
commit 37c41f2c445ecf519f4137c23fb36f3942328b6b
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Mar 23 20:06:49 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Mar 24 08:36:25 2022 +0100

    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.
    
    Change-Id: Ia4995be68d5f243875632eec4aaf8afbb8f4d5cc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131984
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index e1aaca0c4386..a128a812483c 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -224,6 +224,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
new file mode 100644
index 000000000000..b12772e111e3
Binary files /dev/null and b/oox/qa/unit/data/refer-to-theme-shape-fill.odp 
differ
diff --git a/oox/qa/unit/export.cxx b/oox/qa/unit/export.cxx
index 8876d507dd9c..56546384820c 100644
--- a/oox/qa/unit/export.cxx
+++ b/oox/qa/unit/export.cxx
@@ -396,6 +396,25 @@ CPPUNIT_TEST_FIXTURE(Test, testReferToTheme)
     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_TEST_FIXTURE(Test, 
testTdf146690_endParagraphRunPropertiesNewLinesTextSize)
 {
     // Given a PPTX file that contains references to a theme:
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 4615bbd39503..85c7a34d5f5f 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -551,7 +551,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() )
     {
@@ -566,6 +569,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));

Reply via email to