bump product version to 4.1.6.2
[LibreOffice.git] / oox / source / drawingml / chart / objectformatter.cxx
blob2541d422beb95866ec497bc61d41de69e7744ca6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "oox/drawingml/chart/objectformatter.hxx"
22 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
23 #include <com/sun/star/util/XNumberFormatTypes.hpp>
24 #include <osl/thread.h>
25 #include <rtl/strbuf.hxx>
26 #include "oox/core/xmlfilterbase.hxx"
27 #include "oox/drawingml/fillproperties.hxx"
28 #include "oox/drawingml/lineproperties.hxx"
29 #include "oox/drawingml/shapepropertymap.hxx"
30 #include "oox/drawingml/textbody.hxx"
31 #include "oox/drawingml/textparagraph.hxx"
32 #include "oox/drawingml/theme.hxx"
33 #include "oox/drawingml/chart/chartspacemodel.hxx"
34 #include "oox/helper/modelobjecthelper.hxx"
36 namespace oox {
37 namespace drawingml {
38 namespace chart {
40 // ============================================================================
42 using namespace ::com::sun::star::chart2;
43 using namespace ::com::sun::star::frame;
44 using namespace ::com::sun::star::graphic;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::util;
49 using ::oox::core::XmlFilterBase;
51 // ============================================================================
53 namespace {
55 struct AutoFormatPatternEntry
57 sal_Int32 mnColorToken; /// Theme color token.
58 sal_Int32 mnModToken; /// Color modification token.
59 sal_Int32 mnModValue; /// Color modification value.
62 #define AUTOFORMAT_PATTERN_COLOR( color_token ) \
63 { color_token, XML_TOKEN_INVALID, 0 }
65 #define AUTOFORMAT_PATTERN_COLORMOD( color_token, mod_token, mod_value ) \
66 { color_token, mod_token, mod_value }
68 #define AUTOFORMAT_PATTERN_END() \
69 AUTOFORMAT_PATTERN_COLOR( XML_TOKEN_INVALID )
71 static const AutoFormatPatternEntry spAutoFormatPattern1[] =
73 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 88500 ),
74 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 55000 ),
75 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 78000 ),
76 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 92500 ),
77 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 70000 ),
78 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 30000 ),
79 AUTOFORMAT_PATTERN_END()
82 static const AutoFormatPatternEntry spAutoFormatPattern2[] =
84 AUTOFORMAT_PATTERN_COLOR( XML_accent1 ),
85 AUTOFORMAT_PATTERN_COLOR( XML_accent2 ),
86 AUTOFORMAT_PATTERN_COLOR( XML_accent3 ),
87 AUTOFORMAT_PATTERN_COLOR( XML_accent4 ),
88 AUTOFORMAT_PATTERN_COLOR( XML_accent5 ),
89 AUTOFORMAT_PATTERN_COLOR( XML_accent6 ),
90 AUTOFORMAT_PATTERN_END()
93 static const AutoFormatPatternEntry spAutoFormatPattern3[] =
95 AUTOFORMAT_PATTERN_COLORMOD( XML_accent1, XML_shade, 50000 ),
96 AUTOFORMAT_PATTERN_COLORMOD( XML_accent2, XML_shade, 50000 ),
97 AUTOFORMAT_PATTERN_COLORMOD( XML_accent3, XML_shade, 50000 ),
98 AUTOFORMAT_PATTERN_COLORMOD( XML_accent4, XML_shade, 50000 ),
99 AUTOFORMAT_PATTERN_COLORMOD( XML_accent5, XML_shade, 50000 ),
100 AUTOFORMAT_PATTERN_COLORMOD( XML_accent6, XML_shade, 50000 ),
101 AUTOFORMAT_PATTERN_END()
104 static const AutoFormatPatternEntry spAutoFormatPattern4[] =
106 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 5000 ),
107 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 55000 ),
108 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 78000 ),
109 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 15000 ),
110 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 70000 ),
111 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 30000 ),
112 AUTOFORMAT_PATTERN_END()
115 #undef AUTOFORMAT_PATTERN_COLOR
116 #undef AUTOFORMAT_PATTERN_COLORMOD
117 #undef AUTOFORMAT_PATTERN_END
119 // ----------------------------------------------------------------------------
121 struct AutoFormatEntry
123 sal_Int32 mnFirstStyleIdx; /// First chart style index.
124 sal_Int32 mnLastStyleIdx; /// Last chart style index.
125 sal_Int32 mnThemedIdx; /// Themed style index.
126 sal_Int32 mnColorToken; /// Theme color token.
127 sal_Int32 mnModToken; /// Color modification token.
128 sal_Int32 mnModValue; /// Color modification value.
129 sal_Int32 mnRelLineWidth; /// Relative line width (percent).
130 const AutoFormatPatternEntry* mpPattern;/// Color cycling pattern for data series.
131 bool mbFadedColor; /// True = Faded color for data series.
134 #define AUTOFORMAT_COLOR( first, last, themed_style, color_token ) \
135 { first, last, themed_style, color_token, XML_TOKEN_INVALID, 0, 100, 0, false }
137 #define AUTOFORMAT_COLORMOD( first, last, themed_style, color_token, mod_token, mod_value ) \
138 { first, last, themed_style, color_token, mod_token, mod_value, 100, 0, false }
140 #define AUTOFORMAT_ACCENTSMOD( first, themed_style, mod_token, mod_value ) \
141 AUTOFORMAT_COLORMOD( first, first, themed_style, XML_accent1, mod_token, mod_value ), \
142 AUTOFORMAT_COLORMOD( first + 1, first + 1, themed_style, XML_accent2, mod_token, mod_value ), \
143 AUTOFORMAT_COLORMOD( first + 2, first + 2, themed_style, XML_accent3, mod_token, mod_value ), \
144 AUTOFORMAT_COLORMOD( first + 3, first + 3, themed_style, XML_accent4, mod_token, mod_value ), \
145 AUTOFORMAT_COLORMOD( first + 4, first + 4, themed_style, XML_accent5, mod_token, mod_value ), \
146 AUTOFORMAT_COLORMOD( first + 5, first + 5, themed_style, XML_accent6, mod_token, mod_value )
148 #define AUTOFORMAT_PATTERN( first, last, themed_style, line_width, pattern ) \
149 { first, last, themed_style, XML_TOKEN_INVALID, XML_TOKEN_INVALID, 0, line_width, pattern, false }
151 #define AUTOFORMAT_FADED( first, last, themed_style, color_token, line_width ) \
152 { first, last, themed_style, color_token, XML_TOKEN_INVALID, 0, line_width, 0, true }
154 #define AUTOFORMAT_FADEDACCENTS( first, themed_style, line_width ) \
155 AUTOFORMAT_FADED( first, first, themed_style, XML_accent1, line_width ), \
156 AUTOFORMAT_FADED( first + 1, first + 1, themed_style, XML_accent2, line_width ), \
157 AUTOFORMAT_FADED( first + 2, first + 2, themed_style, XML_accent3, line_width ), \
158 AUTOFORMAT_FADED( first + 3, first + 3, themed_style, XML_accent4, line_width ), \
159 AUTOFORMAT_FADED( first + 4, first + 4, themed_style, XML_accent5, line_width ), \
160 AUTOFORMAT_FADED( first + 5, first + 5, themed_style, XML_accent6, line_width )
162 #define AUTOFORMAT_INVISIBLE( first, last ) \
163 AUTOFORMAT_COLOR( first, last, -1, XML_TOKEN_INVALID )
165 #define AUTOFORMAT_END() \
166 AUTOFORMAT_INVISIBLE( -1, -1 )
168 static const AutoFormatEntry spNoFormats[] =
170 AUTOFORMAT_INVISIBLE( 1, 48 ),
171 AUTOFORMAT_END()
174 static const AutoFormatEntry spDataTableLines[] =
176 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ),
177 AUTOFORMAT_COLORMOD( 33, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ),
178 // 41...48: no line, same as Chart2
179 AUTOFORMAT_END()
182 static const AutoFormatEntry spPlotArea2dFills[] =
184 AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_bg1 ),
185 AUTOFORMAT_COLORMOD( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 20000 ),
186 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_tint, 20000 ), // tint not documented!?
187 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
188 AUTOFORMAT_END()
191 static const AutoFormatEntry spWallFloorLines[] =
193 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ),
194 AUTOFORMAT_COLORMOD( 33, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ),
195 // 41...48: no line, same as Chart2
196 AUTOFORMAT_END()
199 static const AutoFormatEntry spWallFloorFills[] =
201 AUTOFORMAT_INVISIBLE( 1, 32 ),
202 AUTOFORMAT_COLORMOD( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 20000 ),
203 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_tint, 20000 ), // tint not documented!?
204 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
205 AUTOFORMAT_END()
208 static const AutoFormatEntry spAxisLines[] =
210 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), // tint not documented!?
211 AUTOFORMAT_COLORMOD( 33, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), // tint not documented!?
212 AUTOFORMAT_END()
215 static const AutoFormatEntry spMajorGridLines[] =
217 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), // tint not documented!?
218 AUTOFORMAT_COLORMOD( 33, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), // tint not documented!?
219 AUTOFORMAT_END()
222 static const AutoFormatEntry spMinorGridLines[] =
224 AUTOFORMAT_COLORMOD( 1, 40, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 50000 ),
225 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 90000 ),
226 AUTOFORMAT_END()
229 static const AutoFormatEntry spOtherLines[] =
231 AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1 ),
232 AUTOFORMAT_COLOR( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1 ),
233 AUTOFORMAT_COLORMOD( 35, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_shade, 25000 ),
234 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_SUBTLE, XML_lt1 ),
235 AUTOFORMAT_END()
238 static const AutoFormatEntry spLinearSeriesLines[] =
240 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 300, spAutoFormatPattern1 ),
241 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 300, spAutoFormatPattern2 ),
242 AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 300 ),
243 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
244 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
245 AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 500 ),
246 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
247 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
248 AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_SUBTLE, 500 ),
249 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_SUBTLE, 700, spAutoFormatPattern1 ),
250 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_SUBTLE, 700, spAutoFormatPattern2 ),
251 AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_SUBTLE, 700 ),
252 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
253 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
254 AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 500 ),
255 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern4 ),
256 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
257 AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_SUBTLE, 500 ),
258 AUTOFORMAT_END()
261 static const AutoFormatEntry spFilledSeriesLines[] =
263 AUTOFORMAT_INVISIBLE( 1, 8 ),
264 AUTOFORMAT_COLOR( 9, 16, THEMED_STYLE_SUBTLE, XML_lt1 ),
265 AUTOFORMAT_INVISIBLE( 17, 32 ),
266 AUTOFORMAT_COLORMOD( 33, 33, THEMED_STYLE_SUBTLE, XML_dk1, XML_shade, 50000 ),
267 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern3 ),
268 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 50000 ),
269 AUTOFORMAT_INVISIBLE( 41, 48 ),
270 AUTOFORMAT_END()
273 static const AutoFormatEntry spFilledSeries2dFills[] =
275 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
276 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
277 AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 100 ),
278 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
279 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
280 AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 100 ),
281 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern1 ),
282 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
283 AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_INTENSE, 100 ),
284 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern1 ),
285 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
286 AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_INTENSE, 100 ),
287 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
288 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
289 AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 100 ),
290 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern4 ),
291 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
292 AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_INTENSE, 100 ),
293 AUTOFORMAT_END()
296 static const AutoFormatEntry spFilledSeries3dFills[] =
298 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
299 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
300 AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 100 ),
301 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
302 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
303 AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 100 ),
304 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
305 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
306 AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_SUBTLE, 100 ),
307 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
308 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
309 AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_SUBTLE, 100 ),
310 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
311 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
312 AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 100 ),
313 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern4 ),
314 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
315 AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_SUBTLE, 100 ),
316 AUTOFORMAT_END()
319 static const AutoFormatEntry spFilledSeriesEffects[] =
321 // 1...8: no effect, same as Chart2
322 AUTOFORMAT_COLOR( 9, 16, THEMED_STYLE_SUBTLE, XML_dk1 ),
323 AUTOFORMAT_COLOR( 17, 24, THEMED_STYLE_MODERATE, XML_dk1 ),
324 AUTOFORMAT_COLOR( 25, 32, THEMED_STYLE_INTENSE, XML_dk1 ),
325 // 33...40: no effect, same as Chart2
326 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_INTENSE, XML_dk1 ),
327 AUTOFORMAT_END()
330 static const AutoFormatEntry spUpDownBarLines[] =
332 AUTOFORMAT_COLOR( 1, 16, THEMED_STYLE_SUBTLE, XML_tx1 ),
333 AUTOFORMAT_INVISIBLE( 17, 32 ),
334 AUTOFORMAT_COLOR( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1 ),
335 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
336 AUTOFORMAT_INVISIBLE( 41, 48 ),
337 AUTOFORMAT_END()
340 static const AutoFormatEntry spUpBarFills[] =
342 AUTOFORMAT_COLORMOD( 1, 1, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 25000 ),
343 AUTOFORMAT_COLORMOD( 2, 2, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 5000 ),
344 AUTOFORMAT_ACCENTSMOD( 3, THEMED_STYLE_SUBTLE, XML_tint, 25000 ),
345 AUTOFORMAT_COLORMOD( 9, 9, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 25000 ),
346 AUTOFORMAT_COLORMOD( 10, 10, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 5000 ),
347 AUTOFORMAT_ACCENTSMOD( 11, THEMED_STYLE_SUBTLE, XML_tint, 25000 ),
348 AUTOFORMAT_COLORMOD( 17, 17, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
349 AUTOFORMAT_COLORMOD( 18, 18, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 5000 ),
350 AUTOFORMAT_ACCENTSMOD( 19, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
351 AUTOFORMAT_COLORMOD( 25, 25, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
352 AUTOFORMAT_COLORMOD( 26, 26, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 5000 ),
353 AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
354 AUTOFORMAT_COLOR( 33, 40, THEMED_STYLE_SUBTLE, XML_lt1 ),
355 AUTOFORMAT_COLORMOD( 41, 41, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
356 AUTOFORMAT_COLOR( 42, 42, THEMED_STYLE_INTENSE, XML_lt1 ),
357 AUTOFORMAT_ACCENTSMOD( 43, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
358 AUTOFORMAT_END()
361 static const AutoFormatEntry spDownBarFills[] =
363 AUTOFORMAT_COLORMOD( 1, 1, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
364 AUTOFORMAT_COLORMOD( 2, 2, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
365 AUTOFORMAT_ACCENTSMOD( 3, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
366 AUTOFORMAT_COLORMOD( 9, 9, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
367 AUTOFORMAT_COLORMOD( 10, 10, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
368 AUTOFORMAT_ACCENTSMOD( 11, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
369 AUTOFORMAT_COLORMOD( 17, 17, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
370 AUTOFORMAT_COLORMOD( 18, 18, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 95000 ),
371 AUTOFORMAT_ACCENTSMOD( 19, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
372 AUTOFORMAT_COLORMOD( 25, 25, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
373 AUTOFORMAT_COLORMOD( 26, 26, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 95000 ),
374 AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
375 AUTOFORMAT_COLORMOD( 33, 33, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
376 AUTOFORMAT_COLORMOD( 34, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
377 AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
378 AUTOFORMAT_COLORMOD( 41, 41, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
379 AUTOFORMAT_COLOR( 42, 42, THEMED_STYLE_INTENSE, XML_dk1 ),
380 AUTOFORMAT_ACCENTSMOD( 43, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
381 AUTOFORMAT_END()
384 static const AutoFormatEntry spUpDownBarEffects[] =
386 // 1...8: no effect, same as Chart2
387 AUTOFORMAT_COLOR( 9, 16, THEMED_STYLE_SUBTLE, XML_dk1 ),
388 AUTOFORMAT_COLOR( 17, 24, THEMED_STYLE_MODERATE, XML_dk1 ),
389 AUTOFORMAT_COLOR( 25, 32, THEMED_STYLE_INTENSE, XML_dk1 ),
390 // 33...40: no effect, same as Chart2
391 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_INTENSE, XML_dk1 ),
392 AUTOFORMAT_END()
395 #undef AUTOFORMAT_COLOR
396 #undef AUTOFORMAT_COLORMOD
397 #undef AUTOFORMAT_ACCENTSMOD
398 #undef AUTOFORMAT_PATTERN
399 #undef AUTOFORMAT_FADED
400 #undef AUTOFORMAT_FADEDACCENTS
401 #undef AUTOFORMAT_INVISIBLE
402 #undef AUTOFORMAT_END
404 const AutoFormatEntry* lclGetAutoFormatEntry( const AutoFormatEntry* pEntries, sal_Int32 nStyle )
406 for( ; pEntries && (pEntries->mnFirstStyleIdx >= 0); ++pEntries )
407 if( (pEntries->mnFirstStyleIdx <= nStyle) && (nStyle <= pEntries->mnLastStyleIdx) )
408 return pEntries;
409 return 0;
412 // ----------------------------------------------------------------------------
414 struct AutoTextEntry
416 sal_Int32 mnFirstStyleIdx; /// First chart style index.
417 sal_Int32 mnLastStyleIdx; /// Last chart style index.
418 sal_Int32 mnThemedFont; /// Themed font (minor/major).
419 sal_Int32 mnColorToken; /// Theme color token.
420 sal_Int32 mnDefFontSize; /// Default font size (1/100 points).
421 sal_Int32 mnRelFontSize; /// Font size relative to chart global font (percent).
422 bool mbBold; /// True = bold font.
425 #define AUTOTEXT_COLOR( first, last, themed_font, color_token, def_font_size, rel_font_size, bold ) \
426 { first, last, themed_font, color_token, def_font_size, rel_font_size, bold }
428 #define AUTOTEXT_END() \
429 AUTOTEXT_COLOR( -1, -1, XML_none, XML_TOKEN_INVALID, 1000, 100, false )
431 static const AutoTextEntry spChartTitleTexts[] =
433 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1800, 120, true ),
434 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1800, 120, true ),
435 AUTOTEXT_END()
438 static const AutoTextEntry spAxisTitleTexts[] =
440 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1000, 100, true ),
441 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1000, 100, true ),
442 AUTOTEXT_END()
445 static const AutoTextEntry spOtherTexts[] =
447 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1000, 100, false ),
448 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1000, 100, false ),
449 AUTOTEXT_END()
452 #undef AUTOTEXT_COLOR
453 #undef AUTOTEXT_END
455 const AutoTextEntry* lclGetAutoTextEntry( const AutoTextEntry* pEntries, sal_Int32 nStyle )
457 for( ; pEntries && (pEntries->mnFirstStyleIdx >= 0); ++pEntries )
458 if( (pEntries->mnFirstStyleIdx <= nStyle) && (nStyle <= pEntries->mnLastStyleIdx) )
459 return pEntries;
460 return 0;
463 // ----------------------------------------------------------------------------
465 /** Property identifiers for common chart objects, to be used in ShapePropertyInfo. */
466 static const sal_Int32 spnCommonPropIds[] =
468 PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDashName,
469 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
470 PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillGradientName,
471 PROP_FillBitmapName, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
472 PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint
475 /** Property identifiers for linear data series, to be used in ShapePropertyInfo. */
476 static const sal_Int32 spnLinearPropIds[] =
478 PROP_LineStyle, PROP_LineWidth, PROP_Color, PROP_Transparency, PROP_LineDashName,
479 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
480 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
481 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
482 PROP_INVALID, PROP_INVALID, PROP_INVALID
485 /** Property identifiers for filled data series, to be used in ShapePropertyInfo. */
486 static const sal_Int32 spnFilledPropIds[] =
488 PROP_BorderStyle, PROP_BorderWidth, PROP_BorderColor, PROP_BorderTransparency, PROP_BorderDashName,
489 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
490 PROP_FillStyle, PROP_Color, PROP_Transparency, PROP_GradientName,
491 PROP_FillBitmapName, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
492 PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint
495 /** Property info for common chart objects, to be used in ShapePropertyMap. */
496 static const ShapePropertyInfo saCommonPropInfo( spnCommonPropIds, false, true, true, true );
497 /** Property info for linear data series, to be used in ShapePropertyMap. */
498 static const ShapePropertyInfo saLinearPropInfo( spnLinearPropIds, false, true, true, true );
499 /** Property info for filled data series, to be used in ShapePropertyMap. */
500 static const ShapePropertyInfo saFilledPropInfo( spnFilledPropIds, false, true, true, true );
502 // ----------------------------------------------------------------------------
504 /** Contains information about formatting of a specific chart object type. */
505 struct ObjectTypeFormatEntry
507 ObjectType meObjType; /// Object type for automatic format.
508 const ShapePropertyInfo* mpPropInfo; /// Property info for the ShapePropertyMap class.
509 const AutoFormatEntry* mpAutoLines; /// Automatic line formatting for all chart styles.
510 const AutoFormatEntry* mpAutoFills; /// Automatic fill formatting for all chart styles.
511 const AutoFormatEntry* mpAutoEffects; /// Automatic effect formatting for all chart styles.
512 const AutoTextEntry* mpAutoTexts; /// Automatic text attributes for all chart styles.
513 bool mbIsFrame; /// True = object is a frame, false = object is a line.
516 #define TYPEFORMAT_FRAME( obj_type, prop_type, auto_texts, auto_lines, auto_fills, auto_effects ) \
517 { obj_type, prop_type, auto_lines, auto_fills, auto_effects, auto_texts, true }
519 #define TYPEFORMAT_LINE( obj_type, prop_type, auto_texts, auto_lines ) \
520 { obj_type, prop_type, auto_lines, 0, 0, auto_texts, false }
522 static const ObjectTypeFormatEntry spObjTypeFormatEntries[] =
524 // object type property info auto text auto line auto fill auto effect
525 TYPEFORMAT_FRAME( OBJECTTYPE_CHARTSPACE, &saCommonPropInfo, 0, spNoFormats, spNoFormats, 0 /* eq to Ch2 */ ),
526 TYPEFORMAT_FRAME( OBJECTTYPE_CHARTTITLE, &saCommonPropInfo, spChartTitleTexts, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
527 TYPEFORMAT_FRAME( OBJECTTYPE_LEGEND, &saCommonPropInfo, spOtherTexts, spNoFormats, spNoFormats, 0 /* eq to Ch2 */ ),
528 TYPEFORMAT_FRAME( OBJECTTYPE_PLOTAREA2D, &saCommonPropInfo, 0, 0 /* eq to Ch2 */, spPlotArea2dFills, 0 /* eq to Ch2 */ ),
529 TYPEFORMAT_FRAME( OBJECTTYPE_PLOTAREA3D, &saCommonPropInfo, 0, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
530 TYPEFORMAT_FRAME( OBJECTTYPE_WALL, &saCommonPropInfo, 0, spWallFloorLines, spWallFloorFills, 0 /* eq to Ch2 */ ),
531 TYPEFORMAT_FRAME( OBJECTTYPE_FLOOR, &saCommonPropInfo, 0, spWallFloorLines, spWallFloorFills, 0 /* eq to Ch2 */ ),
532 TYPEFORMAT_LINE( OBJECTTYPE_AXIS, &saCommonPropInfo, spOtherTexts, spAxisLines ),
533 TYPEFORMAT_FRAME( OBJECTTYPE_AXISTITLE, &saCommonPropInfo, spAxisTitleTexts, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
534 TYPEFORMAT_FRAME( OBJECTTYPE_AXISUNIT, &saCommonPropInfo, spAxisTitleTexts, 0 /* eq in Ch2 */, 0 /* eq in Ch2 */, 0 /* eq in Ch2 */ ),
535 TYPEFORMAT_LINE( OBJECTTYPE_MAJORGRIDLINE, &saCommonPropInfo, 0, spMajorGridLines ),
536 TYPEFORMAT_LINE( OBJECTTYPE_MINORGRIDLINE, &saCommonPropInfo, 0, spMinorGridLines ),
537 TYPEFORMAT_LINE( OBJECTTYPE_LINEARSERIES2D, &saLinearPropInfo, 0, spLinearSeriesLines ),
538 TYPEFORMAT_FRAME( OBJECTTYPE_FILLEDSERIES2D, &saFilledPropInfo, 0, spFilledSeriesLines, spFilledSeries2dFills, spFilledSeriesEffects ),
539 TYPEFORMAT_FRAME( OBJECTTYPE_FILLEDSERIES3D, &saFilledPropInfo, 0, spFilledSeriesLines, spFilledSeries3dFills, spFilledSeriesEffects ),
540 TYPEFORMAT_FRAME( OBJECTTYPE_DATALABEL, &saCommonPropInfo, spOtherTexts, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
541 TYPEFORMAT_LINE( OBJECTTYPE_TRENDLINE, &saCommonPropInfo, 0, spOtherLines ),
542 TYPEFORMAT_FRAME( OBJECTTYPE_TRENDLINELABEL, &saCommonPropInfo, spOtherTexts, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
543 TYPEFORMAT_LINE( OBJECTTYPE_ERRORBAR, &saCommonPropInfo, 0, spOtherLines ),
544 TYPEFORMAT_LINE( OBJECTTYPE_SERLINE, &saCommonPropInfo, 0, spOtherLines ),
545 TYPEFORMAT_LINE( OBJECTTYPE_LEADERLINE, &saCommonPropInfo, 0, spOtherLines ),
546 TYPEFORMAT_LINE( OBJECTTYPE_DROPLINE, &saCommonPropInfo, 0, spOtherLines ),
547 TYPEFORMAT_LINE( OBJECTTYPE_HILOLINE, &saLinearPropInfo, 0, spOtherLines ),
548 TYPEFORMAT_FRAME( OBJECTTYPE_UPBAR, &saCommonPropInfo, 0, spUpDownBarLines, spUpBarFills, spUpDownBarEffects ),
549 TYPEFORMAT_FRAME( OBJECTTYPE_DOWNBAR, &saCommonPropInfo, 0, spUpDownBarLines, spDownBarFills, spUpDownBarEffects ),
550 TYPEFORMAT_LINE( OBJECTTYPE_DATATABLE, &saCommonPropInfo, spOtherTexts, spDataTableLines )
553 #undef TYPEFORMAT_FRAME
554 #undef TYPEFORMAT_LINE
556 // ----------------------------------------------------------------------------
558 void lclConvertPictureOptions( FillProperties& orFillProps, const PictureOptionsModel& rPicOptions )
560 bool bStacked = (rPicOptions.mnPictureFormat == XML_stack) || (rPicOptions.mnPictureFormat == XML_stackScale);
561 orFillProps.maBlipProps.moBitmapMode = bStacked ? XML_tile : XML_stretch;
564 } // namespace
566 // ============================================================================
568 struct ObjectFormatterData;
570 // ----------------------------------------------------------------------------
572 class DetailFormatterBase
574 public:
575 explicit DetailFormatterBase(
576 ObjectFormatterData& rData,
577 const AutoFormatEntry* pAutoFormatEntry );
578 explicit DetailFormatterBase(
579 ObjectFormatterData& rData,
580 const AutoTextEntry* pAutoTextEntry );
582 protected:
583 /** Returns the placeholder color which may depend on the passed series index. */
584 sal_Int32 getPhColor( sal_Int32 nSeriesIdx ) const;
586 private:
587 /** Resolves and returns the scheme color with the passed transformation. */
588 sal_Int32 getSchemeColor( sal_Int32 nColorToken, sal_Int32 nModToken, sal_Int32 nModValue ) const;
590 protected:
591 typedef ::std::vector< sal_Int32 > ColorPatternVec;
593 ObjectFormatterData& mrData; /// Shared formatter data.
594 sal_Int32 mnPhClr; /// RGB placeholder color for themed style.
595 ColorPatternVec maColorPattern; /// Different cycling colors for data series.
598 // ----------------------------------------------------------------------------
600 class LineFormatter : public DetailFormatterBase
602 public:
603 explicit LineFormatter(
604 ObjectFormatterData& rData,
605 const AutoFormatEntry* pAutoFormatEntry );
607 /** Converts line formatting to the passed property set. */
608 void convertFormatting(
609 ShapePropertyMap& rPropMap,
610 const ModelRef< Shape >& rxShapeProp,
611 sal_Int32 nSeriesIdx );
613 private:
614 LinePropertiesPtr mxAutoLine; /// Automatic line properties.
617 // ----------------------------------------------------------------------------
619 class FillFormatter : public DetailFormatterBase
621 public:
622 explicit FillFormatter(
623 ObjectFormatterData& rData,
624 const AutoFormatEntry* pAutoFormatEntry );
626 /** Converts area formatting to the passed property set. */
627 void convertFormatting(
628 ShapePropertyMap& rPropMap,
629 const ModelRef< Shape >& rxShapeProp,
630 const PictureOptionsModel* pPicOptions,
631 sal_Int32 nSeriesIdx );
633 private:
634 FillPropertiesPtr mxAutoFill; /// Automatic fill properties.
637 // ----------------------------------------------------------------------------
639 class EffectFormatter : public DetailFormatterBase
641 public:
642 explicit EffectFormatter(
643 ObjectFormatterData& rData,
644 const AutoFormatEntry* pAutoFormatEntry );
646 /** Converts effect formatting to the passed property set. */
647 void convertFormatting(
648 ShapePropertyMap& rPropMap,
649 const ModelRef< Shape >& rxShapeProp,
650 sal_Int32 nSeriesIdx ) const;
653 // ----------------------------------------------------------------------------
655 class TextFormatter : public DetailFormatterBase
657 public:
658 explicit TextFormatter(
659 ObjectFormatterData& rData,
660 const AutoTextEntry* pAutoTextEntry,
661 const ModelRef< TextBody >& rxGlobalTextProp );
663 /** Converts text formatting to the passed property set. */
664 void convertFormatting(
665 PropertySet& rPropSet,
666 const TextCharacterProperties* pTextProps );
667 /** Converts text formatting to the passed property set. */
668 void convertFormatting(
669 PropertySet& rPropSet,
670 const ModelRef< TextBody >& rxTextProp );
672 private:
673 TextCharacterPropertiesPtr mxAutoText; /// Automatic text properties.
676 // ----------------------------------------------------------------------------
678 /** Formatter for a specific object type. */
679 class ObjectTypeFormatter
681 public:
682 explicit ObjectTypeFormatter(
683 ObjectFormatterData& rData,
684 const ObjectTypeFormatEntry& rEntry,
685 const ChartSpaceModel& rChartSpace );
687 /** Sets frame formatting properties to the passed property set. */
688 void convertFrameFormatting(
689 PropertySet& rPropSet,
690 const ModelRef< Shape >& rxShapeProp,
691 const PictureOptionsModel* pPicOptions,
692 sal_Int32 nSeriesIdx );
694 /** Sets text formatting properties to the passed property set. */
695 void convertTextFormatting(
696 PropertySet& rPropSet,
697 const ModelRef< TextBody >& rxTextProp );
699 /** Sets frame/text formatting properties to the passed property set. */
700 void convertFormatting(
701 PropertySet& rPropSet,
702 const ModelRef< Shape >& rxShapeProp,
703 const ModelRef< TextBody >& rxTextProp );
705 /** Sets text formatting properties to the passed property set. */
706 void convertTextFormatting(
707 PropertySet& rPropSet,
708 const TextCharacterProperties& rTextProps );
710 /** Sets automatic fill properties to the passed property set. */
711 void convertAutomaticFill(
712 PropertySet& rPropSet,
713 sal_Int32 nSeriesIdx );
715 private:
716 LineFormatter maLineFormatter; /// Converter for line formatting.
717 FillFormatter maFillFormatter; /// Converter for fill formatting.
718 EffectFormatter maEffectFormatter; /// Converter for effect formatting.
719 TextFormatter maTextFormatter; /// Converter for text formatting.
720 ModelObjectHelper& mrModelObjHelper; /// Helper for named drawing formatting.
721 const ObjectTypeFormatEntry& mrEntry; /// Additional settings.
724 // ----------------------------------------------------------------------------
726 struct ObjectFormatterData
728 typedef RefMap< ObjectType, ObjectTypeFormatter > ObjectTypeFormatterMap;
730 const XmlFilterBase& mrFilter; /// Base filter object.
731 ObjectTypeFormatterMap maTypeFormatters; /// Formatters for all types of objects in a chart.
732 ModelObjectHelper maModelObjHelper; /// Helper for named drawing formatting (dashes, gradients, bitmaps).
733 Reference< XNumberFormats > mxNumFmts; /// Number formats collection of container document.
734 Reference< XNumberFormatTypes > mxNumTypes; /// Number format types collection of container document.
735 Locale maEnUsLocale; /// Locale struct containing en-US.
736 Locale maFromLocale; /// Empty locale struct.
737 sal_Int32 mnMaxSeriesIdx; /// Maximum series index used for color cycling/fading.
739 explicit ObjectFormatterData(
740 const XmlFilterBase& rFilter,
741 const Reference< XChartDocument >& rxChartDoc,
742 const ChartSpaceModel& rChartSpace );
744 ObjectTypeFormatter* getTypeFormatter( ObjectType eObjType );
747 // ============================================================================
749 DetailFormatterBase::DetailFormatterBase( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) :
750 mrData( rData ),
751 mnPhClr( -1 )
753 if( pAutoFormatEntry )
755 if( pAutoFormatEntry->mpPattern )
757 // prepare multi-color pattern
758 for( const AutoFormatPatternEntry* pPatternEntry = pAutoFormatEntry->mpPattern; pPatternEntry->mnColorToken != XML_TOKEN_INVALID; ++pPatternEntry )
759 maColorPattern.push_back( getSchemeColor( pPatternEntry->mnColorToken, pPatternEntry->mnModToken, pPatternEntry->mnModValue ) );
761 else if( pAutoFormatEntry->mnColorToken != XML_TOKEN_INVALID )
763 // prepare color or single-color pattern (color fading)
764 mnPhClr = getSchemeColor( pAutoFormatEntry->mnColorToken, pAutoFormatEntry->mnModToken, pAutoFormatEntry->mnModValue );
765 if( pAutoFormatEntry->mbFadedColor )
766 maColorPattern.push_back( mnPhClr );
771 DetailFormatterBase::DetailFormatterBase( ObjectFormatterData& rData, const AutoTextEntry* pAutoTextEntry ) :
772 mrData( rData ),
773 mnPhClr( -1 )
775 if( pAutoTextEntry && (pAutoTextEntry->mnColorToken != XML_TOKEN_INVALID) )
776 mnPhClr = getSchemeColor( pAutoTextEntry->mnColorToken, XML_TOKEN_INVALID, 0 );
779 sal_Int32 DetailFormatterBase::getPhColor( sal_Int32 nSeriesIdx ) const
781 if( maColorPattern.empty() || (mrData.mnMaxSeriesIdx < 0) || (nSeriesIdx < 0) )
782 return mnPhClr;
784 /* Apply tint/shade depending on the cycle index. The colors of leading
785 series are darkened (color shade), the colors of trailing series are
786 lightened (color tint). Shade/tint is applied in an exclusive range of
787 -70% to 70%.
789 Example 1: 3 data series using single-color shading with accent color 1
790 (e.g. automatic chart style #3). Shade/tint is applied per series.
791 Shade/tint changes in steps of 140%/(<series_count+1) = 140%/4 = 35%,
792 starting at -70%:
793 Step 1: -70% -> Not used.
794 Step 2: -35% -> Series 1 has 35% shade of accent color 1.
795 Step 3: 0% -> Series 2 has pure accent color 1.
796 Step 4: 35% -> Series 3 has 35% tint of accent color 1.
797 Step 5: 70% -> Not used.
799 Example 2: 20 data series using accent color pattern (e.g. automatic
800 chart style #2). Each color cycle has a size of 6 series (accent colors
801 1 to 6). Shade/tint is applied per color cycle.
802 Cycle #1: Series 1...6 are based on accent colors 1 to 6.
803 Cycle #2: Series 7...12 are based on accent colors 1 to 6.
804 Cycle #3: Series 13...18 are based on accent colors 1 to 6.
805 Cycle #4: Series 19...20 are based on accent colors 1 to 2.
806 Shade/tint changes in steps of 140%/(cycle_count+1) = 140%/5 = 28%,
807 starting at -70%:
808 Step 1: -70% -> Not used.
809 Step 2: -42% -> Cycle #1 has 42% shade of accent colors 1...6
810 step 3: -14% -> Cycle #2 has 14% shade of accent colors 1...6
811 step 4: 14% -> Cycle #3 has 14% tint of accent colors 1...6
812 step 5: 42% -> Cycle #4 has 42% tint of accent colors 1...6
813 step 6: 70% -> Not used.
815 sal_Int32 nPhClr = maColorPattern[ static_cast< size_t >( nSeriesIdx % maColorPattern.size() ) ];
816 size_t nCycleIdx = static_cast< size_t >( nSeriesIdx / maColorPattern.size() );
817 size_t nMaxCycleIdx = static_cast< size_t >( mrData.mnMaxSeriesIdx / maColorPattern.size() );
818 double fShadeTint = static_cast< double >( nCycleIdx + 1 ) / (nMaxCycleIdx + 2) * 1.4 - 0.7;
819 if( fShadeTint != 0.0 )
821 Color aColor;
822 aColor.setSrgbClr( nPhClr );
823 aColor.addChartTintTransformation( fShadeTint );
824 nPhClr = aColor.getColor( mrData.mrFilter.getGraphicHelper() );
827 return nPhClr;
830 sal_Int32 DetailFormatterBase::getSchemeColor( sal_Int32 nColorToken, sal_Int32 nModToken, sal_Int32 nModValue ) const
832 Color aColor;
833 aColor.setSchemeClr( nColorToken );
834 if( nModToken != XML_TOKEN_INVALID )
835 aColor.addTransformation( nModToken, nModValue );
836 return aColor.getColor( mrData.mrFilter.getGraphicHelper() );
839 // ============================================================================
841 LineFormatter::LineFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) :
842 DetailFormatterBase( rData, pAutoFormatEntry )
844 if( pAutoFormatEntry )
846 mxAutoLine.reset( new LineProperties );
847 mxAutoLine->maLineFill.moFillType = XML_noFill;
848 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
849 if( const LineProperties* pLineProps = pTheme->getLineStyle( pAutoFormatEntry->mnThemedIdx ) )
850 *mxAutoLine = *pLineProps;
851 // change line width according to chart auto style
852 if( mxAutoLine->moLineWidth.has() )
853 mxAutoLine->moLineWidth = mxAutoLine->moLineWidth.get() * pAutoFormatEntry->mnRelLineWidth / 100;
857 void LineFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, sal_Int32 nSeriesIdx )
859 LineProperties aLineProps;
860 if( mxAutoLine.get() )
861 aLineProps.assignUsed( *mxAutoLine );
862 if( rxShapeProp.is() )
863 aLineProps.assignUsed( rxShapeProp->getLineProperties() );
864 aLineProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), getPhColor( nSeriesIdx ) );
867 // ============================================================================
869 FillFormatter::FillFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) :
870 DetailFormatterBase( rData, pAutoFormatEntry )
872 if( pAutoFormatEntry )
874 mxAutoFill.reset( new FillProperties );
875 mxAutoFill->moFillType = XML_noFill;
876 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
877 if( const FillProperties* pFillProps = pTheme->getFillStyle( pAutoFormatEntry->mnThemedIdx ) )
878 *mxAutoFill = *pFillProps;
882 void FillFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx )
884 FillProperties aFillProps;
885 if( mxAutoFill.get() )
886 aFillProps.assignUsed( *mxAutoFill );
887 if( rxShapeProp.is() )
888 aFillProps.assignUsed( rxShapeProp->getFillProperties() );
889 if( pPicOptions )
890 lclConvertPictureOptions( aFillProps, *pPicOptions );
891 aFillProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), 0, getPhColor( nSeriesIdx ) );
894 // ============================================================================
896 EffectFormatter::EffectFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) :
897 DetailFormatterBase( rData, pAutoFormatEntry )
900 //TODO :
901 void EffectFormatter::convertFormatting( ShapePropertyMap& /*rPropMap*/, const ModelRef< Shape >& /*rxShapeProp*/, sal_Int32 /*nSeriesIdx*/ ) const
905 // ============================================================================
907 namespace {
909 const TextCharacterProperties* lclGetTextProperties( const ModelRef< TextBody >& rxTextProp )
911 return (rxTextProp.is() && !rxTextProp->getParagraphs().empty()) ?
912 &rxTextProp->getParagraphs().front()->getProperties().getTextCharacterProperties() : 0;
915 } // namespace
917 TextFormatter::TextFormatter( ObjectFormatterData& rData, const AutoTextEntry* pAutoTextEntry, const ModelRef< TextBody >& rxGlobalTextProp ) :
918 DetailFormatterBase( rData, pAutoTextEntry )
920 if( pAutoTextEntry )
922 mxAutoText.reset( new TextCharacterProperties );
923 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
924 if( const TextCharacterProperties* pTextProps = pTheme->getFontStyle( pAutoTextEntry->mnThemedFont ) )
925 *mxAutoText = *pTextProps;
926 sal_Int32 nTextColor = getPhColor( -1 );
927 if( nTextColor >= 0 )
928 mxAutoText->maCharColor.setSrgbClr( nTextColor );
929 mxAutoText->moHeight = pAutoTextEntry->mnDefFontSize;
930 mxAutoText->moBold = pAutoTextEntry->mbBold;
932 if( const TextCharacterProperties* pTextProps = lclGetTextProperties( rxGlobalTextProp ) )
934 mxAutoText->assignUsed( *pTextProps );
935 if( pTextProps->moHeight.has() )
936 mxAutoText->moHeight = pTextProps->moHeight.get() * pAutoTextEntry->mnRelFontSize / 100;
941 void TextFormatter::convertFormatting( PropertySet& rPropSet, const TextCharacterProperties* pTextProps )
943 TextCharacterProperties aTextProps;
944 if( mxAutoText.get() )
945 aTextProps.assignUsed( *mxAutoText );
946 if( pTextProps )
947 aTextProps.assignUsed( *pTextProps );
948 aTextProps.pushToPropSet( rPropSet, mrData.mrFilter );
951 void TextFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp )
953 convertFormatting( rPropSet, lclGetTextProperties( rxTextProp ) );
956 // ============================================================================
958 ObjectTypeFormatter::ObjectTypeFormatter( ObjectFormatterData& rData, const ObjectTypeFormatEntry& rEntry, const ChartSpaceModel& rChartSpace ) :
959 maLineFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoLines, rChartSpace.mnStyle ) ),
960 maFillFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoFills, rChartSpace.mnStyle ) ),
961 maEffectFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoEffects, rChartSpace.mnStyle ) ),
962 maTextFormatter( rData, lclGetAutoTextEntry( rEntry.mpAutoTexts, rChartSpace.mnStyle ), rChartSpace.mxTextProp ),
963 mrModelObjHelper( rData.maModelObjHelper ),
964 mrEntry( rEntry )
968 void ObjectTypeFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx )
970 ShapePropertyMap aPropMap( mrModelObjHelper, *mrEntry.mpPropInfo );
971 maLineFormatter.convertFormatting( aPropMap, rxShapeProp, nSeriesIdx );
972 if( mrEntry.mbIsFrame )
973 maFillFormatter.convertFormatting( aPropMap, rxShapeProp, pPicOptions, nSeriesIdx );
974 maEffectFormatter.convertFormatting( aPropMap, rxShapeProp, nSeriesIdx );
975 rPropSet.setProperties( aPropMap );
978 void ObjectTypeFormatter::convertTextFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp )
980 maTextFormatter.convertFormatting( rPropSet, rxTextProp );
983 void ObjectTypeFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const ModelRef< TextBody >& rxTextProp )
985 convertFrameFormatting( rPropSet, rxShapeProp, 0, -1 );
986 convertTextFormatting( rPropSet, rxTextProp );
989 void ObjectTypeFormatter::convertTextFormatting( PropertySet& rPropSet, const TextCharacterProperties& rTextProps )
991 maTextFormatter.convertFormatting( rPropSet, &rTextProps );
994 void ObjectTypeFormatter::convertAutomaticFill( PropertySet& rPropSet, sal_Int32 nSeriesIdx )
996 ShapePropertyMap aPropMap( mrModelObjHelper, *mrEntry.mpPropInfo );
997 ModelRef< Shape > xShapeProp;
998 maFillFormatter.convertFormatting( aPropMap, xShapeProp, 0, nSeriesIdx );
999 maEffectFormatter.convertFormatting( aPropMap, xShapeProp, nSeriesIdx );
1000 rPropSet.setProperties( aPropMap );
1003 // ============================================================================
1005 ObjectFormatterData::ObjectFormatterData( const XmlFilterBase& rFilter, const Reference< XChartDocument >& rxChartDoc, const ChartSpaceModel& rChartSpace ) :
1006 mrFilter( rFilter ),
1007 maModelObjHelper( Reference< XMultiServiceFactory >( rxChartDoc, UNO_QUERY ) ),
1008 maEnUsLocale( "en", "US", OUString() ),
1009 mnMaxSeriesIdx( -1 )
1011 const ObjectTypeFormatEntry* pEntryEnd = STATIC_ARRAY_END( spObjTypeFormatEntries );
1012 for( const ObjectTypeFormatEntry* pEntry = spObjTypeFormatEntries; pEntry != pEntryEnd; ++pEntry )
1013 maTypeFormatters[ pEntry->meObjType ].reset( new ObjectTypeFormatter( *this, *pEntry, rChartSpace ) );
1017 Reference< XNumberFormatsSupplier > xNumFmtsSupp( rxChartDoc, UNO_QUERY_THROW );
1018 mxNumFmts = xNumFmtsSupp->getNumberFormats();
1019 mxNumTypes.set( mxNumFmts, UNO_QUERY );
1021 catch( Exception& )
1024 OSL_ENSURE( mxNumFmts.is() && mxNumTypes.is(), "ObjectFormatterData::ObjectFormatterData - cannot get number formats" );
1027 ObjectTypeFormatter* ObjectFormatterData::getTypeFormatter( ObjectType eObjType )
1029 OSL_ENSURE( maTypeFormatters.has( eObjType ), "ObjectFormatterData::getTypeFormatter - unknown object type" );
1030 return maTypeFormatters.get( eObjType ).get();
1033 // ============================================================================
1035 ObjectFormatter::ObjectFormatter( const XmlFilterBase& rFilter, const Reference< XChartDocument >& rxChartDoc, const ChartSpaceModel& rChartSpace ) :
1036 mxData( new ObjectFormatterData( rFilter, rxChartDoc, rChartSpace ) )
1040 ObjectFormatter::~ObjectFormatter()
1044 void ObjectFormatter::setMaxSeriesIndex( sal_Int32 nMaxSeriesIdx )
1046 mxData->mnMaxSeriesIdx = nMaxSeriesIdx;
1049 sal_Int32 ObjectFormatter::getMaxSeriesIndex() const
1051 return mxData->mnMaxSeriesIdx;
1054 void ObjectFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, ObjectType eObjType, sal_Int32 nSeriesIdx )
1056 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1057 pFormat->convertFrameFormatting( rPropSet, rxShapeProp, 0, nSeriesIdx );
1060 void ObjectFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel& rPicOptions, ObjectType eObjType, sal_Int32 nSeriesIdx )
1062 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1063 pFormat->convertFrameFormatting( rPropSet, rxShapeProp, &rPicOptions, nSeriesIdx );
1066 void ObjectFormatter::convertTextFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType )
1068 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1069 pFormat->convertTextFormatting( rPropSet, rxTextProp );
1072 void ObjectFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType )
1074 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1075 pFormat->convertFormatting( rPropSet, rxShapeProp, rxTextProp );
1078 void ObjectFormatter::convertTextFormatting( PropertySet& rPropSet, const TextCharacterProperties& rTextProps, ObjectType eObjType )
1080 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1081 pFormat->convertTextFormatting( rPropSet, rTextProps );
1084 void ObjectFormatter::convertTextRotation( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp, bool bSupportsStacked )
1086 if( rxTextProp.is() )
1088 bool bStacked = false;
1089 if( bSupportsStacked )
1091 sal_Int32 nVert = rxTextProp->getTextProperties().moVert.get( XML_horz );
1092 bStacked = (nVert == XML_wordArtVert) || (nVert == XML_wordArtVertRtl);
1093 rPropSet.setProperty( PROP_StackCharacters, bStacked );
1096 /* Chart2 expects rotation angle as double value in range of [0,360).
1097 OOXML counts clockwise, Chart2 counts counterclockwise. */
1098 double fAngle = static_cast< double >( bStacked ? 0 : rxTextProp->getTextProperties().moRotation.get( 0 ) );
1099 // MS Office UI allows values only in range of [-90,90].
1100 if ( fAngle <= -5400000.0 || fAngle >= 5400000.0 )
1102 fAngle = 0.0;
1104 fAngle = getDoubleIntervalValue< double >( -fAngle / 60000.0, 0.0, 360.0 );
1105 rPropSet.setProperty( PROP_TextRotation, fAngle );
1109 void ObjectFormatter::convertNumberFormat( PropertySet& rPropSet, const NumberFormat& rNumberFormat, bool bPercentFormat )
1111 if( mxData->mxNumFmts.is() )
1113 sal_Int32 nPropId = bPercentFormat ? PROP_PercentageNumberFormat : PROP_NumberFormat;
1114 if( rNumberFormat.mbSourceLinked || rNumberFormat.maFormatCode.isEmpty() )
1116 rPropSet.setAnyProperty( nPropId, Any() );
1118 else try
1120 sal_Int32 nIndex = rNumberFormat.maFormatCode.equalsIgnoreAsciiCase("general") ?
1121 mxData->mxNumTypes->getStandardIndex( mxData->maFromLocale ) :
1122 mxData->mxNumFmts->addNewConverted( rNumberFormat.maFormatCode, mxData->maEnUsLocale, mxData->maFromLocale );
1123 if( nIndex >= 0 )
1124 rPropSet.setProperty( nPropId, nIndex );
1126 catch( Exception& )
1128 OSL_FAIL( OStringBuffer( "ObjectFormatter::convertNumberFormat - cannot create number format '" ).
1129 append( OUStringToOString( rNumberFormat.maFormatCode, osl_getThreadTextEncoding() ) ).append( '\'' ).getStr() );
1134 void ObjectFormatter::convertAutomaticFill( PropertySet& rPropSet, ObjectType eObjType, sal_Int32 nSeriesIdx )
1136 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1137 pFormat->convertAutomaticFill( rPropSet, nSeriesIdx );
1140 bool ObjectFormatter::isAutomaticFill( const ModelRef< Shape >& rxShapeProp )
1142 return !rxShapeProp || !rxShapeProp->getFillProperties().moFillType.has();
1145 // ============================================================================
1147 } // namespace chart
1148 } // namespace drawingml
1149 } // namespace oox
1151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */