include/oox/drawingml/clrscheme.hxx |    3 +++
 include/svx/ColorSets.hxx           |    2 +-
 oox/source/drawingml/clrscheme.cxx  |   27 +++++++++++++++++++++++++++
 oox/source/drawingml/theme.cxx      |   30 ++++++++++++++++++++----------
 4 files changed, 51 insertions(+), 11 deletions(-)

New commits:
commit fa044ee2d251a11e9dda56851d5a06f900db5be7
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Dec 12 21:13:07 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jan 20 07:11:50 2023 +0000

    oox: set svx::Theme directly to a SdrPage when importing
    
    Bypass the need to set the theme data (svx::Theme) throught UNO
    as multiple nested properties. Much more properties will be added
    to the svx::Theme and this will simplify handling a lot.
    
    Change-Id: I0b54628ff22c7c823a999de257fd5bb45e736bdb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143992
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit a6253e13e0f3f866ab47e4271db9a80d8cbce708)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145837
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/oox/drawingml/clrscheme.hxx 
b/include/oox/drawingml/clrscheme.hxx
index a4f0b653441a..fd7662511a88 100644
--- a/include/oox/drawingml/clrscheme.hxx
+++ b/include/oox/drawingml/clrscheme.hxx
@@ -30,6 +30,7 @@
 #include <sal/types.h>
 #include <rtl/ustring.hxx>
 #include <tools/color.hxx>
+#include <svx/ColorSets.hxx>
 
 namespace oox::drawingml {
 
@@ -94,6 +95,8 @@ public:
     const OUString& GetName() const { return maName; }
 
     void ToAny(css::uno::Any& rVal) const;
+    void fill(svx::ColorSet& rColorSet) const;
+
 };
 
 }
diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx
index 71f12c2dbe71..692e683218e8 100644
--- a/include/svx/ColorSets.hxx
+++ b/include/svx/ColorSets.hxx
@@ -50,7 +50,7 @@ constexpr ThemeColorType convertToThemeColorType(sal_Int32 
nIndex)
     return static_cast<ThemeColorType>(nIndex);
 }
 
-class ColorSet
+class SVXCORE_DLLPUBLIC ColorSet
 {
     OUString maColorSetName;
     std::vector<Color> maColors;
diff --git a/oox/source/drawingml/clrscheme.cxx 
b/oox/source/drawingml/clrscheme.cxx
index 19c0afd44900..225faf81eecf 100644
--- a/oox/source/drawingml/clrscheme.cxx
+++ b/oox/source/drawingml/clrscheme.cxx
@@ -120,6 +120,33 @@ void ClrScheme::ToAny(css::uno::Any& rVal) const
     rVal <<= comphelper::containerToSequence(aRet);
 }
 
+void ClrScheme::fill(svx::ColorSet& rColorSet) const
+{
+    for (const auto& [nToken, rColor] : maClrScheme)
+    {
+        switch (nToken)
+        {
+            case XML_tx1:
+            case XML_dk1: rColorSet.add(0, rColor); break;
+            case XML_bg1:
+            case XML_lt1: rColorSet.add(1, rColor); break;
+            case XML_tx2:
+            case XML_dk2: rColorSet.add(2, rColor); break;
+            case XML_bg2:
+            case XML_lt2: rColorSet.add(3, rColor); break;
+            case XML_accent1: rColorSet.add(4, rColor); break;
+            case XML_accent2: rColorSet.add(5, rColor); break;
+            case XML_accent3: rColorSet.add(6, rColor); break;
+            case XML_accent4: rColorSet.add(7, rColor); break;
+            case XML_accent5: rColorSet.add(8, rColor); break;
+            case XML_accent6: rColorSet.add(9, rColor); break;
+            case XML_hlink: rColorSet.add(10, rColor); break;
+            case XML_folHlink: rColorSet.add(11, rColor); break;
+            default: break;
+        }
+    }
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/theme.cxx b/oox/source/drawingml/theme.cxx
index f406f829ea91..885d87b1bb0f 100644
--- a/oox/source/drawingml/theme.cxx
+++ b/oox/source/drawingml/theme.cxx
@@ -24,6 +24,11 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/drawing/XDrawPage.hpp>
 #include <comphelper/propertyvalue.hxx>
+#include <sal/log.hxx>
+#include <svx/unopage.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/ColorSets.hxx>
+#include <svx/unoapi.hxx>
 
 using namespace com::sun::star;
 
@@ -105,16 +110,21 @@ const TextFont* Theme::resolveFont( std::u16string_view 
rName ) const
 
 void Theme::addTheme(const css::uno::Reference<css::drawing::XDrawPage>& 
xDrawPage) const
 {
-    beans::PropertyValue aColorScheme;
-    aColorScheme.Name = "ColorScheme";
-    maClrScheme.ToAny(aColorScheme.Value);
-    beans::PropertyValues aValues = {
-        comphelper::makePropertyValue("Name", maThemeName),
-        comphelper::makePropertyValue("ColorSchemeName", 
maClrScheme.GetName()),
-        aColorScheme,
-    };
-    uno::Reference<beans::XPropertySet> xPropertySet(xDrawPage, 
uno::UNO_QUERY);
-    xPropertySet->setPropertyValue("Theme", uno::Any(aValues));
+    SAL_WARN_IF(!xDrawPage.is(), "oox", "DrawPage is not set");
+
+    SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage);
+
+    SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage");
+
+    if (!pPage)
+        return;
+
+    auto pTheme = std::make_unique<svx::Theme>(maThemeName);
+    auto pColorSet = std::make_unique<svx::ColorSet>(maClrScheme.GetName());
+    maClrScheme.fill(*pColorSet);
+    pTheme->SetColorSet(std::move(pColorSet));
+
+    pPage->getSdrPageProperties().SetTheme(std::move(pTheme));
 }
 
 } // namespace oox::drawingml

Reply via email to