Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / clrscheme.cxx
blob47d9426e064681ff2567076f97b1587abfd824b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <algorithm>
22 #include <osl/diagnose.h>
23 #include <oox/drawingml/clrscheme.hxx>
24 #include <oox/token/tokens.hxx>
26 namespace oox { namespace drawingml {
28 bool ClrMap::getColorMap( sal_Int32& nClrToken )
30 sal_Int32 nMapped = 0;
31 std::map < sal_Int32, sal_Int32 >::const_iterator aIter( maClrMap.find( nClrToken ) );
32 if ( aIter != maClrMap.end() )
33 nMapped = (*aIter).second;
34 if ( nMapped )
36 nClrToken = nMapped;
37 return true;
39 else
40 return false;
43 void ClrMap::setColorMap( sal_Int32 nClrToken, sal_Int32 nMappedClrToken )
45 maClrMap[ nClrToken ] = nMappedClrToken;
48 struct find_by_token
50 explicit find_by_token(sal_Int32 token):
51 m_token(token)
55 bool operator()(const std::pair<sal_Int32, ::Color>& r)
57 return r.first == m_token;
60 private:
61 sal_Int32 const m_token;
64 bool ClrScheme::getColor( sal_Int32 nSchemeClrToken, ::Color& rColor ) const
66 OSL_ASSERT((nSchemeClrToken & sal_Int32(0xFFFF0000))==0);
67 switch( nSchemeClrToken )
69 case XML_bg1 : nSchemeClrToken = XML_lt1; break;
70 case XML_bg2 : nSchemeClrToken = XML_lt2; break;
71 case XML_tx1 : nSchemeClrToken = XML_dk1; break;
72 case XML_tx2 : nSchemeClrToken = XML_dk2; break;
75 auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
77 if ( aIter != maClrScheme.end() )
78 rColor = aIter->second;
80 return aIter != maClrScheme.end();
83 void ClrScheme::setColor( sal_Int32 nSchemeClrToken, ::Color nColor )
85 const auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
86 if ( aIter != maClrScheme.end() )
87 aIter->second = nColor;
88 else
89 maClrScheme.emplace_back(nSchemeClrToken, nColor);
92 bool ClrScheme::getColorByIndex(size_t nIndex, ::Color& rColor) const
94 if (nIndex >= maClrScheme.size())
95 return false;
97 rColor = maClrScheme[nIndex].second;
98 return true;
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */