Kaydet (Commit) 7ca8a6c8 authored tarafından Noel Grandin's avatar Noel Grandin

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/50028Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
Tested-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 7b8a0b7c
......@@ -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: */
......@@ -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();
......
......@@ -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;
......
......@@ -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)
{
......
......@@ -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;
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment