include/oox/drawingml/clrscheme.hxx      |   10 +++---
 sd/CppunitTest_sd_filter_eppt.mk         |    1 
 sd/qa/filter/eppt/eppt.cxx               |   51 ++++++++++++++++++++++++++++++-
 sd/source/filter/eppt/pptx-epptooxml.cxx |   26 +++++++--------
 4 files changed, 69 insertions(+), 19 deletions(-)

New commits:
commit 3776c15fdf63262721126539bdaa6fd5d4474b1c
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue May 24 20:11:47 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jul 4 08:06:52 2022 +0200

    tdf#149205 sd theme: fix PPTX export loosing dk1 and lt1 colors
    
    Document theme of Impress documents were exported to PPTX only
    partially: dk1 and lt1 was hardcoded to the SYS_COLOR_SCHEMES define,
    while the rest was written from master-slide-specific svx::Theme.
    
    The benefit of this is that our theme is just a set of colors
    (<a:srgbClr> markup in OOXML), while dk1 and lt1 is more dynamic by
    default in PowerPoint (<a:sysClr> in OOXML). The downside is that this
    way a custom dk1 and lt1 color was lost on export.
    
    Fix the problem by switching to <a:srgbClr> markup even for dk1 and lt1:
    not using the <a:sysClr> markup doesn't seem to be a problem in
    practice, or at least much less problematic than rendering with bad
    colors.
    
    If there is a need, dedicated <a:sysClr> markup support can be still
    added later by extending svx::ColorSet::maColors to not only store a
    list of colors, but also some additional properties of those colors.
    
    (cherry picked from commit 4a54a24c207f3040390e2fefec41cbbf0edd5eca)
    
    Change-Id: I26df3fd8c891c217df0d36382f6599805198f4bc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136747
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/oox/drawingml/clrscheme.hxx 
b/include/oox/drawingml/clrscheme.hxx
index 01711fe8bfbd..a4f0b653441a 100644
--- a/include/oox/drawingml/clrscheme.hxx
+++ b/include/oox/drawingml/clrscheme.hxx
@@ -34,9 +34,9 @@
 namespace oox::drawingml {
 
 enum PredefinedClrSchemeId {
-    //dk1,
-    //lt1,
-    dk2 = 0,
+    dk1 = 0,
+    lt1,
+    dk2,
     lt2,
     accent1,
     accent2,
@@ -51,8 +51,8 @@ enum PredefinedClrSchemeId {
 
 static std::map<PredefinedClrSchemeId, OUString> PredefinedClrNames =
 {
-    //{ dk1,  "dk1" },
-    //{ lt1, "lt1" },
+    { dk1,  "dk1" },
+    { lt1, "lt1" },
     { dk2, "dk2" },
     { lt2, "lt2" },
     { accent1, "accent1" },
diff --git a/sd/CppunitTest_sd_filter_eppt.mk b/sd/CppunitTest_sd_filter_eppt.mk
index 1a58e113643e..72b7b4d4dbb7 100644
--- a/sd/CppunitTest_sd_filter_eppt.mk
+++ b/sd/CppunitTest_sd_filter_eppt.mk
@@ -13,6 +13,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sd_filter_eppt))
 
 $(eval $(call gb_CppunitTest_use_externals,sd_filter_eppt,\
        boost_headers \
+       libxml2 \
 ))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sd_filter_eppt, \
diff --git a/sd/qa/filter/eppt/eppt.cxx b/sd/qa/filter/eppt/eppt.cxx
index d27713da20b0..1e8e2c7e1491 100644
--- a/sd/qa/filter/eppt/eppt.cxx
+++ b/sd/qa/filter/eppt/eppt.cxx
@@ -9,20 +9,25 @@
 
 #include <test/bootstrapfixture.hxx>
 #include <unotest/macros_test.hxx>
+#include <test/xmltesttools.hxx>
 
+#include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/drawing/XMasterPageTarget.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/util/Color.hpp>
 
 #include <unotools/mediadescriptor.hxx>
 #include <unotools/tempfile.hxx>
+#include <test/xmldocptr.hxx>
 
 using namespace ::com::sun::star;
 
 namespace
 {
 /// Covers sd/source/filter/eppt/ fixes.
-class Test : public test::BootstrapFixture, public unotest::MacrosTest
+class Test : public test::BootstrapFixture, public unotest::MacrosTest, public 
XmlTestTools
 {
 private:
     uno::Reference<lang::XComponent> mxComponent;
@@ -30,6 +35,7 @@ private:
 public:
     void setUp() override;
     void tearDown() override;
+    void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override;
     uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
 };
 
@@ -48,6 +54,11 @@ void Test::tearDown()
     test::BootstrapFixture::tearDown();
 }
 
+void Test::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
+{
+    XmlTestTools::registerOOXMLNamespaces(pXmlXpathCtx);
+}
+
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sd/qa/filter/eppt/data/";
 
 CPPUNIT_TEST_FIXTURE(Test, testOOXMLCustomShapeBitmapFill)
@@ -76,6 +87,44 @@ CPPUNIT_TEST_FIXTURE(Test, testOOXMLCustomShapeBitmapFill)
     CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GraphicObjectShape"),
                          xShape->getShapeType());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testThemeExport)
