schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng |    8 +
 sw/source/filter/xml/xmlexp.hxx                             |    3 
 sw/source/filter/xml/xmlfmte.cxx                            |   77 ++++++++++++
 3 files changed, 88 insertions(+)

New commits:
commit 32a8095eb2c22f7de4bce14f1b5c08dc701deaea
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Thu Jan 26 18:09:06 2023 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Mon Jan 30 05:54:13 2023 +0000

    xmloff: export Theme for ODT (Writer) documents
    
    Exports the Theme set on the one and only SdrPage for ODT (Writer)
    documents. The theme is exported as a sub-element of "style".
    This differs to ODP (Impress) documents, which export the Theme
    as part of the master-page element.
    
    Currently the code is duplicated, because the theme can't yet be
    accessed inside xmloff in a non-conflicting way (creating conflicts
    between modules), which will be fixed in the future.
    
    Change-Id: I0e440d14724b49e7d86e9deabc6615a91e8cd31a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146172
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    (cherry picked from commit 6d1413da02602992b42b62bda9a26ffeb774b603)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146227
    Tested-by: Tomaž Vajngerl <[email protected]>

diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng 
b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index 0a8aadad1ba3..384b3cde05f3 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -3223,6 +3223,14 @@ 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
       </rng:optional>
     </rng:element>
   </rng:define>
+
+  <!-- TODO no proposal -->
+  <rng:define name="style-style" combine="interleave">
+      <rng:optional>
+        <rng:ref name="loext-theme"/>
+      </rng:optional>
+  </rng:define>
+
   <rng:define name="style-master-page" combine="choice">
     <rng:element name="style:master-page">
       <rng:ref name="style-master-page-attlist"/>
diff --git a/sw/source/filter/xml/xmlexp.hxx b/sw/source/filter/xml/xmlexp.hxx
index 86b919ac95a7..3ba34a5cced4 100644
--- a/sw/source/filter/xml/xmlexp.hxx
+++ b/sw/source/filter/xml/xmlexp.hxx
@@ -90,6 +90,9 @@ class SwXMLExport : public SvXMLExport
                            SwXMLTableInfo_Impl& rTableInfo,
                            sal_uInt32 nHeaderRows = 0 );
 
+    void ExportThemeElement(const 
css::uno::Reference<css::drawing::XDrawPage>& xDrawPage);
+
+
     virtual void ExportMeta_() override;
     virtual void ExportFontDecls_() override;
     virtual void ExportStyles_( bool bUsed ) override;
diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx
index f98e4ae3fb28..08cc588b2e75 100644
--- a/sw/source/filter/xml/xmlfmte.cxx
+++ b/sw/source/filter/xml/xmlfmte.cxx
@@ -35,9 +35,20 @@
 #include <pagedesc.hxx>
 #include <cellatr.hxx>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/util/Color.hpp>
 #include "xmlexp.hxx"
 #include <SwStyleNameMapper.hxx>
 #include <osl/diagnose.h>
+#include <comphelper/sequenceashashmap.hxx>
+#include <sax/tools/converter.hxx>
+
+#include <o3tl/enumrange.hxx>
+#include <svx/ColorSets.hxx>
+#include <svx/unoapi.hxx>
+#include <svx/svdpage.hxx>
+#include <docmodel/theme/ThemeColor.hxx>
+
 
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::uno;
@@ -170,6 +181,72 @@ void SwXMLExport::ExportStyles_( bool bUsed )
     GetShapeExport()->GetShapeTableExport()->exportTableStyles();
     //page defaults
     GetPageExport()->exportDefaultStyle();
+
+    // Theme
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(GetModel(), 
UNO_QUERY);
+    if (xDrawPageSupplier.is())
+    {
+        uno::Reference<drawing::XDrawPage> xPage = 
xDrawPageSupplier->getDrawPage();
+        if (xPage.is())
+            ExportThemeElement(xPage);
+    }
+}
+
+void SwXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& 
xDrawPage)
+{
+    if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
+    {
+        // Do not export in standard ODF 1.3 or older.
+        return;
+    }
+
+    SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage);
+    SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage");
+
+    if (!pPage)
+        return;
+
+    auto* pTheme = pPage->getSdrPageProperties().GetTheme();
+    if (!pTheme)
+        return;
+
+    if (!pTheme->GetName().isEmpty())
+        AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pTheme->GetName());
+    SvXMLElementExport aTheme(*this, XML_NAMESPACE_LO_EXT, XML_THEME, true, 
true);
+
+    auto* pColorSet = pTheme->GetColorSet();
+    if (!pColorSet->getName().isEmpty())
+        AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pColorSet->getName());
+    SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, 
XML_COLOR_TABLE, true, true);
+
+    static const XMLTokenEnum aColorTokens[] =
+    {
+        XML_DK1, // Text 1
+        XML_LT1, // Background 1
+        XML_DK2, // Text 2
+        XML_LT2, // Background 2
+        XML_ACCENT1,
+        XML_ACCENT2,
+        XML_ACCENT3,
+        XML_ACCENT4,
+        XML_ACCENT5,
+        XML_ACCENT6,
+        XML_HLINK, // Hyperlink
+        XML_FOLHLINK, // Followed hyperlink
+    };
+
+    for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>())
+    {
+        if (eThemeColorType == model::ThemeColorType::Unknown)
+            continue;
+
+        auto nColor = size_t(eThemeColorType);
+        AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, 
GetXMLToken(aColorTokens[nColor]));
+        OUStringBuffer sValue;
+        sax::Converter::convertColor(sValue, 
pColorSet->getColor(eThemeColorType));
+        AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR, 
sValue.makeStringAndClear());
+        SvXMLElementExport aColor(*this, XML_NAMESPACE_LO_EXT, XML_COLOR, 
true, true);
+    }
 }
 
 void SwXMLExport::collectAutoStyles()

Reply via email to