[Libreoffice-commits] core.git: Branch 'feature/themesupport2' - 9 commits - editeng/source include/editeng offapi/com svx/sdi svx/source sw/qa sw/source writerfilter/source

Jan Holesovsky (via logerrit) logerrit at kemper.freedesktop.org
Sat Jun 19 11:51:50 UTC 2021


Rebased ref, commits from common ancestor:
commit 18da302474cc58314649a3bc6700651ed2d44c15
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Apr 2 00:21:34 2021 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:19 2021 +0900

    Unit test (with the content disabled so far) for the theming.
    
    Change-Id: Ie9e003df38e1bc766fb5323936138d3e0e664321

diff --git a/sw/qa/extras/ooxmlexport/data/themeOrange.docx b/sw/qa/extras/ooxmlexport/data/themeOrange.docx
new file mode 100644
index 000000000000..e350c2676d41
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/themeOrange.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index b550e62ef6a2..7af07caa58d8 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -518,6 +518,12 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(Test_ShadowDirection, "tdf142361ShadowDirect
                 "rotWithShape", "0");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testThemeOrange, "themeOrange.docx")
+{
+    // Assert that the theme color of the 1st paragraph is "accent1"
+    //CPPUNIT_ASSERT_EQUAL(getProperty<sal_Int16>(getParagraph(1), "CharColorTheme"), static_cast<sal_Int16>(4));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit afcbc832cae0cd825e5c69748f8a7df2516bb689
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Sep 24 12:32:14 2015 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:19 2021 +0900

    Improve preview of theme color sets - add color set name
    
    Change-Id: I1f7b3668ba9dfbab1da283741e99754de2d6be47

diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx
index 09a7665950c9..d41db8ffd659 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -19,6 +19,7 @@
 #include <editeng/fontitem.hxx>
 #include <vcl/bitmapex.hxx>
 #include <vcl/image.hxx>
+#include <vcl/settings.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/virdev.hxx>
 #include <charatr.hxx>
@@ -371,17 +372,39 @@ BitmapEx GenerateColorPreview(const svx::ColorSet& rColorSet)
 {
     ScopedVclPtrInstance<VirtualDevice> pVirtualDev(*Application::GetDefaultDevice());
     float fScaleFactor = pVirtualDev->GetDPIScaleFactor();
-    tools::Long BORDER = 2 * fScaleFactor;
-    tools::Long SIZE = 12 * fScaleFactor;
+    long BORDER = 3 * fScaleFactor;
+    long SIZE = 14 * fScaleFactor;
+    long LABEL_HEIGHT = 16 * fScaleFactor;
+    long LABEL_TEXT_HEIGHT = 14 * fScaleFactor;
 
-    Size aSize(BORDER * 7 + SIZE * 6, BORDER * 3 + SIZE * 2);
+    Size aSize(BORDER * 7 + SIZE * 6 + BORDER * 2, BORDER * 3 + SIZE * 2 + LABEL_HEIGHT);
     pVirtualDev->SetOutputSizePixel(aSize);
+    pVirtualDev->SetBackground(Wallpaper(Application::GetSettings().GetStyleSettings().GetFaceColor()));
+    pVirtualDev->Erase();
 
     tools::Long x = BORDER;
-    tools::Long y1 = BORDER;
+    tools::Long y1 = BORDER + LABEL_HEIGHT;
     tools::Long y2 = y1 + SIZE + BORDER;
 
     pVirtualDev->SetLineColor(COL_LIGHTGRAY);
+    pVirtualDev->SetFillColor(COL_LIGHTGRAY);
+    tools::Rectangle aNameRect(Point(0, 0), Size(aSize.Width(), LABEL_HEIGHT));
+    pVirtualDev->DrawRect(aNameRect);
+
+    vcl::Font aFont;
+    OUString aName = rColorSet.getName();
+    aFont.SetFontHeight(LABEL_TEXT_HEIGHT);
+    pVirtualDev->SetFont(aFont);
+
+    Size aTextSize(pVirtualDev->GetTextWidth(aName), pVirtualDev->GetTextHeight());
+
+    Point aPoint((aNameRect.GetWidth()  / 2.0) - (aTextSize.Width()  / 2.0),
+                 (aNameRect.GetHeight() / 2.0) - (aTextSize.Height() / 2.0));
+
+    pVirtualDev->DrawText(aPoint, aName);
+
+    pVirtualDev->SetLineColor(COL_LIGHTGRAY);
+    pVirtualDev->SetFillColor();
 
     for (sal_uInt32 i = 0; i < 12; i += 2)
     {
@@ -392,6 +415,8 @@ BitmapEx GenerateColorPreview(const svx::ColorSet& rColorSet)
         pVirtualDev->DrawRect(tools::Rectangle(x, y2, x + SIZE, y2 + SIZE));
 
         x += SIZE + BORDER;
+        if (i == 2 || i == 8)
+            x += BORDER;
     }
 
     return pVirtualDev->GetBitmapEx(Point(), aSize);
@@ -419,6 +444,7 @@ ThemePanel::ThemePanel(weld::Widget* pParent)
 {
     mxValueSetColors->SetColCount(2);
     mxValueSetColors->SetLineCount(3);
+    mxValueSetColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
 
     mxApplyButton->connect_clicked(LINK(this, ThemePanel, ClickHdl));
     mxListBoxFonts->connect_row_activated(LINK(this, ThemePanel, DoubleClickHdl));
commit bc94559bc118da7957799f36cf721cc2e7335eb7
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Sep 24 12:30:10 2015 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:19 2021 +0900

    StylePresets: set bacground color for ValueSet
    
    Change-Id: Ifbaab139235dbe2fdcebf278bce2c91c2b744aa6

diff --git a/sw/source/uibase/sidebar/StylePresetsPanel.cxx b/sw/source/uibase/sidebar/StylePresetsPanel.cxx
index 79b1b93ed34c..981f26b3e839 100644
--- a/sw/source/uibase/sidebar/StylePresetsPanel.cxx
+++ b/sw/source/uibase/sidebar/StylePresetsPanel.cxx
@@ -13,8 +13,9 @@
 #include "StylePresetsPanel.hxx"
 
 #include <vcl/image.hxx>
-#include <vcl/virdev.hxx>
+#include <vcl/settings.hxx>
 #include <vcl/svapp.hxx>
+#include <vcl/virdev.hxx>
 
 #include <sfx2/objsh.hxx>
 #include <sfx2/StylePreviewRenderer.hxx>
@@ -145,6 +146,7 @@ StylePresetsPanel::StylePresetsPanel(weld::Widget* pParent)
 {
     mxValueSet->SetColCount(2);
 
+    mxValueSet->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
     mxValueSet->SetDoubleClickHdl(LINK(this, StylePresetsPanel, DoubleClickHdl));
 
     RefreshList();
commit 02b450f120139803a3ee57242edf49dab7a6e6ef
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Sep 23 13:38:38 2015 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:18 2021 +0900

    adjust the conversion from theme color type to the color set index
    
    Change-Id: I8c54c8935de8acc3e2b302e10327aa2488f9ac85

diff --git a/writerfilter/source/dmapper/TDefTableHandler.cxx b/writerfilter/source/dmapper/TDefTableHandler.cxx
index 42ab0d61bd83..4bc8faf7e3d5 100644
--- a/writerfilter/source/dmapper/TDefTableHandler.cxx
+++ b/writerfilter/source/dmapper/TDefTableHandler.cxx
@@ -298,15 +298,15 @@ sal_Int16 TDefTableHandler::getThemeColorTypeIndex(sal_Int32 nType)
         case NS_ooxml::LN_Value_St_ThemeColor_followedHyperlink:
                 return 11;
         case NS_ooxml::LN_Value_St_ThemeColor_none:
-                return 12;
+                return -1;
         case NS_ooxml::LN_Value_St_ThemeColor_background1:
-                return 13;
+                return 0;
         case NS_ooxml::LN_Value_St_ThemeColor_text1:
-                return 14;
+                return 1;
         case NS_ooxml::LN_Value_St_ThemeColor_background2:
-                return 15;
+                return 2;
         case NS_ooxml::LN_Value_St_ThemeColor_text2:
-                return 16;
+                return 3;
         default:
                 break;
     }
commit 7efbb18409fe7c8f9764ab8a9792d90a5fedcf83
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Sep 23 13:37:43 2015 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:18 2021 +0900

    convert tint value from ooxml to the value we support
    
    Change-Id: I5a79ca434be16f9dccc5aa6118a7efbf4544f0b1

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index c08e1e130ce1..0542f58ef11f 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -999,7 +999,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
         case NS_ooxml::LN_CT_Color_themeTint:
             if (m_pImpl->GetTopContext())
             {
-                m_pImpl->GetTopContext()->Insert(PROP_CHAR_COLOR_TINT_OR_SHADE, uno::makeAny(sal_Int16(nIntValue * 10000 / 256)));
+                m_pImpl->GetTopContext()->Insert(PROP_CHAR_COLOR_TINT_OR_SHADE, uno::makeAny(sal_Int16((256 - nIntValue) * 10000 / 256)));
             }
             m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "themeTint", OUString::number(nIntValue, 16));
         break;
commit 135da0bf0b15e72af8c02a465fb669e196a116e9
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Sep 23 13:35:56 2015 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:18 2021 +0900

    check that the color index is valid
    
    Change-Id: Id5c7c83f50e1611af12f3b25e6c9a335a8353ba0

diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx
index 8f63588f9622..09a7665950c9 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -231,9 +231,9 @@ void changeFont(SwFormat* pFormat, SwDocStyleSheet const * pStyle, FontSet const
 void changeColor(SwTextFormatColl* pCollection, svx::ColorSet const& rColorSet, StyleRedefinition* /*pRedefinition*/)
 {
     SvxColorItem aColorItem(pCollection->GetColor());
-    if (aColorItem.GetThemeIndex() >= 0)
+    sal_Int16 nIndex = aColorItem.GetThemeIndex();
+    if (nIndex >= 0 && nIndex < 12)
     {
-        sal_Int16 nIndex = aColorItem.GetThemeIndex();
         Color aColor = Color(rColorSet.getColor(nIndex));
         aColor.ApplyTintOrShade(aColorItem.GetTintOrShade());
         aColorItem.SetValue(aColor);
commit 5bfd84e9e32f9311e2c1ed7b8c64704049f1278b
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Sep 23 13:33:59 2015 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:18 2021 +0900

    swap text and background colors in colorsets
    
    Change-Id: I1e1da85d6c58e3ed5ab4c44c2ab0ae7c3b080251

diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx
index 0c68d726a017..7a04eb4e6314 100644
--- a/svx/source/styles/ColorSets.cxx
+++ b/svx/source/styles/ColorSets.cxx
@@ -28,10 +28,10 @@ void ColorSets::init()
 {
     {
         ColorSet aColorSet("Breeze");
-        aColorSet.add(0,  0x232629);
-        aColorSet.add(1,  0xFCFCFC);
-        aColorSet.add(2,  0x31363B);
-        aColorSet.add(3,  0xEFF0F1);
+        aColorSet.add(0,  0xFCFCFC);
+        aColorSet.add(1,  0x232629);
+        aColorSet.add(2,  0xEFF0F1);
+        aColorSet.add(3,  0x31363B);
         aColorSet.add(4,  0xDA4453);
         aColorSet.add(5,  0xF47750);
         aColorSet.add(6,  0xFDBC4B);
@@ -44,10 +44,10 @@ void ColorSets::init()
     }
     {
         ColorSet aColorSet("Material Blue");
-        aColorSet.add(0,  0x212121);
-        aColorSet.add(1,  0xFFFFFF);
-        aColorSet.add(2,  0x37474F);
-        aColorSet.add(3,  0xECEFF1);
+        aColorSet.add(0,  0xFFFFFF);
+        aColorSet.add(1,  0x212121);
+        aColorSet.add(2,  0xECEFF1);
+        aColorSet.add(3,  0x37474F);
         aColorSet.add(4,  0x7986CB);
         aColorSet.add(5,  0x303F9F);
         aColorSet.add(6,  0x64B5F6);
@@ -60,10 +60,10 @@ void ColorSets::init()
     }
     {
         ColorSet aColorSet("Material Red");
-        aColorSet.add(0,  0x212121);
-        aColorSet.add(1,  0xFFFFFF);
-        aColorSet.add(2,  0x424242);
-        aColorSet.add(3,  0xF5F5F5);
+        aColorSet.add(0,  0xFFFFFF);
+        aColorSet.add(1,  0x212121);
+        aColorSet.add(2,  0xF5F5F5);
+        aColorSet.add(3,  0x424242);
         aColorSet.add(4,  0xFF9800);
         aColorSet.add(5,  0xFF6D00);
         aColorSet.add(6,  0xFF5722);
@@ -76,10 +76,10 @@ void ColorSets::init()
     }
     {
         ColorSet aColorSet("Material Green");
-        aColorSet.add(0,  0x212121);
-        aColorSet.add(1,  0xFFFFFF);
-        aColorSet.add(2,  0x424242);
-        aColorSet.add(3,  0xF5F5F5);
+        aColorSet.add(0,  0xFFFFFF);
+        aColorSet.add(1,  0x212121);
+        aColorSet.add(2,  0xF5F5F5);
+        aColorSet.add(3,  0x424242);
         aColorSet.add(4,  0x009688);
         aColorSet.add(5,  0x00bfa5);
         aColorSet.add(6,  0x4caf50);
commit c598023b5f5630d5246756b6f0d43a39428d2be9
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Sep 20 19:27:09 2015 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:18 2021 +0900

    Support reading back theme color from an ooxml document
    
    ooxml supports theme colors and tint/shade value that additionally
    changed the theme color. Read back which theme color + tint/shade
    value was applied in the resulting color and add this attributes
    as properties to be used by writer.
    In sidebar theme panel the changing the theme colors now doesn't
    takes this into account and changes the colors correctly.
    
    Change-Id: I6703e86b1fc6b2ba07f3023ec48e619aec961ff1

diff --git a/include/editeng/unoprnms.hxx b/include/editeng/unoprnms.hxx
index 011e504ae7f4..c637521dcf2d 100644
--- a/include/editeng/unoprnms.hxx
+++ b/include/editeng/unoprnms.hxx
@@ -22,6 +22,8 @@
 
 
 #define UNO_NAME_CHAR_COLOR                     "CharColor"
+#define UNO_NAME_CHAR_COLOR_THEME               "CharColorTheme"
+#define UNO_NAME_CHAR_COLOR_TINT_OR_SHADE       "CharColorTintOrShade"
 #define UNO_NAME_CHAR_HEIGHT                    "CharHeight"
 #define UNO_NAME_CHAR_POSTURE                   "CharPosture"
 #define UNO_NAME_CHAR_SHADOWED                  "CharShadowed"
diff --git a/sw/source/core/unocore/unomap.cxx b/sw/source/core/unocore/unomap.cxx
index 3580a8f416a2..26913359031e 100644
--- a/sw/source/core/unocore/unomap.cxx
+++ b/sw/source/core/unocore/unomap.cxx
@@ -1506,7 +1506,7 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetPropertyMapEntries(s
                     // SvxAdjustItem
                     { u"" UNO_NAME_PARA_ADJUST,            RES_PARATR_ADJUST, cppu::UnoType<sal_Int16>::get(),PropertyAttribute::MAYBEVOID,  MID_PARA_ADJUST                      },
                     // SvxColorItem
-                    { u"" UNO_NAME_CHAR_COLOR,             RES_CHRATR_COLOR,  cppu::UnoType<sal_Int32>::get(),               PROPERTY_NONE,  0                                    },
+                    { u"" UNO_NAME_CHAR_COLOR,             RES_CHRATR_COLOR,  cppu::UnoType<sal_Int32>::get(),               PROPERTY_NONE,  MID_COLOR_RGB                        },
                     // SvxShadowedItem
                     { u"" UNO_NAME_CHAR_SHADOWED,          RES_CHRATR_SHADOWED,    cppu::UnoType<bool>::get(),               PROPERTY_NONE,  0                                    },
                     // SvxContouredItem
diff --git a/sw/source/core/unocore/unomapproperties.hxx b/sw/source/core/unocore/unomapproperties.hxx
index 263a712010c0..f873500432e7 100644
--- a/sw/source/core/unocore/unomapproperties.hxx
+++ b/sw/source/core/unocore/unomapproperties.hxx
@@ -121,8 +121,10 @@
         { u"" UNO_NAME_CHAR_HIGHLIGHT,                      RES_CHRATR_HIGHLIGHT,          cppu::UnoType<sal_Int32>::get(), PropertyAttribute::MAYBEVOID, MID_BACK_COLOR                         }, \
         { u"" UNO_NAME_PARA_BACK_COLOR,                     RES_BACKGROUND,                cppu::UnoType<sal_Int32>::get(),         PropertyAttribute::MAYBEVOID, MID_BACK_COLOR                         }, \
         { u"" UNO_NAME_CHAR_CASE_MAP,                       RES_CHRATR_CASEMAP,            cppu::UnoType<sal_Int16>::get(),         PropertyAttribute::MAYBEVOID, 0                                      }, \
-        { u"" UNO_NAME_CHAR_COLOR,                          RES_CHRATR_COLOR,              cppu::UnoType<sal_Int32>::get(),         PropertyAttribute::MAYBEVOID, 0                                      }, \
+        { u"" UNO_NAME_CHAR_COLOR,                          RES_CHRATR_COLOR,              cppu::UnoType<sal_Int32>::get(),         PropertyAttribute::MAYBEVOID, MID_COLOR_RGB }, \
         { u"" UNO_NAME_CHAR_TRANSPARENCE,                   RES_CHRATR_COLOR,              cppu::UnoType<sal_Int16>::get(),         PropertyAttribute::MAYBEVOID, MID_COLOR_ALPHA }, \
+        { u"" UNO_NAME_CHAR_COLOR_THEME,                    RES_CHRATR_COLOR,              cppu::UnoType<sal_Int16>::get(),         PropertyAttribute::MAYBEVOID, MID_COLOR_THEME_INDEX }, \
+        { u"" UNO_NAME_CHAR_COLOR_TINT_OR_SHADE,            RES_CHRATR_COLOR,              cppu::UnoType<sal_Int16>::get(),         PropertyAttribute::MAYBEVOID, MID_COLOR_TINT_OR_SHADE }, \
         { u"" UNO_NAME_CHAR_STRIKEOUT,                      RES_CHRATR_CROSSEDOUT,         cppu::UnoType<sal_Int16>::get(),         PropertyAttribute::MAYBEVOID, MID_CROSS_OUT                          }, \
         { u"" UNO_NAME_CHAR_CROSSED_OUT,                    RES_CHRATR_CROSSEDOUT,         cppu::UnoType<bool>::get(),       PropertyAttribute::MAYBEVOID, MID_CROSSED_OUT                        }, \
         { u"" UNO_NAME_CHAR_ESCAPEMENT,                     RES_CHRATR_ESCAPEMENT,         cppu::UnoType<sal_Int16>::get(),         PropertyAttribute::MAYBEVOID, MID_ESC                                }, \
@@ -363,8 +365,10 @@
                     { u"" UNO_NAME_PARA_GRAPHIC_FILTER, RES_BACKGROUND,       cppu::UnoType<OUString>::get(), PROPERTY_NONE ,MID_GRAPHIC_FILTER    },\
                     { u"" UNO_NAME_PARA_GRAPHIC_LOCATION, RES_BACKGROUND,         cppu::UnoType<css::style::GraphicLocation>::get(), PROPERTY_NONE ,MID_GRAPHIC_POSITION}, \
                     { u"" UNO_NAME_CHAR_CASE_MAP, RES_CHRATR_CASEMAP,     cppu::UnoType<sal_Int16>::get(),           PROPERTY_NONE, 0},\
-                    { u"" UNO_NAME_CHAR_COLOR, RES_CHRATR_COLOR,      cppu::UnoType<sal_Int32>::get(),           PROPERTY_NONE, 0},\
+                    { u"" UNO_NAME_CHAR_COLOR,        RES_CHRATR_COLOR,      cppu::UnoType<sal_Int32>::get(),           PROPERTY_NONE, MID_COLOR_RGB }, \
                     { u"" UNO_NAME_CHAR_TRANSPARENCE, RES_CHRATR_COLOR,      cppu::UnoType<sal_Int16>::get(),           PROPERTY_NONE, MID_COLOR_ALPHA},\
+                    { u"" UNO_NAME_CHAR_COLOR_THEME,  RES_CHRATR_COLOR,      cppu::UnoType<sal_Int16>::get(),           PROPERTY_NONE, MID_COLOR_THEME_INDEX }, \
+                    { u"" UNO_NAME_CHAR_COLOR_TINT_OR_SHADE, RES_CHRATR_COLOR, cppu::UnoType<sal_Int16>::get(),         PROPERTY_NONE, MID_COLOR_TINT_OR_SHADE }, \
                     { u"" UNO_NAME_CHAR_STRIKEOUT, RES_CHRATR_CROSSEDOUT,  cppu::UnoType<sal_Int16>::get(),                  PropertyAttribute::MAYBEVOID, MID_CROSS_OUT},\
                     { u"" UNO_NAME_CHAR_CROSSED_OUT, RES_CHRATR_CROSSEDOUT,  cppu::UnoType<bool>::get()  ,        PROPERTY_NONE, 0},\
                     { u"" UNO_NAME_CHAR_ESCAPEMENT, RES_CHRATR_ESCAPEMENT,  cppu::UnoType<sal_Int16>::get(),             PROPERTY_NONE, MID_ESC          },\
@@ -468,8 +472,10 @@
 
 #define COMMON_ACCESSIBILITY_TEXT_ATTRIBUTE \
                     { u"" UNO_NAME_CHAR_BACK_COLOR, RES_CHRATR_BACKGROUND,    cppu::UnoType<sal_Int32>::get(),           PROPERTY_NONE ,MID_BACK_COLOR        }, \
-                    { u"" UNO_NAME_CHAR_COLOR, RES_CHRATR_COLOR,      cppu::UnoType<sal_Int32>::get(),           PROPERTY_NONE, 0},  \
+                    { u"" UNO_NAME_CHAR_COLOR,        RES_CHRATR_COLOR,      cppu::UnoType<sal_Int32>::get(),           PROPERTY_NONE, MID_COLOR_RGB },  \
                     { u"" UNO_NAME_CHAR_TRANSPARENCE, RES_CHRATR_COLOR,      cppu::UnoType<sal_Int16>::get(),           PROPERTY_NONE, MID_COLOR_ALPHA },  \
+                    { u"" UNO_NAME_CHAR_COLOR_THEME,  RES_CHRATR_COLOR,      cppu::UnoType<sal_Int16>::get(),           PROPERTY_NONE, MID_COLOR_THEME_INDEX }, \
+                    { u"" UNO_NAME_CHAR_COLOR_TINT_OR_SHADE, RES_CHRATR_COLOR, cppu::UnoType<sal_Int16>::get(),         PROPERTY_NONE, MID_COLOR_TINT_OR_SHADE }, \
                     { u"" UNO_NAME_CHAR_CONTOURED, RES_CHRATR_CONTOUR,    cppu::UnoType<bool>::get()  ,       PROPERTY_NONE, 0},  \
                     { u"" UNO_NAME_CHAR_EMPHASIS, RES_CHRATR_EMPHASIS_MARK,           cppu::UnoType<sal_Int16>::get(),   PROPERTY_NONE, MID_EMPHASIS},   \
                     { u"" UNO_NAME_CHAR_ESCAPEMENT, RES_CHRATR_ESCAPEMENT,  cppu::UnoType<sal_Int16>::get(),             PROPERTY_NONE, MID_ESC          },  \
diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx
index 3ff74fcdb016..8f63588f9622 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -228,13 +228,17 @@ void changeFont(SwFormat* pFormat, SwDocStyleSheet const * pStyle, FontSet const
     }
 }*/
 
-void changeColor(SwTextFormatColl* pCollection, svx::ColorSet const & rColorSet, StyleRedefinition* pRedefinition)
+void changeColor(SwTextFormatColl* pCollection, svx::ColorSet const& rColorSet, StyleRedefinition* /*pRedefinition*/)
 {
-    Color aColor = pRedefinition->getColor(rColorSet);
-
     SvxColorItem aColorItem(pCollection->GetColor());
-    aColorItem.SetValue(aColor);
-    pCollection->SetFormatAttr(aColorItem);
+    if (aColorItem.GetThemeIndex() >= 0)
+    {
+        sal_Int16 nIndex = aColorItem.GetThemeIndex();
+        Color aColor = Color(rColorSet.getColor(nIndex));
+        aColor.ApplyTintOrShade(aColorItem.GetTintOrShade());
+        aColorItem.SetValue(aColor);
+        pCollection->SetFormatAttr(aColorItem);
+    }
 }
 
 std::vector<FontSet> initFontSets()
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index fd341dd4d765..c08e1e130ce1 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -989,12 +989,25 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
             // footnote or endnote reference id - not needed
         break;
         case NS_ooxml::LN_CT_Color_themeColor:
+            if (m_pImpl->GetTopContext())
+            {
+                sal_Int16 nIndex = TDefTableHandler::getThemeColorTypeIndex(nIntValue);
+                m_pImpl->GetTopContext()->Insert(PROP_CHAR_COLOR_THEME_INDEX, uno::makeAny(nIndex));
+            }
             m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue));
         break;
         case NS_ooxml::LN_CT_Color_themeTint:
+            if (m_pImpl->GetTopContext())
+            {
+                m_pImpl->GetTopContext()->Insert(PROP_CHAR_COLOR_TINT_OR_SHADE, uno::makeAny(sal_Int16(nIntValue * 10000 / 256)));
+            }
             m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "themeTint", OUString::number(nIntValue, 16));
         break;
         case NS_ooxml::LN_CT_Color_themeShade:
+            if (m_pImpl->GetTopContext())
+            {
+                m_pImpl->GetTopContext()->Insert(PROP_CHAR_COLOR_TINT_OR_SHADE, uno::makeAny(sal_Int16((nIntValue - 256) * 10000 / 256)));
+            }
             m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "themeShade", OUString::number(nIntValue, 16));
         break;
         case NS_ooxml::LN_CT_DocGrid_linePitch:
diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx
index 0100313bdf45..08b695a6007d 100644
--- a/writerfilter/source/dmapper/PropertyIds.cxx
+++ b/writerfilter/source/dmapper/PropertyIds.cxx
@@ -32,6 +32,8 @@ OUString getPropertyName( PropertyIds eId )
         case PROP_CHAR_SHADOWED:   sName = "CharShadowed"; break;
         case PROP_CHAR_CASE_MAP:   sName = "CharCaseMap"; break;
         case PROP_CHAR_COLOR:      sName = "CharColor"; break;
+        case PROP_CHAR_COLOR_THEME_INDEX: sName = "CharColorTheme"; break;
+        case PROP_CHAR_COLOR_TINT_OR_SHADE: sName = "CharColorTintOrShade"; break;
         case PROP_CHAR_RELIEF:     sName = "CharRelief"; break;
         case PROP_CHAR_UNDERLINE:  sName = "CharUnderline"; break;
         case PROP_CHAR_UNDERLINE_COLOR:  sName = "CharUnderlineColor"; break;
diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx
index a6afe0c5313f..09ec7954c8df 100644
--- a/writerfilter/source/dmapper/PropertyIds.hxx
+++ b/writerfilter/source/dmapper/PropertyIds.hxx
@@ -54,6 +54,8 @@ enum PropertyIds
         ,PROP_CHAR_CASE_MAP
         ,PROP_CHAR_CHAR_KERNING
         ,PROP_CHAR_COLOR
+        ,PROP_CHAR_COLOR_THEME_INDEX
+        ,PROP_CHAR_COLOR_TINT_OR_SHADE
         ,PROP_CHAR_COMBINE_IS_ON
         ,PROP_CHAR_COMBINE_PREFIX
         ,PROP_CHAR_COMBINE_SUFFIX
diff --git a/writerfilter/source/dmapper/TDefTableHandler.cxx b/writerfilter/source/dmapper/TDefTableHandler.cxx
index 9d7059feece6..42ab0d61bd83 100644
--- a/writerfilter/source/dmapper/TDefTableHandler.cxx
+++ b/writerfilter/source/dmapper/TDefTableHandler.cxx
@@ -269,6 +269,50 @@ OUString TDefTableHandler::getThemeColorTypeString(sal_Int32 nType)
     return OUString();
 }
 
+sal_Int16 TDefTableHandler::getThemeColorTypeIndex(sal_Int32 nType)
+{
+    switch (nType)
+    {
+        case NS_ooxml::LN_Value_St_ThemeColor_dark1:
+                return 0;
+        case NS_ooxml::LN_Value_St_ThemeColor_light1:
+                return 1;
+        case NS_ooxml::LN_Value_St_ThemeColor_dark2:
+                return 2;
+        case NS_ooxml::LN_Value_St_ThemeColor_light2:
+                return 3;
+        case NS_ooxml::LN_Value_St_ThemeColor_accent1:
+                return 4;
+        case NS_ooxml::LN_Value_St_ThemeColor_accent2:
+                return 5;
+        case NS_ooxml::LN_Value_St_ThemeColor_accent3:
+                return 6;
+        case NS_ooxml::LN_Value_St_ThemeColor_accent4:
+                return 7;
+        case NS_ooxml::LN_Value_St_ThemeColor_accent5:
+                return 8;
+        case NS_ooxml::LN_Value_St_ThemeColor_accent6:
+                return 9;
+        case NS_ooxml::LN_Value_St_ThemeColor_hyperlink:
+                return 10;
+        case NS_ooxml::LN_Value_St_ThemeColor_followedHyperlink:
+                return 11;
+        case NS_ooxml::LN_Value_St_ThemeColor_none:
+                return 12;
+        case NS_ooxml::LN_Value_St_ThemeColor_background1:
+                return 13;
+        case NS_ooxml::LN_Value_St_ThemeColor_text1:
+                return 14;
+        case NS_ooxml::LN_Value_St_ThemeColor_background2:
+                return 15;
+        case NS_ooxml::LN_Value_St_ThemeColor_text2:
+                return 16;
+        default:
+                break;
+    }
+    return -1;
+}
+
 void TDefTableHandler::lcl_attribute(Id rName, Value & rVal)
 {
     sal_Int32 nIntValue = rVal.getInt();
diff --git a/writerfilter/source/dmapper/TDefTableHandler.hxx b/writerfilter/source/dmapper/TDefTableHandler.hxx
index 17e6f2ed4fab..f9ae47eb5390 100644
--- a/writerfilter/source/dmapper/TDefTableHandler.hxx
+++ b/writerfilter/source/dmapper/TDefTableHandler.hxx
@@ -66,6 +66,7 @@ public:
     css::beans::PropertyValue getInteropGrabBag(const OUString& aName = OUString());
     static OUString getBorderTypeString(sal_Int32 nType);
     static OUString getThemeColorTypeString(sal_Int32 nType);
+    static sal_Int16 getThemeColorTypeIndex(sal_Int32 nType);
 };
 }
 
commit e83ce819b32e38f9a5a8dfb33c371eb86fc62339
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Sep 20 19:20:59 2015 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Jun 17 13:15:16 2021 +0900

    Theme color and tint/shade attribute for SvxColorItem
    
    To support theme colors the SvxColorItem must be extended with
    an optional attribute theme index to define the index to which
    theme color current color belongs and an optional tint/shade
    attribute define how much the color ha been additionally tinted
    or shaded.
    
    Change-Id: I87b7788ead25f956eeec835ba80df5e913790697

diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx
index 53f5328890b2..ac87db3a2573 100644
--- a/editeng/source/items/textitem.cxx
+++ b/editeng/source/items/textitem.cxx
@@ -1311,14 +1311,18 @@ bool SvxContourItem::GetPresentation
 
 // class SvxColorItem ----------------------------------------------------
 SvxColorItem::SvxColorItem( const sal_uInt16 nId ) :
-    SfxPoolItem( nId ),
-    mColor( COL_BLACK )
+    SfxPoolItem(nId),
+    mColor( COL_BLACK ),
+    maThemeIndex(-1),
+    maTintShade(0)
 {
 }
 
 SvxColorItem::SvxColorItem( const Color& rCol, const sal_uInt16 nId ) :
     SfxPoolItem( nId ),
-    mColor( rCol )
+    mColor( rCol ),
+    maThemeIndex(-1),
+    maTintShade(0)
 {
 }
 
@@ -1329,8 +1333,11 @@ SvxColorItem::~SvxColorItem()
 bool SvxColorItem::operator==( const SfxPoolItem& rAttr ) const
 {
     assert(SfxPoolItem::operator==(rAttr));
+    const SvxColorItem& rColorItem = static_cast<const SvxColorItem&>(rAttr);
 
-    return  mColor == static_cast<const SvxColorItem&>( rAttr ).mColor;
+    return mColor == rColorItem.mColor &&
+           maThemeIndex == rColorItem.maThemeIndex &&
+           maTintShade == rColorItem.maTintShade;
 }
 
 bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
@@ -1349,6 +1356,16 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
             rVal <<= mColor.GetAlpha() == 0;
             break;
         }
+        case MID_COLOR_THEME_INDEX:
+        {
+            rVal <<= maThemeIndex;
+            break;
+        }
+        case MID_COLOR_TINT_OR_SHADE:
+        {
+            rVal <<= maTintShade;
+            break;
+        }
         default:
         {
             rVal <<= mColor;
@@ -1379,11 +1396,29 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
             mColor.SetAlpha( Any2Bool( rVal ) ? 0 : 255 );
             return true;
         }
+        case MID_COLOR_THEME_INDEX:
+        {
+            sal_Int16 nIndex = -1;
+            if (!(rVal >>= nIndex))
+                return false;
+            maThemeIndex = nIndex;
+        }
+        break;
+        case MID_COLOR_TINT_OR_SHADE:
+        {
+            sal_Int16 nTintShade = -1;
+            if (!(rVal >>= nTintShade))
+                return false;
+            maTintShade = nTintShade;
+        }
+        break;
         default:
         {
             return rVal >>= mColor;
         }
+        break;
     }
+    return true;
 }
 
 SvxColorItem* SvxColorItem::Clone( SfxItemPool * ) const
diff --git a/include/editeng/colritem.hxx b/include/editeng/colritem.hxx
index 630648adea19..cdd697a2a467 100644
--- a/include/editeng/colritem.hxx
+++ b/include/editeng/colritem.hxx
@@ -31,6 +31,8 @@ class EDITENG_DLLPUBLIC SvxColorItem : public SfxPoolItem
 {
 private:
     Color mColor;
+    sal_Int16 maThemeIndex;
+    sal_Int16 maTintShade;
 
 public:
     static SfxPoolItem* CreateDefault();
@@ -57,6 +59,26 @@ public:
     }
     void SetValue(const Color& rNewColor);
 
+    sal_Int16 GetThemeIndex() const
+    {
+        return maThemeIndex;
+    }
+
+    void SetThemeIndex(sal_Int16 nIndex)
+    {
+        maThemeIndex = nIndex;
+    }
+
+    sal_Int16 GetTintOrShade() const
+    {
+        return maTintShade;
+    }
+
+    void SetTintOrShade(sal_Int16 nTintOrShade)
+    {
+        maTintShade = nTintOrShade;
+    }
+
     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 };
 
diff --git a/include/editeng/memberids.h b/include/editeng/memberids.h
index 8a6c9d0e7769..c6d781da568a 100644
--- a/include/editeng/memberids.h
+++ b/include/editeng/memberids.h
@@ -178,8 +178,12 @@
 #define MID_SHADOW_TRANSPARENCE 1
 
 // SvxColorItem
-#define MID_COLOR_RGB 0
-#define MID_COLOR_ALPHA 1
+#define MID_COLOR_RGB           0
+#define MID_COLOR_ALPHA         1
+//#define MID_GRAPHIC_TRANSPARENT 3 // used, but already defined above
+#define MID_COLOR_THEME_INDEX   4
+#define MID_COLOR_TINT_OR_SHADE 5
+
 
 #endif
 
diff --git a/offapi/com/sun/star/style/CharacterProperties.idl b/offapi/com/sun/star/style/CharacterProperties.idl
index 2f8a87448a33..b9fb1e7a1ca9 100644
--- a/offapi/com/sun/star/style/CharacterProperties.idl
+++ b/offapi/com/sun/star/style/CharacterProperties.idl
@@ -468,6 +468,18 @@ published service CharacterProperties
     */
     [optional, property] short CharTransparence;
 
+    /** If available, keeps the color theme index, so that the character can
+     *  be re-colored easily based on a theme.
+     *
+     *  @since LibreOffice 7.2
+     **/
+    [optional, property] short CharColorTheme;
+
+    /** Tint or shade of the character color.
+     *
+     *  @since LibreOffice 7.2
+     **/
+    [optional, property] short CharColorTintOrShade;
 };
 
 }; }; }; };
diff --git a/svx/sdi/svxitems.sdi b/svx/sdi/svxitems.sdi
index 549ffc3f3227..321d84019568 100644
--- a/svx/sdi/svxitems.sdi
+++ b/svx/sdi/svxitems.sdi
@@ -164,12 +164,19 @@ enum SvxShadowLocation
 };
 item SvxShadowLocation      SvxShadowLocationItem;
 
+struct SvxColor
+{
+    INT32 ColorValue       MID_COLOR_RGB;
+    INT16 ThemeIndex       MID_COLOR_THEME_INDEX;
+    INT16 ThemeTintOrShade MID_COLOR_TINT_OR_SHADE;
+};
+item SvxColor SvxColorItem;
+
 item INT16                  SvxCharScaleWidthItem;
 item INT16                  SvxParaVertAlignItem;
 item INT16                  SvxCharReliefItem;
 item BOOL                   SvxBlinkItem;
 item BOOL                   SvxAutoKernItem;
-item INT32                  SvxColorItem;
 item BOOL                   SvxContourItem;
 item INT16                  SvxFormatBreakItem;  // enum
 item BOOL                   SvxFormatKeepItem;


More information about the Libreoffice-commits mailing list