include/svx/ColorSets.hxx                |   48 ++++++++++++++++++-------------
 oox/inc/drawingml/textfont.hxx           |   10 +++---
 oox/source/drawingml/textfont.cxx        |   20 ++++++++----
 sd/source/filter/eppt/pptx-epptooxml.cxx |    3 +
 sd/source/ui/func/fuconstr.cxx           |    2 -
 svx/source/styles/ColorSets.cxx          |   31 +++++++++-----------
 sw/source/uibase/sidebar/ThemePanel.cxx  |    7 ++--
 7 files changed, 69 insertions(+), 52 deletions(-)

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

    svx: rename mnPitch to mnPitchFamily, add resolvePitchFamily
    
    Rename mnPitch to mnPitchFamily as it contains both. Extract the
    code to resolve what is pitch and what is family into its own
    (static) function.
    
    Change-Id: I0c17351ea690a85decefb8d73dd07644ce5c78d5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143991
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 4ee7e71d850315f5ae4c3b763b0e80e8d83a6454)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145836
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/oox/inc/drawingml/textfont.hxx b/oox/inc/drawingml/textfont.hxx
index 6bdf13ab890a..231b18cffecb 100644
--- a/oox/inc/drawingml/textfont.hxx
+++ b/oox/inc/drawingml/textfont.hxx
@@ -51,6 +51,8 @@ public:
                             sal_Int16& rnFontFamily,
                             const ::oox::core::XmlFilterBase& rFilter ) const;
 
+    static void resolvePitch(sal_Int32 nOoxPitch, sal_Int16& rnFontPitch, 
sal_Int16& rnFontFamily);
+
 private:
     bool                implGetFontData(
                             OUString& rFontName,
@@ -58,10 +60,10 @@ private:
                             sal_Int16& rnFontFamily ) const;
 
 private:
-    OUString     maTypeface;
-    OUString     maPanose;
-    sal_Int32           mnPitch;
-    sal_Int32           mnCharset;
+    OUString maTypeface;
+    OUString maPanose;
+    sal_Int32 mnPitchFamily;
+    sal_Int32 mnCharset;
 };
 
 
diff --git a/oox/source/drawingml/textfont.cxx 
b/oox/source/drawingml/textfont.cxx
index bcfe516893ee..e5899780ad2c 100644
--- a/oox/source/drawingml/textfont.cxx
+++ b/oox/source/drawingml/textfont.cxx
@@ -48,7 +48,7 @@ sal_Int16 lclGetFontFamily( sal_Int32 nOoxValue )
 } // namespace
 
 TextFont::TextFont() :
-    mnPitch( 0 ),
+    mnPitchFamily(0),
     mnCharset( WINDOWS_CHARSET_ANSI )
 {
 }
@@ -56,16 +56,16 @@ TextFont::TextFont() :
 void TextFont::setAttributes( const AttributeList& rAttribs )
 {
     maTypeface = rAttribs.getStringDefaulted( XML_typeface);
-    maPanose   = rAttribs.getStringDefaulted( XML_panose);
-    mnPitch    = rAttribs.getInteger( XML_pitchFamily, 0 );
-    mnCharset  = rAttribs.getInteger( XML_charset, WINDOWS_CHARSET_DEFAULT );
+    maPanose = rAttribs.getStringDefaulted( XML_panose);
+    mnPitchFamily = rAttribs.getInteger( XML_pitchFamily, 0 );
+    mnCharset = rAttribs.getInteger( XML_charset, WINDOWS_CHARSET_DEFAULT );
 }
 
 void TextFont::setAttributes( const OUString& sFontName )
 {
     maTypeface = sFontName;
     maPanose.clear();
-    mnPitch = 0;
+    mnPitchFamily = 0;
     mnCharset = WINDOWS_CHARSET_DEFAULT;
 }
 
