diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-20 10:55:31 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-20 12:55:47 +0100 |
commit | 7ca8a6c8b17ffb4727af2df295b82d33227bdcde (patch) | |
tree | 1399af3b9cc051e587a0f4d71086626268601f43 /include/tools | |
parent | 7b8a0b7c0dcf8380a6bd2d458d0e20ffc6a5d355 (diff) |
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@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/tools')
-rw-r--r-- | include/tools/color.hxx | 43 |
1 files changed, 38 insertions, 5 deletions
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: */ |