1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/util/Color.hpp>
25 #include <osl/diagnose.h>
26 #include <oox/drawingml/clrscheme.hxx>
27 #include <oox/token/tokens.hxx>
28 #include <comphelper/sequence.hxx>
30 #include <frozen/bits/defines.h>
31 #include <frozen/bits/elsa_std.h>
32 #include <frozen/unordered_map.h>
34 using namespace com::sun::star
;
36 namespace oox::drawingml
{
41 constexpr frozen::unordered_map
<PredefinedClrSchemeId
, std::u16string_view
, 12> constPredefinedClrNames
47 { accent1
, u
"accent1" },
48 { accent2
, u
"accent2" },
49 { accent3
, u
"accent3" },
50 { accent4
, u
"accent4" },
51 { accent5
, u
"accent5" },
52 { accent6
, u
"accent6" },
54 { folHlink
, u
"folHlink" }
57 } // end anonymous namespace
59 std::u16string_view
getPredefinedClrNames(PredefinedClrSchemeId eID
)
61 std::u16string_view empty
;
62 auto iterator
= constPredefinedClrNames
.find(eID
);
63 if (iterator
== constPredefinedClrNames
.end())
65 return iterator
->second
;
68 bool ClrMap::getColorMap( sal_Int32
& nClrToken
)
70 sal_Int32 nMapped
= 0;
71 std::map
< sal_Int32
, sal_Int32
>::const_iterator
aIter( maClrMap
.find( nClrToken
) );
72 if ( aIter
!= maClrMap
.end() )
73 nMapped
= (*aIter
).second
;
83 void ClrMap::setColorMap( sal_Int32 nClrToken
, sal_Int32 nMappedClrToken
)
85 maClrMap
[ nClrToken
] = nMappedClrToken
;
92 explicit find_by_token(sal_Int32 token
):
97 bool operator()(const std::pair
<sal_Int32
, ::Color
>& r
)
99 return r
.first
== m_token
;
108 bool ClrScheme::getColor( sal_Int32 nSchemeClrToken
, ::Color
& rColor
) const
110 OSL_ASSERT((nSchemeClrToken
& sal_Int32(0xFFFF0000))==0);
111 switch( nSchemeClrToken
)
113 case XML_bg1
: nSchemeClrToken
= XML_lt1
; break;
114 case XML_bg2
: nSchemeClrToken
= XML_lt2
; break;
115 case XML_tx1
: nSchemeClrToken
= XML_dk1
; break;
116 case XML_tx2
: nSchemeClrToken
= XML_dk2
; break;
117 case XML_background1
: nSchemeClrToken
= XML_lt1
; break;
118 case XML_background2
: nSchemeClrToken
= XML_lt2
; break;
119 case XML_text1
: nSchemeClrToken
= XML_dk1
; break;
120 case XML_text2
: nSchemeClrToken
= XML_dk2
; break;
121 case XML_light1
: nSchemeClrToken
= XML_lt1
; break;
122 case XML_light2
: nSchemeClrToken
= XML_lt2
; break;
123 case XML_dark1
: nSchemeClrToken
= XML_dk1
; break;
124 case XML_dark2
: nSchemeClrToken
= XML_dk2
; break;
125 case XML_hyperlink
: nSchemeClrToken
= XML_hlink
; break;
126 case XML_followedHyperlink
: nSchemeClrToken
= XML_folHlink
; break;
129 auto aIter
= std::find_if(maClrScheme
.begin(), maClrScheme
.end(), find_by_token(nSchemeClrToken
) );
131 if ( aIter
!= maClrScheme
.end() )
132 rColor
= aIter
->second
;
134 return aIter
!= maClrScheme
.end();
137 void ClrScheme::setColor( sal_Int32 nSchemeClrToken
, ::Color nColor
)
139 const auto aIter
= std::find_if(maClrScheme
.begin(), maClrScheme
.end(), find_by_token(nSchemeClrToken
) );
140 if ( aIter
!= maClrScheme
.end() )
141 aIter
->second
= nColor
;
143 maClrScheme
.emplace_back(nSchemeClrToken
, nColor
);
146 bool ClrScheme::getColorByIndex(size_t nIndex
, ::Color
& rColor
) const
148 if (nIndex
>= maClrScheme
.size())
151 rColor
= maClrScheme
[nIndex
].second
;
155 void ClrScheme::ToAny(css::uno::Any
& rVal
) const
157 std::vector
<util::Color
> aRet
;
159 for (const auto& rIndexAndColor
: maClrScheme
)
161 aRet
.push_back(static_cast<sal_Int32
>(rIndexAndColor
.second
));
164 rVal
<<= comphelper::containerToSequence(aRet
);
167 void ClrScheme::fill(model::ColorSet
& rColorSet
) const
169 for (const auto& [nToken
, rColor
] : maClrScheme
)
174 case XML_dk1
: rColorSet
.add(model::ThemeColorType::Dark1
, rColor
); break;
176 case XML_lt1
: rColorSet
.add(model::ThemeColorType::Light1
, rColor
); break;
178 case XML_dk2
: rColorSet
.add(model::ThemeColorType::Dark2
, rColor
); break;
180 case XML_lt2
: rColorSet
.add(model::ThemeColorType::Light2
, rColor
); break;
181 case XML_accent1
: rColorSet
.add(model::ThemeColorType::Accent1
, rColor
); break;
182 case XML_accent2
: rColorSet
.add(model::ThemeColorType::Accent2
, rColor
); break;
183 case XML_accent3
: rColorSet
.add(model::ThemeColorType::Accent3
, rColor
); break;
184 case XML_accent4
: rColorSet
.add(model::ThemeColorType::Accent4
, rColor
); break;
185 case XML_accent5
: rColorSet
.add(model::ThemeColorType::Accent5
, rColor
); break;
186 case XML_accent6
: rColorSet
.add(model::ThemeColorType::Accent6
, rColor
); break;
187 case XML_hlink
: rColorSet
.add(model::ThemeColorType::Hyperlink
, rColor
); break;
188 case XML_folHlink
: rColorSet
.add(model::ThemeColorType::FollowedHyperlink
, rColor
); break;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */