Kaydet (Commit) f3121049 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

use index as real index and not token, tdf#90511

At least in calc a theme index is a zero based index into the clrScheme.
A map is unsiutable for that task so let us use a vector and still allow
to get them by their tokens.

Change-Id: I09d56acaf22c3ed16387aae95c36382302c5a17e
üst b99a4b81
......@@ -42,12 +42,15 @@ typedef std::shared_ptr< ClrMap > ClrMapPtr;
class OOX_DLLPUBLIC ClrScheme
{
std::map < sal_Int32, sal_Int32 > maClrScheme;
std::vector< std::pair<sal_Int32, sal_Int32> > maClrScheme;
public:
bool getColor( sal_Int32 nSchemeClrToken, sal_Int32& rColor ) const;
void setColor( sal_Int32 nSchemeClrToken, sal_Int32 nColor );
bool getColorByIndex(size_t nIndex,
sal_Int32& rColor) const;
};
typedef std::shared_ptr< ClrScheme > ClrSchemePtr;
......
......@@ -43,6 +43,21 @@ void ClrMap::setColorMap( sal_Int32 nClrToken, sal_Int32 nMappedClrToken )
maClrMap[ nClrToken ] = nMappedClrToken;
}
struct find_by_token
{
find_by_token(sal_Int32 token):
m_token(token)
{
}
bool operator()(const std::pair<sal_Int32, sal_Int32>& r)
{
return r.first == m_token;
}
private:
sal_Int32 m_token;
};
bool ClrScheme::getColor( sal_Int32 nSchemeClrToken, sal_Int32& rColor ) const
{
......@@ -54,15 +69,27 @@ bool ClrScheme::getColor( sal_Int32 nSchemeClrToken, sal_Int32& rColor ) const
case XML_tx1 : nSchemeClrToken = XML_dk1; break;
case XML_tx2 : nSchemeClrToken = XML_dk2; break;
}
std::map < sal_Int32, sal_Int32 >::const_iterator aIter( maClrScheme.find( nSchemeClrToken ) );
auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
if ( aIter != maClrScheme.end() )
rColor = (*aIter).second;
rColor = aIter->second;
return aIter != maClrScheme.end();
}
void ClrScheme::setColor( sal_Int32 nSchemeClrToken, sal_Int32 nColor )
{
maClrScheme[ nSchemeClrToken ] = nColor;
maClrScheme.push_back(std::pair<sal_Int32, sal_Int32>(nSchemeClrToken, nColor));
}
bool ClrScheme::getColorByIndex(size_t nIndex, sal_Int32& rColor) const
{
if (nIndex >= maClrScheme.size())
return false;
rColor = maClrScheme[nIndex].second;
return true;
}
} }
......
......@@ -37,6 +37,8 @@ public:
/** Returns the theme color with the specified token identifier. */
sal_Int32 getColorByToken( sal_Int32 nToken ) const;
sal_Int32 getColorByIndex(size_t nIndex) const;
/** Returns the default font data for the current file type. */
inline const FontModel& getDefaultFontModel() const { return *mxDefFontModel; }
......
......@@ -245,7 +245,7 @@ void DataBarRule::importColor( const AttributeList& rAttribs )
else if( rAttribs.hasAttribute( XML_theme ) )
{
sal_uInt32 nThemeIndex = rAttribs.getUnsigned( XML_theme, 0 );
nColor = getTheme().getColorByToken( nThemeIndex );
nColor = getTheme().getColorByIndex( nThemeIndex );
}
::Color aColor = RgbToRgbComponents( nColor );
......
......@@ -56,6 +56,12 @@ sal_Int32 ThemeBuffer::getColorByToken( sal_Int32 nToken ) const
return getClrScheme().getColor( nToken, nColor ) ? nColor : API_RGB_TRANSPARENT;
}
sal_Int32 ThemeBuffer::getColorByIndex(size_t nIndex) const
{
sal_Int32 nColor = 0;
return getClrScheme().getColorByIndex(nIndex, nColor) ? nColor : API_RGB_TRANSPARENT;
}
} // namespace xls
} // namespace oox
......
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