+{
+    // Given a document with a master slide and a theme, lt1 is set to 
0x000002:
+    uno::Reference<lang::XComponent> xComponent = 
loadFromDesktop("private:factory/simpress");
+    uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, 
uno::UNO_QUERY);
+    uno::Reference<drawing::XMasterPageTarget> xDrawPage(
+        xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> 
xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY);
+    comphelper::SequenceAsHashMap aMap;
+    aMap["Name"] <<= OUString("mytheme");
+    aMap["ColorSchemeName"] <<= OUString("mycolorscheme");
+    uno::Sequence<util::Color> aColorScheme
+        = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc };
+    aMap["ColorScheme"] <<= aColorScheme;
+    uno::Any aTheme(aMap.getAsConstPropertyValueList());
+    xMasterPage->setPropertyValue("Theme", aTheme);
+
+    // When exporting to PPTX:
+    utl::TempFile aTempFile;
+    uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
+    utl::MediaDescriptor aMediaDescriptor;
+    aMediaDescriptor["FilterName"] <<= OUString("Impress Office Open XML");
+    aTempFile.EnableKillingFile();
+    xStorable->storeToURL(aTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+    validate(aTempFile.GetFileName(), test::OOXML);
+
+    // Then verify that this color is not lost:
+    std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, 
"ppt/theme/theme1.xml");
+    xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
+    assertXPath(pXmlDoc, "//a:clrScheme/a:lt1/a:srgbClr", "val", "000002");
+    // Without the fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // - XPath '//a:clrScheme/a:lt1/a:srgbClr' number of nodes is incorrect
+    // i.e. the RGB color was lost on export.
+    xComponent->dispose();
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx 
b/sd/source/filter/eppt/pptx-epptooxml.cxx
index f6e78d357ead..cabd5c390078 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -2149,7 +2149,8 @@ bool PowerPointExport::WriteColorSets(const FSHelperPtr& 
pFS, svx::Theme* pTheme
 {
     static std::map<PredefinedClrSchemeId, sal_Int32> aPredefinedClrTokens =
     {
-        // dk1 and lt1 is intentionally missing.
+        { dk1, XML_dk1 },
+        { lt1, XML_lt1 },
         { dk2, XML_dk2 },
         { lt2, XML_lt2 },
         { accent1, XML_accent1 },
@@ -2173,14 +2174,11 @@ bool PowerPointExport::WriteColorSets(const 
FSHelperPtr& pFS, svx::Theme* pTheme
         return false;
     }
 
-    for (int nId = PredefinedClrSchemeId::dk2; nId < 
PredefinedClrSchemeId::Count; nId++)
+    for (int nId = PredefinedClrSchemeId::dk1; nId < 
PredefinedClrSchemeId::Count; nId++)
     {
-        // dk1 and lt1 are not written here.
-        int nIndex = nId + 2;
-
         sal_Int32 nToken = 
aPredefinedClrTokens[static_cast<PredefinedClrSchemeId>(nId)];
         pFS->startElementNS(XML_a, nToken);
-        pFS->singleElementNS(XML_a, XML_srgbClr, XML_val, 
I32SHEX(static_cast<sal_Int32>(pColorSet->getColor(nIndex))));
+        pFS->singleElementNS(XML_a, XML_srgbClr, XML_val, 
I32SHEX(static_cast<sal_Int32>(pColorSet->getColor(nId))));
         pFS->endElementNS(XML_a, nToken);
     }
 
@@ -2272,15 +2270,17 @@ void PowerPointExport::WriteTheme(sal_Int32 nThemeNum, 
svx::Theme* pTheme)
     }
     pFS->startElementNS(XML_a, XML_clrScheme, XML_name, aColorSchemeName);
 
-    pFS->write(SYS_COLOR_SCHEMES);
-
-    if (!WriteColorSets(pFS, pTheme) && !WriteColorSchemes(pFS, sThemePath))
+    if (!WriteColorSets(pFS, pTheme))
     {
-        // if style is not defined, try to use first one
-        if (!WriteColorSchemes(pFS, "ppt/theme/theme1.xml"))
+        pFS->write(SYS_COLOR_SCHEMES);
+        if (!WriteColorSchemes(pFS, sThemePath))
         {
-            // color schemes are required - use default values
-            WriteDefaultColorSchemes(pFS);
+            // if style is not defined, try to use first one
+            if (!WriteColorSchemes(pFS, "ppt/theme/theme1.xml"))
+            {
+                // color schemes are required - use default values
+                WriteDefaultColorSchemes(pFS);
+            }
         }
     }
 

Reply via email to