LibreOffice Module oox (master)  1
clrscheme.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <algorithm>
21 
22 #include <osl/diagnose.h>
24 #include <oox/token/tokens.hxx>
25 
26 namespace oox::drawingml {
27 
28 bool ClrMap::getColorMap( sal_Int32& nClrToken )
29 {
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 )
35  {
36  nClrToken = nMapped;
37  return true;
38  }
39  else
40  return false;
41 }
42 
43 void ClrMap::setColorMap( sal_Int32 nClrToken, sal_Int32 nMappedClrToken )
44 {
45  maClrMap[ nClrToken ] = nMappedClrToken;
46 }
47 
48 namespace {
49 
50 struct find_by_token
51 {
52  explicit find_by_token(sal_Int32 token):
53  m_token(token)
54  {
55  }
56 
57  bool operator()(const std::pair<sal_Int32, ::Color>& r)
58  {
59  return r.first == m_token;
60  }
61 
62 private:
63  sal_Int32 m_token;
64 };
65 
66 }
67 
68 bool ClrScheme::getColor( sal_Int32 nSchemeClrToken, ::Color& rColor ) const
69 {
70  OSL_ASSERT((nSchemeClrToken & sal_Int32(0xFFFF0000))==0);
71  switch( nSchemeClrToken )
72  {
73  case XML_bg1 : nSchemeClrToken = XML_lt1; break;
74  case XML_bg2 : nSchemeClrToken = XML_lt2; break;
75  case XML_tx1 : nSchemeClrToken = XML_dk1; break;
76  case XML_tx2 : nSchemeClrToken = XML_dk2; break;
77  }
78 
79  auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
80 
81  if ( aIter != maClrScheme.end() )
82  rColor = aIter->second;
83 
84  return aIter != maClrScheme.end();
85 }
86 
87 void ClrScheme::setColor( sal_Int32 nSchemeClrToken, ::Color nColor )
88 {
89  const auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
90  if ( aIter != maClrScheme.end() )
91  aIter->second = nColor;
92  else
93  maClrScheme.emplace_back(nSchemeClrToken, nColor);
94 }
95 
96 bool ClrScheme::getColorByIndex(size_t nIndex, ::Color& rColor) const
97 {
98  if (nIndex >= maClrScheme.size())
99  return false;
100 
101  rColor = maClrScheme[nIndex].second;
102  return true;
103 }
104 
105 }
106 
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< std::pair< sal_Int32,::Color > > maClrScheme
Definition: clrscheme.hxx:82
void setColor(sal_Int32 nSchemeClrToken,::Color nColor)
Definition: clrscheme.cxx:87
sal_Int32 m_token
Definition: clrscheme.cxx:63
std::map< sal_Int32, sal_Int32 > maClrMap
Definition: clrscheme.hxx:70
bool getColor(sal_Int32 nSchemeClrToken,::Color &rColor) const
Definition: clrscheme.cxx:68
void setColorMap(sal_Int32 nClrToken, sal_Int32 nMappedClrToken)
Definition: clrscheme.cxx:43
bool getColorMap(sal_Int32 &nClrToken)
Definition: clrscheme.cxx:28
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
bool getColorByIndex(size_t nIndex,::Color &rColor) const
Definition: clrscheme.cxx:96