/src/libreoffice/oox/source/drawingml/clrscheme.cxx
Line | Count | Source |
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> |
26 | | #include <oox/drawingml/clrscheme.hxx> |
27 | | #include <oox/token/tokens.hxx> |
28 | | #include <comphelper/sequence.hxx> |
29 | | |
30 | | #include <frozen/bits/defines.h> |
31 | | #include <frozen/bits/elsa_std.h> |
32 | | #include <frozen/unordered_map.h> |
33 | | |
34 | | using namespace com::sun::star; |
35 | | |
36 | | namespace oox::drawingml { |
37 | | |
38 | | namespace |
39 | | { |
40 | | |
41 | | constexpr auto constPredefinedClrNames = frozen::make_unordered_map<PredefinedClrSchemeId, std::u16string_view> |
42 | | ({ |
43 | | { dk1, u"dk1" }, |
44 | | { lt1, u"lt1" }, |
45 | | { dk2, u"dk2" }, |
46 | | { lt2, u"lt2" }, |
47 | | { accent1, u"accent1" }, |
48 | | { accent2, u"accent2" }, |
49 | | { accent3, u"accent3" }, |
50 | | { accent4, u"accent4" }, |
51 | | { accent5, u"accent5" }, |
52 | | { accent6, u"accent6" }, |
53 | | { hlink, u"hlink" }, |
54 | | { folHlink, u"folHlink" } |
55 | | }); |
56 | | |
57 | | } // end anonymous namespace |
58 | | |
59 | | std::u16string_view getPredefinedClrNames(PredefinedClrSchemeId eID) |
60 | 19.7k | { |
61 | 19.7k | std::u16string_view empty; |
62 | 19.7k | auto iterator = constPredefinedClrNames.find(eID); |
63 | 19.7k | if (iterator == constPredefinedClrNames.end()) |
64 | 0 | return empty; |
65 | 19.7k | return iterator->second; |
66 | 19.7k | } |
67 | | |
68 | | bool ClrMap::getColorMap( sal_Int32& nClrToken ) |
69 | 395k | { |
70 | 395k | sal_Int32 nMapped = 0; |
71 | 395k | std::map < sal_Int32, sal_Int32 >::const_iterator aIter( maClrMap.find( nClrToken ) ); |
72 | 395k | if ( aIter != maClrMap.end() ) |
73 | 395k | nMapped = (*aIter).second; |
74 | 395k | if ( nMapped ) |
75 | 395k | { |
76 | 395k | nClrToken = nMapped; |
77 | 395k | return true; |
78 | 395k | } |
79 | 549 | else |
80 | 549 | return false; |
81 | 395k | } |
82 | | |
83 | | void ClrMap::setColorMap( sal_Int32 nClrToken, sal_Int32 nMappedClrToken ) |
84 | 103k | { |
85 | 103k | maClrMap[ nClrToken ] = nMappedClrToken; |
86 | 103k | } |
87 | | |
88 | | namespace { |
89 | | |
90 | | struct find_by_token |
91 | | { |
92 | | explicit find_by_token(sal_Int32 token): |
93 | 3.09M | m_token(token) |
94 | 3.09M | { |
95 | 3.09M | } |
96 | | |
97 | | bool operator()(const std::pair<sal_Int32, ::Color>& r) |
98 | 5.78M | { |
99 | 5.78M | return r.first == m_token; |
100 | 5.78M | } |
101 | | |
102 | | private: |
103 | | sal_Int32 m_token; |
104 | | }; |
105 | | |
106 | | } |
107 | | |
108 | | bool ClrScheme::getColor( sal_Int32 nSchemeClrToken, ::Color& rColor ) const |
109 | 3.04M | { |
110 | 3.04M | OSL_ASSERT((nSchemeClrToken & sal_Int32(0xFFFF0000))==0); |
111 | 3.04M | switch( nSchemeClrToken ) |
112 | 3.04M | { |
113 | 289 | case XML_bg1 : nSchemeClrToken = XML_lt1; break; |
114 | 10 | case XML_bg2 : nSchemeClrToken = XML_lt2; break; |
115 | 51.5k | case XML_tx1 : nSchemeClrToken = XML_dk1; break; |
116 | 172 | case XML_tx2 : nSchemeClrToken = XML_dk2; break; |
117 | 0 | case XML_background1 : nSchemeClrToken = XML_lt1; break; |
118 | 0 | case XML_background2 : nSchemeClrToken = XML_lt2; break; |
119 | 0 | case XML_text1 : nSchemeClrToken = XML_dk1; break; |
120 | 0 | case XML_text2 : nSchemeClrToken = XML_dk2; break; |
121 | 0 | case XML_light1 : nSchemeClrToken = XML_lt1; break; |
122 | 0 | case XML_light2 : nSchemeClrToken = XML_lt2; break; |
123 | 0 | case XML_dark1 : nSchemeClrToken = XML_dk1; break; |
124 | 0 | case XML_dark2 : nSchemeClrToken = XML_dk2; break; |
125 | 0 | case XML_hyperlink : nSchemeClrToken = XML_hlink; break; |
126 | 0 | case XML_followedHyperlink: nSchemeClrToken = XML_folHlink; break; |
127 | 3.04M | } |
128 | | |
129 | 3.04M | auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) ); |
130 | | |
131 | 3.04M | if ( aIter != maClrScheme.end() ) |
132 | 1.21M | rColor = aIter->second; |
133 | | |
134 | 3.04M | return aIter != maClrScheme.end(); |
135 | 3.04M | } |
136 | | |
137 | | void ClrScheme::setColor( sal_Int32 nSchemeClrToken, ::Color nColor ) |
138 | 52.6k | { |
139 | 52.6k | const auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) ); |
140 | 52.6k | if ( aIter != maClrScheme.end() ) |
141 | 0 | aIter->second = nColor; |
142 | 52.6k | else |
143 | 52.6k | maClrScheme.emplace_back(nSchemeClrToken, nColor); |
144 | 52.6k | } |
145 | | |
146 | | bool ClrScheme::getColorByIndex(size_t nIndex, ::Color& rColor) const |
147 | 69 | { |
148 | 69 | if (nIndex >= maClrScheme.size()) |
149 | 17 | return false; |
150 | | |
151 | 52 | rColor = maClrScheme[nIndex].second; |
152 | 52 | return true; |
153 | 69 | } |
154 | | |
155 | | void ClrScheme::ToAny(css::uno::Any& rVal) const |
156 | 0 | { |
157 | 0 | std::vector<util::Color> aRet; |
158 | |
|
159 | 0 | for (const auto& rIndexAndColor : maClrScheme) |
160 | 0 | { |
161 | 0 | aRet.push_back(static_cast<sal_Int32>(rIndexAndColor.second)); |
162 | 0 | } |
163 | |
|
164 | 0 | rVal <<= comphelper::containerToSequence(aRet); |
165 | 0 | } |
166 | | |
167 | | void ClrScheme::fill(model::ColorSet& rColorSet) const |
168 | 0 | { |
169 | 0 | for (const auto& [nToken, rColor] : maClrScheme) |
170 | 0 | { |
171 | 0 | switch (nToken) |
172 | 0 | { |
173 | 0 | case XML_tx1: |
174 | 0 | case XML_dk1: rColorSet.add(model::ThemeColorType::Dark1, rColor); break; |
175 | 0 | case XML_bg1: |
176 | 0 | case XML_lt1: rColorSet.add(model::ThemeColorType::Light1, rColor); break; |
177 | 0 | case XML_tx2: |
178 | 0 | case XML_dk2: rColorSet.add(model::ThemeColorType::Dark2, rColor); break; |
179 | 0 | case XML_bg2: |
180 | 0 | case XML_lt2: rColorSet.add(model::ThemeColorType::Light2, rColor); break; |
181 | 0 | case XML_accent1: rColorSet.add(model::ThemeColorType::Accent1, rColor); break; |
182 | 0 | case XML_accent2: rColorSet.add(model::ThemeColorType::Accent2, rColor); break; |
183 | 0 | case XML_accent3: rColorSet.add(model::ThemeColorType::Accent3, rColor); break; |
184 | 0 | case XML_accent4: rColorSet.add(model::ThemeColorType::Accent4, rColor); break; |
185 | 0 | case XML_accent5: rColorSet.add(model::ThemeColorType::Accent5, rColor); break; |
186 | 0 | case XML_accent6: rColorSet.add(model::ThemeColorType::Accent6, rColor); break; |
187 | 0 | case XML_hlink: rColorSet.add(model::ThemeColorType::Hyperlink, rColor); break; |
188 | 0 | case XML_folHlink: rColorSet.add(model::ThemeColorType::FollowedHyperlink, rColor); break; |
189 | 0 | default: break; |
190 | 0 | } |
191 | 0 | } |
192 | 0 | } |
193 | | |
194 | | } |
195 | | |
196 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |