[Libreoffice-commits] core.git: include/tools include/xmloff writerfilter/source xmloff/source

Noel Grandin noel.grandin at collabora.co.uk
Tue Feb 20 11:56:12 UTC 2018


 include/tools/color.hxx                         |   43 +++++++++++++++++++++---
 include/xmloff/xmlnumfi.hxx                     |    2 -
 writerfilter/source/rtftok/rtfdispatchvalue.cxx |   16 +++++---
 writerfilter/source/rtftok/rtfdocumentimpl.cxx  |    2 -
 writerfilter/source/rtftok/rtfdocumentimpl.hxx  |    8 ++--
 xmloff/source/style/xmlnumfi.cxx                |    4 +-
 6 files changed, 55 insertions(+), 20 deletions(-)

New commits:
commit 7ca8a6c8b17ffb4727af2df295b82d33227bdcde
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Feb 20 10:55:31 2018 +0200

    create uno::Any overrides for Color
    
    And use less ColorData in writerfilter and xmloff.
    
    part of removing ColorData.
    
    Change-Id: Ia1c57bf837ae814e7642cf1c7de2eb7ada7a1500
    Reviewed-on: https://gerrit.libreoffice.org/50028
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/tools/color.hxx b/include/tools/color.hxx
index 1006f7a4dc45..cb88d61a6c70 100644
--- a/include/tools/color.hxx
+++ b/include/tools/color.hxx
@@ -21,10 +21,11 @@
 
 #include <tools/toolsdllapi.h>
 #include <tools/colordata.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <basegfx/color/bcolor.hxx>
 
 class SvStream;
 
-#include <basegfx/color/bcolor.hxx>
 
 // Color
 
@@ -33,16 +34,16 @@ class SAL_WARN_UNUSED TOOLS_DLLPUBLIC Color final
     ColorData mnColor;
 
 public:
-    Color()
+    constexpr Color()
         : mnColor(COL_BLACK)
     {}
-    Color(ColorData nColor)
+    constexpr Color(ColorData nColor)
         : mnColor(nColor)
     {}
-    Color(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
+    constexpr Color(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
         : mnColor(RGB_COLORDATA(nRed, nGreen, nBlue))
     {}
-    Color(sal_uInt8 nTransparency, sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
+    constexpr Color(sal_uInt8 nTransparency, sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
         : mnColor(TRGB_COLORDATA(nTransparency, nRed, nGreen, nBlue))
     {}
 
@@ -53,6 +54,17 @@ public:
                                 sal_uInt8((rBColor.getBlue() * 255.0) + 0.5)))
     {}
 
+    /** Primarily used when passing Color objects to UNO API */
+    constexpr explicit operator sal_uInt32() const
+    {
+        return mnColor;
+    }
+
+    constexpr explicit operator sal_Int32() const
+    {
+        return sal_Int32(sal_uInt32());
+    }
+
     bool operator<(const Color& b) const
     {
         return mnColor < b.GetColor();
@@ -193,6 +205,27 @@ inline void Color::Merge( const Color& rMergeColor, sal_uInt8 cTransparency )
     SetBlue(ColorChannelMerge(COLORDATA_BLUE(mnColor), COLORDATA_BLUE(rMergeColor.mnColor), cTransparency));
 }
 
+// to reduce the noise when moving these into and out of Any
+inline bool operator >>=( const css::uno::Any & rAny, Color & value )
+{
+  sal_Int32 nTmp;
+  if (!(rAny >>= nTmp))
+      return false;
+  value = Color(nTmp);
+  return true;
+}
+inline void operator <<=( css::uno::Any & rAny, Color value )
+{
+    rAny <<= sal_Int32(value);
+}
+namespace com { namespace sun { namespace star { namespace uno {
+    template<>
+    inline Any makeAny( Color const & value )
+    {
+        return Any(sal_Int32(value));
+    }
+} } } }
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/xmloff/xmlnumfi.hxx b/include/xmloff/xmlnumfi.hxx
index d62866d9c4a6..39d058fbaeed 100644
--- a/include/xmloff/xmlnumfi.hxx
+++ b/include/xmloff/xmlnumfi.hxx
@@ -199,7 +199,7 @@ public:
     bool ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew );
     void AddCondition( const sal_Int32 nIndex );
     void AddCondition( const OUString& rCondition, const OUString& rApplyName );
-    void AddColor( sal_uInt32 const nColor );
+    void AddColor( Color nColor );
 
     /// determine whether number format uses the system language
     bool IsSystemLanguage();
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index 259b896cdcc3..2ea3c547b10e 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -417,7 +417,7 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
         case RTF_CF:
         {
             RTFSprms aAttributes;
-            auto pValue = std::make_shared<RTFValue>(getColorTable(nParam));
+            auto pValue = std::make_shared<RTFValue>(sal_uInt32(getColorTable(nParam)));
             aAttributes.set(NS_ooxml::LN_CT_Color_val, pValue);
             m_aStates.top().aCharacterSprms.set(NS_ooxml::LN_EG_RPrBase_color,
                                                 std::make_shared<RTFValue>(aAttributes));
@@ -505,7 +505,8 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
         break;
         case RTF_CHCBPAT:
         {
-            auto pValue = std::make_shared<RTFValue>(nParam ? getColorTable(nParam) : COL_AUTO);
+            auto pValue
+                = std::make_shared<RTFValue>(nParam ? sal_uInt32(getColorTable(nParam)) : COL_AUTO);
             putNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_shd,
                                NS_ooxml::LN_CT_Shd_fill, pValue);
         }
@@ -513,7 +514,7 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
         case RTF_CLCBPAT:
         case RTF_CLCBPATRAW:
         {
-            auto pValue = std::make_shared<RTFValue>(getColorTable(nParam));
+            auto pValue = std::make_shared<RTFValue>(sal_uInt32(getColorTable(nParam)));
             putNestedAttribute(m_aStates.top().aTableCellSprms, NS_ooxml::LN_CT_TcPrBase_shd,
                                NS_ooxml::LN_CT_Shd_fill, pValue);
         }
@@ -521,20 +522,21 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
         case RTF_CBPAT:
             if (nParam)
             {
-                auto pValue = std::make_shared<RTFValue>(getColorTable(nParam));
+                auto pValue = std::make_shared<RTFValue>(sal_uInt32(getColorTable(nParam)));
                 putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PrBase_shd,
                                    NS_ooxml::LN_CT_Shd_fill, pValue);
             }
             break;
         case RTF_ULC:
         {
-            auto pValue = std::make_shared<RTFValue>(getColorTable(nParam));
+            auto pValue = std::make_shared<RTFValue>(sal_uInt32(getColorTable(nParam)));
             m_aStates.top().aCharacterSprms.set(0x6877, pValue);
         }
         break;
         case RTF_HIGHLIGHT:
         {
-            auto pValue = std::make_shared<RTFValue>(nParam ? getColorTable(nParam) : COL_AUTO);
+            auto pValue
+                = std::make_shared<RTFValue>(nParam ? sal_uInt32(getColorTable(nParam)) : COL_AUTO);
             m_aStates.top().aCharacterSprms.set(NS_ooxml::LN_EG_RPrBase_highlight, pValue);
         }
         break;
@@ -626,7 +628,7 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
         break;
         case RTF_BRDRCF:
         {
-            auto pValue = std::make_shared<RTFValue>(getColorTable(nParam));
+            auto pValue = std::make_shared<RTFValue>(sal_uInt32(getColorTable(nParam)));
             putBorderProperty(m_aStates, NS_ooxml::LN_CT_Border_color, pValue);
         }
         break;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index d1f09ec42564..44b671de27bc 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -646,7 +646,7 @@ void RTFDocumentImpl::sectBreak(bool bFinal)
     m_bNeedSect = false;
 }
 
-sal_uInt32 RTFDocumentImpl::getColorTable(sal_uInt32 nIndex)
+Color RTFDocumentImpl::getColorTable(sal_uInt32 nIndex)
 {
     if (!m_pSuperstream)
     {
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 38fbad18a1c8..71e7657036f8 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -22,7 +22,7 @@
 #include <oox/mathml/importutils.hxx>
 #include <rtl/strbuf.hxx>
 #include <rtl/ustrbuf.hxx>
-#include <tools/colordata.hxx>
+#include <tools/color.hxx>
 
 #include <rtftok/RTFDocument.hxx>
 #include "rtfreferencetable.hxx"
@@ -143,7 +143,7 @@ public:
         m_bAuto = false;
         m_nB = nBlue;
     }
-    ColorData GetColor() const { return m_bAuto ? COL_AUTO : RGB_COLORDATA(m_nR, m_nG, m_nB); }
+    Color GetColor() const { return m_bAuto ? COL_AUTO : Color(m_nR, m_nG, m_nB); }
 
 private:
     bool m_bAuto = true;
@@ -472,7 +472,7 @@ public:
 
 private:
     SvStream& Strm();
-    sal_uInt32 getColorTable(sal_uInt32 nIndex);
+    Color getColorTable(sal_uInt32 nIndex);
     writerfilter::Reference<Properties>::Pointer_t createStyleProperties();
     void resetSprms();
     void resetAttributes();
@@ -539,7 +539,7 @@ private:
     /// Maps style indexes to style types.
     std::map<int, Id> m_aStyleTypes;
     /// Color index <-> RGB color value map
-    std::vector<sal_uInt32> m_aColorTable;
+    std::vector<Color> m_aColorTable;
     bool m_bFirstRun;
     /// If paragraph properties should be emitted on next run.
     bool m_bNeedPap;
diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index e918edcea82a..2e2905d6ffd0 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -283,7 +283,7 @@ enum SvXMLStyleElemAttrTokens
 
 #define XML_NUMF_COLORCOUNT     10
 
-static const ColorData aNumFmtStdColors[XML_NUMF_COLORCOUNT] =
+static const Color aNumFmtStdColors[XML_NUMF_COLORCOUNT] =
 {
     COL_BLACK,
     COL_LIGHTBLUE,
@@ -2216,7 +2216,7 @@ void SvXMLNumFormatContext::AddCondition( const OUString& rCondition, const OUSt
     aMyConditions.push_back(aCondition);
 }
 
-void SvXMLNumFormatContext::AddColor( sal_uInt32 const nColor )
+void SvXMLNumFormatContext::AddColor( Color const nColor )
 {
     SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
     if (!pFormatter)


More information about the Libreoffice-commits mailing list