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>
29
30using namespace com::sun::star;
31
32namespace oox::drawingml {
33
34bool 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
49void ClrMap::setColorMap( sal_Int32 nClrToken, sal_Int32 nMappedClrToken )
50{
51 maClrMap[ nClrToken ] = nMappedClrToken;
52}
53
54namespace {
55
56struct 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
68private:
69 sal_Int32 m_token;
70};
71
72}
73
74bool 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
93void 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
102bool 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
111void 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: */
bool getColorMap(sal_Int32 &nClrToken)
Definition: clrscheme.cxx:34
void setColorMap(sal_Int32 nClrToken, sal_Int32 nMappedClrToken)
Definition: clrscheme.cxx:49
std::map< sal_Int32, sal_Int32 > maClrMap
Definition: clrscheme.hxx:70
bool getColor(sal_Int32 nSchemeClrToken, ::Color &rColor) const
Definition: clrscheme.cxx:74
void ToAny(css::uno::Any &rVal) const
Definition: clrscheme.cxx:111
bool getColorByIndex(size_t nIndex, ::Color &rColor) const
Definition: clrscheme.cxx:102
void setColor(sal_Int32 nSchemeClrToken, ::Color nColor)
Definition: clrscheme.cxx:93
std::vector< std::pair< sal_Int32, ::Color > > maClrScheme
Definition: clrscheme.hxx:82
sal_Int32 m_token
Definition: clrscheme.cxx:69
sal_Int32 nIndex
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)