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 <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/util/Color.hpp>
24 
25 #include <osl/diagnose.h>
27 #include <oox/token/tokens.hxx>
28 #include <comphelper/sequence.hxx>
29 
30 using namespace com::sun::star;
31 
32 namespace oox::drawingml {
33 
34 bool ClrMap::getColorMap( sal_Int32& nClrToken )
35 {
36  sal_Int32 nMapped = 0;
37  std::map < sal_Int32, sal_Int32 >::const_iterator aIter( maClrMap.find( nClrToken ) );
38  if ( aIter != maClrMap.end() )
39  nMapped = (*aIter).second;
40  if ( nMapped )
41  {
42  nClrToken = nMapped;
43  return true;
44  }
45  else
46  return false;
47 }
48 
49 void ClrMap::setColorMap( sal_Int32 nClrToken, sal_Int32 nMappedClrToken )
50 {
51  maClrMap[ nClrToken ] = nMappedClrToken;
52 }
53 
54 namespace {
55 
56 struct find_by_token
57 {
58  explicit find_by_token(sal_Int32 token):
59  m_token(token)
60  {
61  }
62 
63  bool operator()(const std::pair<sal_Int32, ::Color>& r)
64  {
65  return r.first == m_token;
66  }
67 
68 private:
69  sal_Int32 m_token;
70 };
71 
72 }
73 
74 bool ClrScheme::getColor( sal_Int32 nSchemeClrToken, ::Color& rColor ) const
75 {
76  OSL_ASSERT((nSchemeClrToken & sal_Int32(0xFFFF0000))==0);
77  switch( nSchemeClrToken )
78  {
79  case XML_bg1 : nSchemeClrToken = XML_lt1; break;
80  case XML_bg2 : nSchemeClrToken = XML_lt2; break;
81  case XML_tx1 : nSchemeClrToken = XML_dk1; break;
82  case XML_tx2 : nSchemeClrToken = XML_dk2; break;
83  }
84 
85  auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
86 
87  if ( aIter != maClrScheme.end() )
88  rColor = aIter->second;
89 
90  return aIter != maClrScheme.end();
91 }
92 
93 void ClrScheme::setColor( sal_Int32 nSchemeClrToken, ::Color nColor )
94 {
95  const auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
96  if ( aIter != maClrScheme.end() )
97  aIter->second = nColor;
98  else
99  maClrScheme.emplace_back(nSchemeClrToken, nColor);
100 }
101 
102 bool ClrScheme::getColorByIndex(size_t nIndex, ::Color& rColor) const
103 {
104  if (nIndex >= maClrScheme.size())
105  return false;
106 
107  rColor = maClrScheme[nIndex].second;
108  return true;
109 }
110 
111 void ClrScheme::ToAny(css::uno::Any& rVal) const
112 {
113  std::vector<util::Color> aRet;
114 
115  for (const auto& rIndexAndColor : maClrScheme)
116  {
117  aRet.push_back(static_cast<sal_Int32>(rIndexAndColor.second));
118  }
119 
120  rVal <<= comphelper::containerToSequence(aRet);
121 }
122 
123 }
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_token
Definition: clrscheme.cxx:69
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()