@@ -86,11 +86,17 @@ bool TextFont::getFontData( OUString& rFontName, sal_Int16& 
rnFontPitch, sal_Int
 bool TextFont::implGetFontData( OUString& rFontName, sal_Int16& rnFontPitch, 
sal_Int16& rnFontFamily ) const
 {
     rFontName = maTypeface;
-    rnFontPitch = lclGetFontPitch( extractValue< sal_Int16 >( mnPitch, 0, 4 ) 
);
-    rnFontFamily = lclGetFontFamily( extractValue< sal_Int16 >( mnPitch, 4, 4 
) );
+    resolvePitch(mnPitchFamily, rnFontPitch, rnFontFamily);
     return !rFontName.isEmpty();
 }
 
+void TextFont::resolvePitch(sal_Int32 nOoxPitchFamily, sal_Int16& rnFontPitch, 
sal_Int16& rnFontFamily)
+{
+    rnFontPitch = lclGetFontPitch(extractValue<sal_Int16>(nOoxPitchFamily, 0, 
4));
+    rnFontFamily = lclGetFontFamily(extractValue<sal_Int16>(nOoxPitchFamily, 
4, 4));
+}
+
+
 } // namespace oox::drawingml
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 6ff08e13e6eed09a9b51413910947ac4d75bc620
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Dec 12 20:17:09 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jan 20 07:11:27 2023 +0000

    svx: rename ThemeColorType enum values, use enum instead of index
    
    Change-Id: I81c1553205365c4076562474078b3b0aa834b249
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143990
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 1386e26b2d7fc5173266ffbfb94bc82b1d3f7bb9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145835
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx
index 91ac4e1651c7..71f12c2dbe71 100644
--- a/include/svx/ColorSets.hxx
+++ b/include/svx/ColorSets.hxx
@@ -24,6 +24,32 @@ class SdrPage;
 namespace svx
 {
 
+/// Offsets into the color list of a theme.
+enum class ThemeColorType : sal_Int32
+{
+    Unknown = -1,
+    Dark1 = 0,
+    Light1 = 1,
+    Dark2 = 2,
+    Light2 = 3,
+    Accent1 = 4,
+    Accent2 = 5,
+    Accent3 = 6,
+    Accent4 = 7,
+    Accent5 = 8,
+    Accent6 = 9,
+    Hyperlink = 10,
+    FollowedHyperlink = 11,
+    LAST = FollowedHyperlink
+};
+
+constexpr ThemeColorType convertToThemeColorType(sal_Int32 nIndex)
+{
+    if (nIndex < 0 || nIndex > 11)
+        return ThemeColorType::Unknown;
+    return static_cast<ThemeColorType>(nIndex);
+}
+
 class ColorSet
 {
     OUString maColorSetName;
@@ -40,9 +66,10 @@ public:
     {
         return maColorSetName;
     }
-    const Color& getColor(sal_uInt32 nIndex) const
+
+    Color getColor(ThemeColorType nType) const
     {
-        return maColors[nIndex];
+        return maColors[size_t(nType)];
     }
 
     void dumpAsXml(xmlTextWriterPtr pWriter) const;
@@ -69,23 +96,6 @@ public:
     const ColorSet& getColorSet(std::u16string_view rName);
 };
 
-/// Offsets into the color list of a theme.
-enum class ThemeColorType
-{
-    DK1 = 0,
-    LT1 = 1,
-    DK2 = 2,
-    LT2 = 3,
-    ACCENT1 = 4,
-    ACCENT2 = 5,
-    ACCENT3 = 6,
-    ACCENT4 = 7,
-    ACCENT5 = 8,
-    ACCENT6 = 9,
-    HLINK = 10,
-    FOLHLINK = 11,
-};
-
 /// A named theme has a named color set.
 class SVXCORE_DLLPUBLIC Theme
 {
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx 
b/sd/source/filter/eppt/pptx-epptooxml.cxx
index 05ec471f610f..d0d602cb4299 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -2186,7 +2186,8 @@ bool PowerPointExport::WriteColorSets(const FSHelperPtr& 
pFS, svx::Theme* pTheme
     {
         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(nId))));
+        svx::ThemeColorType eType = svx::convertToThemeColorType(nId);
+        pFS->singleElementNS(XML_a, XML_srgbClr, XML_val, 
I32SHEX(static_cast<sal_Int32>(pColorSet->getColor(eType))));
         pFS->endElementNS(XML_a, nToken);
     }
 
diff --git a/sd/source/ui/func/fuconstr.cxx b/sd/source/ui/func/fuconstr.cxx
index 9d6f363209f2..dd086641cdbf 100644
--- a/sd/source/ui/func/fuconstr.cxx
+++ b/sd/source/ui/func/fuconstr.cxx
@@ -389,7 +389,7 @@ void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, 
SdrObject* pObj,
 
                 aAttr.Put(XFillStyleItem(css::drawing::FillStyle_SOLID));
 
-                svx::ThemeColorType eColorType = svx::ThemeColorType::ACCENT1;
+                svx::ThemeColorType eColorType = svx::ThemeColorType::Accent1;
                 Color aColor = pTheme->GetColor(eColorType);
                 XFillColorItem aFillColorItem("", aColor);
                 
aFillColorItem.GetThemeColor().SetThemeIndex(static_cast<sal_Int16>(eColorType));
diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx
index 0dde00e219c0..6af2ee6313bc 100644
--- a/svx/source/styles/ColorSets.cxx
+++ b/svx/source/styles/ColorSets.cxx
@@ -26,6 +26,7 @@
 #include <svx/svdpage.hxx>
 #include <svx/svditer.hxx>
 #include <editeng/unoprnms.hxx>
+#include <o3tl/enumrange.hxx>
 #include <utility>
 
 using namespace com::sun::star;
@@ -38,12 +39,12 @@ void UpdateTextPortionColorSet(const 
uno::Reference<beans::XPropertySet>& xPorti
 {
     sal_Int16 nCharColorTheme = -1;
     xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME) >>= 
nCharColorTheme;
-    if (nCharColorTheme < 0 || nCharColorTheme > 11)
-    {
+    svx::ThemeColorType eColorThemeType = 
svx::convertToThemeColorType(nCharColorTheme);
+
+    if (eColorThemeType == svx::ThemeColorType::Unknown)
         return;
-    }
 
-    Color aColor = rColorSet.getColor(nCharColorTheme);
+    Color aColor = rColorSet.getColor(eColorThemeType);
     sal_Int32 nCharColorLumMod{};
     xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_LUM_MOD) >>= 
nCharColorLumMod;
     sal_Int32 nCharColorLumOff{};
@@ -73,12 +74,11 @@ void UpdateFillColorSet(const 
uno::Reference<beans::XPropertySet>& xShape, const
 
     sal_Int16 nFillColorTheme = -1;
     xShape->getPropertyValue(UNO_NAME_FILLCOLOR_THEME) >>= nFillColorTheme;
-    if (nFillColorTheme < 0 || nFillColorTheme > 11)
-    {
+    svx::ThemeColorType eColorThemeType = 
svx::convertToThemeColorType(nFillColorTheme);
+    if (eColorThemeType == svx::ThemeColorType::Unknown)
         return;
-    }
 
-    Color aColor = rColorSet.getColor(nFillColorTheme);
+    Color aColor = rColorSet.getColor(eColorThemeType);
     sal_Int32 nFillColorLumMod{};
     xShape->getPropertyValue(UNO_NAME_FILLCOLOR_LUM_MOD) >>= nFillColorLumMod;
     sal_Int32 nFillColorLumOff{};
@@ -272,9 +272,10 @@ void Theme::ToAny(css::uno::Any& rVal) const
     if (mpColorSet)
     {
         std::vector<util::Color> aColorScheme;
-        for (size_t i = 0; i < 12; ++i)
+        for (auto eThemeColorType : o3tl::enumrange<svx::ThemeColorType>())
         {
-            
aColorScheme.push_back(static_cast<sal_Int32>(mpColorSet->getColor(i)));
+            Color aColor = mpColorSet->getColor(eThemeColorType);
+            aColorScheme.push_back(sal_Int32(aColor));
         }
 
         aMap["ColorSchemeName"] <<= mpColorSet->getName();
@@ -349,14 +350,12 @@ void Theme::UpdateSdrPage(const SdrPage* pPage)
 std::vector<Color> Theme::GetColors() const
 {
     if (!mpColorSet)
-    {
         return {};
-    }
 
     std::vector<Color> aColors;
-    for (size_t i = 0; i < 12; ++i)
+    for (auto eThemeColorType : o3tl::enumrange<svx::ThemeColorType>())
     {
-        aColors.push_back(mpColorSet->getColor(i));
+        aColors.push_back(mpColorSet->getColor(eThemeColorType));
     }
     return aColors;
 }
@@ -364,11 +363,9 @@ std::vector<Color> Theme::GetColors() const
 Color Theme::GetColor(ThemeColorType eType) const
 {
     if (!mpColorSet)
-    {
         return {};
-    }
 
-    return mpColorSet->getColor(static_cast<size_t>(eType));
+    return mpColorSet->getColor(eType);
 }
 
 } // end of namespace svx
diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx 
b/sw/source/uibase/sidebar/ThemePanel.cxx
index d392382e1e31..9be8649def38 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -29,6 +29,7 @@
 #include <docstyle.hxx>
 #include <fmtcol.hxx>
 #include <format.hxx>
+#include <svx/ColorSets.hxx>
 
 namespace
 {
@@ -220,7 +221,7 @@ void changeColor(SwTextFormatColl* pCollection, 
svx::ColorSet const& rColorSet,
     auto nThemeIndex = aColorItem.GetThemeColor().GetThemeIndex();
     if (nThemeIndex >= 0)
     {
-        Color aColor = rColorSet.getColor(nThemeIndex);
+        Color aColor = 
rColorSet.getColor(svx::convertToThemeColorType(nThemeIndex));
         aColor.ApplyTintOrShade(aColorItem.GetThemeColor().GetTintOrShade());
         aColorItem.SetValue(aColor);
         pCollection->SetFormatAttr(aColorItem);
@@ -393,10 +394,10 @@ BitmapEx GenerateColorPreview(const svx::ColorSet& 
rColorSet)
 
     for (sal_uInt32 i = 0; i < 12; i += 2)
     {
-        pVirtualDev->SetFillColor(rColorSet.getColor(i));
+        
pVirtualDev->SetFillColor(rColorSet.getColor(svx::convertToThemeColorType(i)));
         pVirtualDev->DrawRect(tools::Rectangle(x, y1, x + SIZE, y1 + SIZE));
 
-        pVirtualDev->SetFillColor(rColorSet.getColor(i + 1));
+        
pVirtualDev->SetFillColor(rColorSet.getColor(svx::convertToThemeColorType(i + 
1)));
         pVirtualDev->DrawRect(tools::Rectangle(x, y2, x + SIZE, y2 + SIZE));
 
         x += SIZE + BORDER;

Reply via email to