sc/CppunitTest_sc_theme_import_export_test.mk |   67 ++++++++++++++++++++++++
 sc/Module_sc.mk                               |    1 
 sc/qa/unit/ThemeImportExportTest.cxx          |   71 ++++++++++++++++++++++++++
 sc/qa/unit/data/xlsx/CalcThemeTest.xlsx       |binary
 sc/source/filter/excel/xestyle.cxx            |   62 +++++++++++++++-------
 sc/source/filter/inc/xestyle.hxx              |    5 +
 6 files changed, 186 insertions(+), 20 deletions(-)

New commits:
commit 25aa310b923ac26b62a97c0e95549e053d294da4
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed May 17 14:54:20 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Jun 22 05:24:09 2023 +0200

    sc: theme color export for cell fill color + test
    
    Change-Id: Ibaad410f094f86d9f7197090db702ae45340c239
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151859
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sc/CppunitTest_sc_theme_import_export_test.mk 
b/sc/CppunitTest_sc_theme_import_export_test.mk
new file mode 100644
index 000000000000..52f9736e36b9
--- /dev/null
+++ b/sc/CppunitTest_sc_theme_import_export_test.mk
@@ -0,0 +1,67 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sc_theme_import_export_test))
+
+$(eval $(call 
gb_CppunitTest_use_common_precompiled_header,sc_theme_import_export_test))
+
+$(eval $(call 
gb_CppunitTest_add_exception_objects,sc_theme_import_export_test, \
+    sc/qa/unit/ThemeImportExportTest \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sc_theme_import_export_test, \
+    boost_headers \
+    mdds_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sc_theme_import_export_test, \
+    basegfx \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    salhelper \
+    sax \
+    sc \
+    scqahelper \
+    sfx \
+    subsequenttest \
+    test \
+    tl \
+    unotest \
+    utl \
+    vcl \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sc_theme_import_export_test,\
+    -I$(SRCDIR)/sc/source/ui/inc \
+    -I$(SRCDIR)/sc/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sc_theme_import_export_test,\
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,sc_theme_import_export_test))
+$(eval $(call gb_CppunitTest_use_ure,sc_theme_import_export_test))
+$(eval $(call gb_CppunitTest_use_vcl,sc_theme_import_export_test))
+$(eval $(call gb_CppunitTest_use_rdb,sc_theme_import_export_test,services))
+$(eval $(call gb_CppunitTest_use_components,sc_theme_import_export_test))
+$(eval $(call gb_CppunitTest_use_configuration,sc_theme_import_export_test))
+
+$(eval $(call gb_CppunitTest_add_arguments,sc_theme_import_export_test, \
+    
-env:arg-env=$(gb_Helper_LIBRARY_PATH_VAR)"$$$${$(gb_Helper_LIBRARY_PATH_VAR)+=$$$$$(gb_Helper_LIBRARY_PATH_VAR)}"
 \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index ce76695b4e4b..0c2178b7fea1 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -236,6 +236,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\
        CppunitTest_sc_tablesheetsobj \
        CppunitTest_sc_tablevalidationobj \
        CppunitTest_sc_tabviewobj \
+       CppunitTest_sc_theme_import_export_test \
        CppunitTest_sc_uniquecellformatsenumeration \
        CppunitTest_sc_uniquecellformatsobj \
        CppunitTest_sc_viewpaneobj \
diff --git a/sc/qa/unit/ThemeImportExportTest.cxx 
b/sc/qa/unit/ThemeImportExportTest.cxx
new file mode 100644
index 000000000000..ae1653837f36
--- /dev/null
+++ b/sc/qa/unit/ThemeImportExportTest.cxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/unoapixml_test.hxx>
+
+#include <com/sun/star/lang/XComponent.hpp>
+#include <comphelper/servicehelper.hxx>
+#include <docsh.hxx>
+
+using namespace css;
+
+class ThemeImportExportTest : public UnoApiXmlTest
+{
+public:
+    ThemeImportExportTest()
+        : UnoApiXmlTest("sc/qa/unit/data")
+    {
+    }
+
+    void test();
+
+    CPPUNIT_TEST_SUITE(ThemeImportExportTest);
+    CPPUNIT_TEST(test);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void ThemeImportExportTest::test()
+{
+    loadFromURL(u"xlsx/CalcThemeTest.xlsx");
+
+    save("Calc Office Open XML");
+
+    xmlDocUniquePtr pXmlDoc = parseExport("xl/styles.xml");
+
+    assertXPath(pXmlDoc, "/x:styleSheet", 1);
+
+    // Fonts
+    assertXPath(pXmlDoc, "/x:styleSheet/x:fonts/x:font", 6);
+
+    assertXPath(pXmlDoc, "/x:styleSheet/x:fonts/x:font[5]/x:color", "rgb",
+                "FFFFC000"); // need to be theme probably
+
+    assertXPath(pXmlDoc, "/x:styleSheet/x:fonts/x:font[6]/x:color", "rgb",
+                "FF9C5700"); // need to be theme probably
+
+    // Fills
+    assertXPath(pXmlDoc, "/x:styleSheet/x:fills/x:fill", 4);
+
+    assertXPath(pXmlDoc, "/x:styleSheet/x:fills/x:fill[1]/x:patternFill", 
"patternType", "none");
+
+    assertXPath(pXmlDoc, "/x:styleSheet/x:fills/x:fill[2]/x:patternFill", 
"patternType", "gray125");
+
+    assertXPath(pXmlDoc, "/x:styleSheet/x:fills/x:fill[3]/x:patternFill", 
"patternType", "solid");
+    assertXPath(pXmlDoc, 
"/x:styleSheet/x:fills/x:fill[3]/x:patternFill/x:fgColor", "rgb",
+                "FFFFEB9C");
+
+    assertXPath(pXmlDoc, "/x:styleSheet/x:fills/x:fill[4]/x:patternFill", 
"patternType", "solid");
+    assertXPath(pXmlDoc, 
"/x:styleSheet/x:fills/x:fill[4]/x:patternFill/x:fgColor", "theme", "4");
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ThemeImportExportTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/data/xlsx/CalcThemeTest.xlsx 
b/sc/qa/unit/data/xlsx/CalcThemeTest.xlsx
new file mode 100644
index 000000000000..f684eb9dd3ec
Binary files /dev/null and b/sc/qa/unit/data/xlsx/CalcThemeTest.xlsx differ
diff --git a/sc/source/filter/excel/xestyle.cxx 
b/sc/source/filter/excel/xestyle.cxx
index 33c2f2db8987..998cad5bb723 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -1869,10 +1869,10 @@ void XclExpCellBorder::SaveXml( XclExpXmlStream& rStrm 
) const
 }
 
 XclExpCellArea::XclExpCellArea() :
-    mnForeColorId( XclExpPalette::GetColorIdFromIndex( mnForeColor ) ),
-    mnBackColorId( XclExpPalette::GetColorIdFromIndex( mnBackColor ) ),
-    maForeColor(0),
-    maBackColor(0)
+    mnForeColorId(XclExpPalette::GetColorIdFromIndex(mnForeColor)),
+    mnBackColorId(XclExpPalette::GetColorIdFromIndex(mnBackColor)),
+    maForeColor(COL_TRANSPARENT),
+    maBackColor(COL_TRANSPARENT)
 {
 }
 
@@ -1888,6 +1888,10 @@ XclExpCellArea::XclExpCellArea(Color aForeColor, Color 
aBackColor)
 bool XclExpCellArea::FillFromItemSet( const SfxItemSet& rItemSet, 
XclExpPalette& rPalette, bool bStyle )
 {
     const SvxBrushItem& rBrushItem = rItemSet.Get( ATTR_BACKGROUND );
+
+    if (rBrushItem.getComplexColor().getType() != model::ColorType::Unused)
+        maForegroundComplexColor = rBrushItem.getComplexColor();
+
     if( rBrushItem.GetColor().IsTransparent() )
     {
         mnPattern = EXC_PATT_NONE;
@@ -1958,39 +1962,53 @@ void XclExpCellArea::SaveXml( XclExpXmlStream& rStrm ) 
const
 
     XclExpPalette& rPalette = rStrm.GetRoot().GetPalette();
 
-    if (mnPattern == EXC_PATT_NONE
-        || (mnForeColor == 0 && mnBackColor == 0 && maForeColor == 0 && 
maBackColor == 0))
+    if (mnPattern == EXC_PATT_NONE ||
+        (mnForeColor == 0 && mnBackColor == 0 && maForeColor == 
COL_TRANSPARENT && maBackColor == COL_TRANSPARENT))
     {
         rStyleSheet->singleElement(XML_patternFill, XML_patternType, 
ToPatternType(mnPattern));
     }
     else
     {
         rStyleSheet->startElement(XML_patternFill, XML_patternType, 
ToPatternType(mnPattern));
-        if (maForeColor != 0 || maBackColor != 0)
+
+        if (maForeColor != COL_TRANSPARENT || maBackColor != COL_TRANSPARENT)
         {
-            if (maForeColor != 0)
+            if (maForegroundComplexColor.getType() == model::ColorType::Scheme)
             {
-                rStyleSheet->singleElement(XML_fgColor, XML_rgb,
-                                           
XclXmlUtils::ToOString(maForeColor));
+                rStyleSheet->singleElement(XML_fgColor, XML_theme, 
OString::number(sal_Int32(maForegroundComplexColor.getSchemeType())));
+            }
+            else if (maForeColor != COL_TRANSPARENT)
+            {
+                rStyleSheet->singleElement(XML_fgColor, XML_rgb, 
XclXmlUtils::ToOString(maForeColor));
             }
 
-            if (maBackColor != 0)
+            if (maBackgroundComplexColor.getType() == model::ColorType::Scheme)
+            {
+                rStyleSheet->singleElement(XML_fgColor, XML_theme, 
OString::number(sal_Int32(maBackgroundComplexColor.getSchemeType())));
+            }
+            else if (maBackColor != COL_TRANSPARENT)
             {
-                rStyleSheet->singleElement(XML_bgColor, XML_rgb,
-                                           
XclXmlUtils::ToOString(maBackColor));
+                rStyleSheet->singleElement(XML_bgColor, XML_rgb, 
XclXmlUtils::ToOString(maBackColor));
             }
         }
         else
         {
-            if (mnForeColor != 0)
+            if (maForegroundComplexColor.getType() == model::ColorType::Scheme)
             {
-                rStyleSheet->singleElement(XML_fgColor, XML_rgb,
-                                           
XclXmlUtils::ToOString(rPalette.GetColor(mnForeColor)));
+                rStyleSheet->singleElement(XML_fgColor, XML_theme, 
OString::number(sal_Int32(maForegroundComplexColor.getSchemeType())));
             }
-            if (mnBackColor != 0)
+            else if (mnForeColor != 0)
             {
-                rStyleSheet->singleElement(XML_bgColor, XML_rgb,
-                                           
XclXmlUtils::ToOString(rPalette.GetColor(mnBackColor)));
+                rStyleSheet->singleElement(XML_fgColor, XML_rgb, 
XclXmlUtils::ToOString(rPalette.GetColor(mnForeColor)));
+            }
+
+            if (maBackgroundComplexColor.getType() == model::ColorType::Scheme)
+            {
+                rStyleSheet->singleElement(XML_fgColor, XML_theme, 
OString::number(sal_Int32(maBackgroundComplexColor.getSchemeType())));
+            }
+            else if (mnBackColor != 0)
+            {
+                rStyleSheet->singleElement(XML_bgColor, XML_rgb, 
XclXmlUtils::ToOString(rPalette.GetColor(mnBackColor)));
             }
         }
 
@@ -2007,6 +2025,7 @@ bool XclExpColor::FillFromItemSet( const SfxItemSet& 
rItemSet )
 
     const SvxBrushItem& rBrushItem = rItemSet.Get( ATTR_BACKGROUND );
     maColor = rBrushItem.GetColor();
+    maComplexColor = rBrushItem.getComplexColor();
 
     return true;
 }
@@ -2016,7 +2035,10 @@ void XclExpColor::SaveXml( XclExpXmlStream& rStrm ) const
     sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
     rStyleSheet->startElement(XML_fill);
     rStyleSheet->startElement(XML_patternFill);
-    rStyleSheet->singleElement(XML_bgColor, XML_rgb, 
XclXmlUtils::ToOString(maColor));
+    if (maComplexColor.getType() == model::ColorType::Scheme)
+        rStyleSheet->singleElement(XML_bgColor, XML_theme, 
OString::number(sal_Int32(maComplexColor.getSchemeType())));
+    else
+        rStyleSheet->singleElement(XML_bgColor, XML_rgb, 
XclXmlUtils::ToOString(maColor));
 
     rStyleSheet->endElement( XML_patternFill );
     rStyleSheet->endElement( XML_fill );
diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx
index bd72f8aa5552..c479c6ac51f6 100644
--- a/sc/source/filter/inc/xestyle.hxx
+++ b/sc/source/filter/inc/xestyle.hxx
@@ -30,6 +30,7 @@
 #include <memory>
 #include <utility>
 #include <vector>
+#include <docmodel/color/ComplexColor.hxx>
 
 /* ============================================================================
 - Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
@@ -375,6 +376,9 @@ struct XclExpCellArea : public XclCellArea
     Color maForeColor; // Actual foreground color
     Color maBackColor; // Actual background color
 
+    model::ComplexColor maForegroundComplexColor;
+    model::ComplexColor maBackgroundComplexColor;
+
     explicit XclExpCellArea();
     explicit XclExpCellArea(Color aForeColor, Color aBackColor);
 
@@ -400,6 +404,7 @@ struct XclExpCellArea : public XclCellArea
 struct XclExpColor
 {
     Color maColor;
+    model::ComplexColor maComplexColor;
 
     bool FillFromItemSet( const SfxItemSet& rItemSet );
 

Reply via email to