fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / drawingml / chart / objectformatter.cxx
blob0d6b971aee9e75c6547aa6fa92dc0705f2e8fa31
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 "drawingml/chart/objectformatter.hxx"
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
24 #include <com/sun/star/util/XNumberFormatTypes.hpp>
25 #include <osl/thread.h>
26 #include <osl/diagnose.h>
27 #include <rtl/strbuf.hxx>
28 #include "oox/core/xmlfilterbase.hxx"
29 #include "oox/drawingml/fillproperties.hxx"
30 #include "oox/drawingml/lineproperties.hxx"
31 #include "oox/drawingml/shapepropertymap.hxx"
32 #include "drawingml/textbody.hxx"
33 #include "drawingml/textparagraph.hxx"
34 #include "oox/drawingml/theme.hxx"
35 #include "drawingml/chart/chartspacemodel.hxx"
36 #include "oox/helper/modelobjecthelper.hxx"
37 #include <oox/helper/graphichelper.hxx>
39 namespace oox {
40 namespace drawingml {
41 namespace chart {
43 using namespace ::com::sun::star::chart2;
44 using namespace ::com::sun::star::frame;
45 using namespace ::com::sun::star::graphic;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::util;
50 using ::oox::core::XmlFilterBase;
52 namespace {
54 struct AutoFormatPatternEntry
56 sal_Int32 mnColorToken; /// Theme color token.
57 sal_Int32 mnModToken; /// Color modification token.
58 sal_Int32 mnModValue; /// Color modification value.
61 #define AUTOFORMAT_PATTERN_COLOR( color_token ) \
62 { color_token, XML_TOKEN_INVALID, 0 }
64 #define AUTOFORMAT_PATTERN_COLORMOD( color_token, mod_token, mod_value ) \
65 { color_token, mod_token, mod_value }
67 #define AUTOFORMAT_PATTERN_END() \
68 AUTOFORMAT_PATTERN_COLOR( XML_TOKEN_INVALID )
70 static const AutoFormatPatternEntry spAutoFormatPattern1[] =
72 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 88500 ),
73 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 55000 ),
74 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 78000 ),
75 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 92500 ),
76 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 70000 ),
77 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 30000 ),
78 AUTOFORMAT_PATTERN_END()
81 static const AutoFormatPatternEntry spAutoFormatPattern2[] =
83 AUTOFORMAT_PATTERN_COLOR( XML_accent1 ),
84 AUTOFORMAT_PATTERN_COLOR( XML_accent2 ),
85 AUTOFORMAT_PATTERN_COLOR( XML_accent3 ),
86 AUTOFORMAT_PATTERN_COLOR( XML_accent4 ),
87 AUTOFORMAT_PATTERN_COLOR( XML_accent5 ),
88 AUTOFORMAT_PATTERN_COLOR( XML_accent6 ),
89 AUTOFORMAT_PATTERN_END()
92 static const AutoFormatPatternEntry spAutoFormatPattern3[] =
94 AUTOFORMAT_PATTERN_COLORMOD( XML_accent1, XML_shade, 50000 ),
95 AUTOFORMAT_PATTERN_COLORMOD( XML_accent2, XML_shade, 50000 ),
96 AUTOFORMAT_PATTERN_COLORMOD( XML_accent3, XML_shade, 50000 ),
97 AUTOFORMAT_PATTERN_COLORMOD( XML_accent4, XML_shade, 50000 ),
98 AUTOFORMAT_PATTERN_COLORMOD( XML_accent5, XML_shade, 50000 ),
99 AUTOFORMAT_PATTERN_COLORMOD( XML_accent6, XML_shade, 50000 ),
100 AUTOFORMAT_PATTERN_END()
103 static const AutoFormatPatternEntry spAutoFormatPattern4[] =
105 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 5000 ),
106 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 55000 ),
107 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 78000 ),
108 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 15000 ),
109 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 70000 ),
110 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 30000 ),
111 AUTOFORMAT_PATTERN_END()
114 #undef AUTOFORMAT_PATTERN_COLOR
115 #undef AUTOFORMAT_PATTERN_COLORMOD
116 #undef AUTOFORMAT_PATTERN_END
118 struct AutoFormatEntry
120 sal_Int32 mnFirstStyleIdx; /// First chart style index.
121 sal_Int32 mnLastStyleIdx; /// Last chart style index.
122 sal_Int32 mnThemedIdx; /// Themed style index.
123 sal_Int32 mnColorToken; /// Theme color token.
124 sal_Int32 mnModToken; /// Color modification token.
125 sal_Int32 mnModValue; /// Color modification value.
126 sal_Int32 mnRelLineWidth; /// Relative line width (percent).
127 const AutoFormatPatternEntry* mpPattern;/// Color cycling pattern for data series.
128 bool mbFadedColor; /// True = Faded color for data series.
131 #define AUTOFORMAT_COLOR( first, last, themed_style, color_token ) \
132 { first, last, themed_style, color_token, XML_TOKEN_INVALID, 0, 100, 0, false }
134 #define AUTOFORMAT_COLORMOD( first, last, themed_style, color_token, mod_token, mod_value ) \
135 { first, last, themed_style, color_token, mod_token, mod_value, 100, 0, false }
137 #define AUTOFORMAT_ACCENTSMOD( first, themed_style, mod_token, mod_value ) \
138 AUTOFORMAT_COLORMOD( first, first, themed_style, XML_accent1, mod_token, mod_value ), \
139 AUTOFORMAT_COLORMOD( first + 1, first + 1, themed_style, XML_accent2, mod_token, mod_value ), \
140 AUTOFORMAT_COLORMOD( first + 2, first + 2, themed_style, XML_accent3, mod_token, mod_value ), \
141 AUTOFORMAT_COLORMOD( first + 3, first + 3, themed_style, XML_accent4, mod_token, mod_value ), \
142 AUTOFORMAT_COLORMOD( first + 4, first + 4, themed_style, XML_accent5, mod_token, mod_value ), \
143 AUTOFORMAT_COLORMOD( first + 5, first + 5, themed_style, XML_accent6, mod_token, mod_value )
145 #define AUTOFORMAT_PATTERN( first, last, themed_style, line_width, pattern ) \
146 { first, last, themed_style, XML_TOKEN_INVALID, XML_TOKEN_INVALID, 0, line_width, pattern, false }
148 #define AUTOFORMAT_FADED( first, last, themed_style, color_token, line_width ) \
149 { first, last, themed_style, color_token, XML_TOKEN_INVALID, 0, line_width, 0, true }
151 #define AUTOFORMAT_FADEDACCENTS( first, themed_style, line_width ) \
152 AUTOFORMAT_FADED( first, first, themed_style, XML_accent1, line_width ), \
153 AUTOFORMAT_FADED( first + 1, first + 1, themed_style, XML_accent2, line_width ), \
154 AUTOFORMAT_FADED( first + 2, first + 2, themed_style, XML_accent3, line_width ), \
155 AUTOFORMAT_FADED( first + 3, first + 3, themed_style, XML_accent4, line_width ), \
156 AUTOFORMAT_FADED( first + 4, first + 4, themed_style, XML_accent5, line_width ), \
157 AUTOFORMAT_FADED( first + 5, first + 5, themed_style, XML_accent6, line_width )
159 #define AUTOFORMAT_INVISIBLE( first, last ) \
160 AUTOFORMAT_COLOR( first, last, -1, XML_TOKEN_INVALID )
162 #define AUTOFORMAT_END() \
163 AUTOFORMAT_INVISIBLE( -1, -1 )
165 static const AutoFormatEntry spNoFormats[] =
167 AUTOFORMAT_INVISIBLE( 1, 48 ),
168 AUTOFORMAT_END()
171 static const AutoFormatEntry spChartSpaceFill[] =
173 AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_bg1 ),
174 AUTOFORMAT_COLOR( 33, 40, THEMED_STYLE_SUBTLE, XML_lt1 ),
175 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1 ),
176 AUTOFORMAT_END()
179 static const AutoFormatEntry spDataTableLines[] =
181 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ),
182 AUTOFORMAT_COLORMOD( 33, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ),
183 // 41...48: no line, same as Chart2
184 AUTOFORMAT_END()
187 static const AutoFormatEntry spPlotArea2dFills[] =
189 AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_bg1 ),
190 AUTOFORMAT_COLORMOD( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 20000 ),
191 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_tint, 20000 ), // tint not documented!?
192 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
193 AUTOFORMAT_END()
196 static const AutoFormatEntry spWallFloorLines[] =
198 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ),
199 AUTOFORMAT_COLORMOD( 33, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ),
200 // 41...48: no line, same as Chart2
201 AUTOFORMAT_END()
204 static const AutoFormatEntry spWallFloorFills[] =
206 AUTOFORMAT_INVISIBLE( 1, 32 ),
207 AUTOFORMAT_COLORMOD( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 20000 ),
208 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_tint, 20000 ), // tint not documented!?
209 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
210 AUTOFORMAT_END()
213 static const AutoFormatEntry spAxisLines[] =
215 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), // tint not documented!?
216 AUTOFORMAT_COLORMOD( 33, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), // tint not documented!?
217 AUTOFORMAT_END()
220 static const AutoFormatEntry spMajorGridLines[] =
222 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), // tint not documented!?
223 AUTOFORMAT_COLORMOD( 33, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), // tint not documented!?
224 AUTOFORMAT_END()
227 static const AutoFormatEntry spMinorGridLines[] =
229 AUTOFORMAT_COLORMOD( 1, 40, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 50000 ),
230 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 90000 ),
231 AUTOFORMAT_END()
234 static const AutoFormatEntry spOtherLines[] =
236 AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1 ),
237 AUTOFORMAT_COLOR( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1 ),
238 AUTOFORMAT_COLORMOD( 35, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_shade, 25000 ),
239 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_SUBTLE, XML_lt1 ),
240 AUTOFORMAT_END()
243 static const AutoFormatEntry spLinearSeriesLines[] =
245 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 300, spAutoFormatPattern1 ),
246 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 300, spAutoFormatPattern2 ),
247 AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 300 ),
248 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
249 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
250 AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 500 ),
251 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
252 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
253 AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_SUBTLE, 500 ),
254 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_SUBTLE, 700, spAutoFormatPattern1 ),
255 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_SUBTLE, 700, spAutoFormatPattern2 ),
256 AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_SUBTLE, 700 ),
257 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
258 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
259 AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 500 ),
260 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern4 ),
261 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
262 AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_SUBTLE, 500 ),
263 AUTOFORMAT_END()
266 static const AutoFormatEntry spFilledSeriesLines[] =
268 AUTOFORMAT_INVISIBLE( 1, 8 ),
269 AUTOFORMAT_COLOR( 9, 16, THEMED_STYLE_SUBTLE, XML_lt1 ),
270 AUTOFORMAT_INVISIBLE( 17, 32 ),
271 AUTOFORMAT_COLORMOD( 33, 33, THEMED_STYLE_SUBTLE, XML_dk1, XML_shade, 50000 ),
272 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern3 ),
273 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 50000 ),
274 AUTOFORMAT_INVISIBLE( 41, 48 ),
275 AUTOFORMAT_END()
278 static const AutoFormatEntry spFilledSeries2dFills[] =
280 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
281 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
282 AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 100 ),
283 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
284 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
285 AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 100 ),
286 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern1 ),
287 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
288 AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_INTENSE, 100 ),
289 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern1 ),
290 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
291 AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_INTENSE, 100 ),
292 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
293 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
294 AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 100 ),
295 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern4 ),
296 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
297 AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_INTENSE, 100 ),
298 AUTOFORMAT_END()
301 static const AutoFormatEntry spFilledSeries3dFills[] =
303 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
304 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
305 AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 100 ),
306 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
307 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
308 AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 100 ),
309 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
310 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
311 AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_SUBTLE, 100 ),
312 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
313 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
314 AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_SUBTLE, 100 ),
315 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
316 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
317 AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 100 ),
318 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern4 ),
319 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
320 AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_SUBTLE, 100 ),
321 AUTOFORMAT_END()
324 static const AutoFormatEntry spFilledSeriesEffects[] =
326 // 1...8: no effect, same as Chart2
327 AUTOFORMAT_COLOR( 9, 16, THEMED_STYLE_SUBTLE, XML_dk1 ),
328 AUTOFORMAT_COLOR( 17, 24, THEMED_STYLE_MODERATE, XML_dk1 ),
329 AUTOFORMAT_COLOR( 25, 32, THEMED_STYLE_INTENSE, XML_dk1 ),
330 // 33...40: no effect, same as Chart2
331 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_INTENSE, XML_dk1 ),
332 AUTOFORMAT_END()
335 static const AutoFormatEntry spUpDownBarLines[] =
337 AUTOFORMAT_COLOR( 1, 16, THEMED_STYLE_SUBTLE, XML_tx1 ),
338 AUTOFORMAT_INVISIBLE( 17, 32 ),
339 AUTOFORMAT_COLOR( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1 ),
340 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
341 AUTOFORMAT_INVISIBLE( 41, 48 ),
342 AUTOFORMAT_END()
345 static const AutoFormatEntry spUpBarFills[] =
347 AUTOFORMAT_COLORMOD( 1, 1, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 25000 ),
348 AUTOFORMAT_COLORMOD( 2, 2, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 5000 ),
349 AUTOFORMAT_ACCENTSMOD( 3, THEMED_STYLE_SUBTLE, XML_tint, 25000 ),
350 AUTOFORMAT_COLORMOD( 9, 9, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 25000 ),
351 AUTOFORMAT_COLORMOD( 10, 10, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 5000 ),
352 AUTOFORMAT_ACCENTSMOD( 11, THEMED_STYLE_SUBTLE, XML_tint, 25000 ),
353 AUTOFORMAT_COLORMOD( 17, 17, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
354 AUTOFORMAT_COLORMOD( 18, 18, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 5000 ),
355 AUTOFORMAT_ACCENTSMOD( 19, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
356 AUTOFORMAT_COLORMOD( 25, 25, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
357 AUTOFORMAT_COLORMOD( 26, 26, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 5000 ),
358 AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
359 AUTOFORMAT_COLOR( 33, 40, THEMED_STYLE_SUBTLE, XML_lt1 ),
360 AUTOFORMAT_COLORMOD( 41, 41, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
361 AUTOFORMAT_COLOR( 42, 42, THEMED_STYLE_INTENSE, XML_lt1 ),
362 AUTOFORMAT_ACCENTSMOD( 43, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
363 AUTOFORMAT_END()
366 static const AutoFormatEntry spDownBarFills[] =
368 AUTOFORMAT_COLORMOD( 1, 1, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
369 AUTOFORMAT_COLORMOD( 2, 2, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
370 AUTOFORMAT_ACCENTSMOD( 3, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
371 AUTOFORMAT_COLORMOD( 9, 9, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
372 AUTOFORMAT_COLORMOD( 10, 10, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
373 AUTOFORMAT_ACCENTSMOD( 11, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
374 AUTOFORMAT_COLORMOD( 17, 17, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
375 AUTOFORMAT_COLORMOD( 18, 18, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 95000 ),
376 AUTOFORMAT_ACCENTSMOD( 19, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
377 AUTOFORMAT_COLORMOD( 25, 25, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
378 AUTOFORMAT_COLORMOD( 26, 26, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 95000 ),
379 AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
380 AUTOFORMAT_COLORMOD( 33, 33, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
381 AUTOFORMAT_COLORMOD( 34, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
382 AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
383 AUTOFORMAT_COLORMOD( 41, 41, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
384 AUTOFORMAT_COLOR( 42, 42, THEMED_STYLE_INTENSE, XML_dk1 ),
385 AUTOFORMAT_ACCENTSMOD( 43, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
386 AUTOFORMAT_END()
389 static const AutoFormatEntry spUpDownBarEffects[] =
391 // 1...8: no effect, same as Chart2
392 AUTOFORMAT_COLOR( 9, 16, THEMED_STYLE_SUBTLE, XML_dk1 ),
393 AUTOFORMAT_COLOR( 17, 24, THEMED_STYLE_MODERATE, XML_dk1 ),
394 AUTOFORMAT_COLOR( 25, 32, THEMED_STYLE_INTENSE, XML_dk1 ),
395 // 33...40: no effect, same as Chart2
396 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_INTENSE, XML_dk1 ),
397 AUTOFORMAT_END()
400 #undef AUTOFORMAT_COLOR
401 #undef AUTOFORMAT_COLORMOD
402 #undef AUTOFORMAT_ACCENTSMOD
403 #undef AUTOFORMAT_PATTERN
404 #undef AUTOFORMAT_FADED
405 #undef AUTOFORMAT_FADEDACCENTS
406 #undef AUTOFORMAT_INVISIBLE
407 #undef AUTOFORMAT_END
409 const AutoFormatEntry* lclGetAutoFormatEntry( const AutoFormatEntry* pEntries, sal_Int32 nStyle )
411 for( ; pEntries && (pEntries->mnFirstStyleIdx >= 0); ++pEntries )
412 if( (pEntries->mnFirstStyleIdx <= nStyle) && (nStyle <= pEntries->mnLastStyleIdx) )
413 return pEntries;
414 return 0;
417 struct AutoTextEntry
419 sal_Int32 mnFirstStyleIdx; /// First chart style index.
420 sal_Int32 mnLastStyleIdx; /// Last chart style index.
421 sal_Int32 mnThemedFont; /// Themed font (minor/major).
422 sal_Int32 mnColorToken; /// Theme color token.
423 sal_Int32 mnDefFontSize; /// Default font size (1/100 points).
424 sal_Int32 mnRelFontSize; /// Font size relative to chart global font (percent).
425 bool mbBold; /// True = bold font.
428 #define AUTOTEXT_COLOR( first, last, themed_font, color_token, def_font_size, rel_font_size, bold ) \
429 { first, last, themed_font, color_token, def_font_size, rel_font_size, bold }
431 #define AUTOTEXT_END() \
432 AUTOTEXT_COLOR( -1, -1, XML_none, XML_TOKEN_INVALID, 1000, 100, false )
434 static const AutoTextEntry spChartTitleTexts[] =
436 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1800, 120, true ),
437 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1800, 120, true ),
438 AUTOTEXT_END()
441 static const AutoTextEntry spAxisTitleTexts[] =
443 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1000, 100, true ),
444 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1000, 100, true ),
445 AUTOTEXT_END()
448 static const AutoTextEntry spOtherTexts[] =
450 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1000, 100, false ),
451 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1000, 100, false ),
452 AUTOTEXT_END()
455 #undef AUTOTEXT_COLOR
456 #undef AUTOTEXT_END
458 const AutoTextEntry* lclGetAutoTextEntry( const AutoTextEntry* pEntries, sal_Int32 nStyle )
460 for( ; pEntries && (pEntries->mnFirstStyleIdx >= 0); ++pEntries )
461 if( (pEntries->mnFirstStyleIdx <= nStyle) && (nStyle <= pEntries->mnLastStyleIdx) )
462 return pEntries;
463 return 0;
466 // These PropIds arrays will be indexed into using a ShapePropertyId enum (include/oox/drawingml/shapepropertymap.hxx)
468 /** Property identifiers for common chart objects, to be used in ShapePropertyInfo. */
469 static const sal_Int32 spnCommonPropIds[] =
471 PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDashName,
472 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
473 PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_INVALID, PROP_FillGradientName,
474 PROP_FillBitmapName, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
475 PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint,
476 PROP_END_LIST
479 /** Property identifiers for linear data series, to be used in ShapePropertyInfo. */
480 static const sal_Int32 spnLinearPropIds[] =
482 PROP_LineStyle, PROP_LineWidth, PROP_Color, PROP_Transparency, PROP_LineDashName,
483 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
484 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
485 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
486 PROP_INVALID, PROP_INVALID, PROP_INVALID,
487 PROP_END_LIST
490 /** Property identifiers for filled data series, to be used in ShapePropertyInfo. */
491 static const sal_Int32 spnFilledPropIds[] =
493 PROP_BorderStyle,
494 PROP_BorderWidth,
495 PROP_BorderColor,
496 PROP_BorderTransparency,
497 PROP_BorderDashName,
498 PROP_INVALID,
499 PROP_INVALID,
500 PROP_INVALID,
501 PROP_INVALID,
502 PROP_INVALID,
503 PROP_INVALID,
504 PROP_INVALID,
505 PROP_FillStyle,
506 PROP_Color,
507 PROP_Transparency,
508 PROP_FillTransparenceGradientName,
509 PROP_GradientName,
510 PROP_FillBitmapName,
511 PROP_FillBitmapMode,
512 PROP_FillBitmapSizeX,
513 PROP_FillBitmapSizeY,
514 PROP_FillBitmapPositionOffsetX,
515 PROP_FillBitmapPositionOffsetY,
516 PROP_FillBitmapRectanglePoint,
517 PROP_FillHatch,
518 PROP_END_LIST
521 /** Property info for common chart objects, to be used in ShapePropertyMap. */
522 static const ShapePropertyInfo saCommonPropInfo( spnCommonPropIds, false, true, true, true );
523 /** Property info for linear data series, to be used in ShapePropertyMap. */
524 static const ShapePropertyInfo saLinearPropInfo( spnLinearPropIds, false, true, true, true );
525 /** Property info for filled data series, to be used in ShapePropertyMap. */
526 static const ShapePropertyInfo saFilledPropInfo( spnFilledPropIds, false, true, true, true );
528 /** Contains information about formatting of a specific chart object type. */
529 struct ObjectTypeFormatEntry
531 ObjectType meObjType; /// Object type for automatic format.
532 const ShapePropertyInfo* mpPropInfo; /// Property info for the ShapePropertyMap class.
533 const AutoFormatEntry* mpAutoLines; /// Automatic line formatting for all chart styles.
534 const AutoFormatEntry* mpAutoFills; /// Automatic fill formatting for all chart styles.
535 const AutoFormatEntry* mpAutoEffects; /// Automatic effect formatting for all chart styles.
536 const AutoTextEntry* mpAutoTexts; /// Automatic text attributes for all chart styles.
537 bool mbIsFrame; /// True = object is a frame, false = object is a line.
540 #define TYPEFORMAT_FRAME( obj_type, prop_type, auto_texts, auto_lines, auto_fills, auto_effects ) \
541 { obj_type, prop_type, auto_lines, auto_fills, auto_effects, auto_texts, true }
543 #define TYPEFORMAT_LINE( obj_type, prop_type, auto_texts, auto_lines ) \
544 { obj_type, prop_type, auto_lines, 0, 0, auto_texts, false }
546 static const ObjectTypeFormatEntry spObjTypeFormatEntries[] =
548 // object type property info auto text auto line auto fill auto effect
549 TYPEFORMAT_FRAME( OBJECTTYPE_CHARTSPACE, &saCommonPropInfo, 0, spNoFormats, spChartSpaceFill, 0 /* eq to Ch2 */ ),
550 TYPEFORMAT_FRAME( OBJECTTYPE_CHARTTITLE, &saCommonPropInfo, spChartTitleTexts, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
551 TYPEFORMAT_FRAME( OBJECTTYPE_LEGEND, &saCommonPropInfo, spOtherTexts, spNoFormats, spNoFormats, 0 /* eq to Ch2 */ ),
552 TYPEFORMAT_FRAME( OBJECTTYPE_PLOTAREA2D, &saCommonPropInfo, 0, 0 /* eq to Ch2 */, spPlotArea2dFills, 0 /* eq to Ch2 */ ),
553 TYPEFORMAT_FRAME( OBJECTTYPE_PLOTAREA3D, &saCommonPropInfo, 0, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
554 TYPEFORMAT_FRAME( OBJECTTYPE_WALL, &saCommonPropInfo, 0, spWallFloorLines, spWallFloorFills, 0 /* eq to Ch2 */ ),
555 TYPEFORMAT_FRAME( OBJECTTYPE_FLOOR, &saCommonPropInfo, 0, spWallFloorLines, spWallFloorFills, 0 /* eq to Ch2 */ ),
556 TYPEFORMAT_LINE( OBJECTTYPE_AXIS, &saCommonPropInfo, spOtherTexts, spAxisLines ),
557 TYPEFORMAT_FRAME( OBJECTTYPE_AXISTITLE, &saCommonPropInfo, spAxisTitleTexts, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
558 TYPEFORMAT_FRAME( OBJECTTYPE_AXISUNIT, &saCommonPropInfo, spAxisTitleTexts, 0 /* eq in Ch2 */, 0 /* eq in Ch2 */, 0 /* eq in Ch2 */ ),
559 TYPEFORMAT_LINE( OBJECTTYPE_MAJORGRIDLINE, &saCommonPropInfo, 0, spMajorGridLines ),
560 TYPEFORMAT_LINE( OBJECTTYPE_MINORGRIDLINE, &saCommonPropInfo, 0, spMinorGridLines ),
561 TYPEFORMAT_LINE( OBJECTTYPE_LINEARSERIES2D, &saLinearPropInfo, 0, spLinearSeriesLines ),
562 TYPEFORMAT_FRAME( OBJECTTYPE_FILLEDSERIES2D, &saFilledPropInfo, 0, spFilledSeriesLines, spFilledSeries2dFills, spFilledSeriesEffects ),
563 TYPEFORMAT_FRAME( OBJECTTYPE_FILLEDSERIES3D, &saFilledPropInfo, 0, spFilledSeriesLines, spFilledSeries3dFills, spFilledSeriesEffects ),
564 TYPEFORMAT_FRAME( OBJECTTYPE_DATALABEL, &saCommonPropInfo, spOtherTexts, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
565 TYPEFORMAT_LINE( OBJECTTYPE_TRENDLINE, &saCommonPropInfo, 0, spOtherLines ),
566 TYPEFORMAT_FRAME( OBJECTTYPE_TRENDLINELABEL, &saCommonPropInfo, spOtherTexts, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */, 0 /* eq to Ch2 */ ),
567 TYPEFORMAT_LINE( OBJECTTYPE_ERRORBAR, &saCommonPropInfo, 0, spOtherLines ),
568 TYPEFORMAT_LINE( OBJECTTYPE_SERLINE, &saCommonPropInfo, 0, spOtherLines ),
569 TYPEFORMAT_LINE( OBJECTTYPE_LEADERLINE, &saCommonPropInfo, 0, spOtherLines ),
570 TYPEFORMAT_LINE( OBJECTTYPE_DROPLINE, &saCommonPropInfo, 0, spOtherLines ),
571 TYPEFORMAT_LINE( OBJECTTYPE_HILOLINE, &saLinearPropInfo, 0, spOtherLines ),
572 TYPEFORMAT_FRAME( OBJECTTYPE_UPBAR, &saCommonPropInfo, 0, spUpDownBarLines, spUpBarFills, spUpDownBarEffects ),
573 TYPEFORMAT_FRAME( OBJECTTYPE_DOWNBAR, &saCommonPropInfo, 0, spUpDownBarLines, spDownBarFills, spUpDownBarEffects ),
574 TYPEFORMAT_LINE( OBJECTTYPE_DATATABLE, &saCommonPropInfo, spOtherTexts, spDataTableLines )
577 #undef TYPEFORMAT_FRAME
578 #undef TYPEFORMAT_LINE
580 void lclConvertPictureOptions( FillProperties& orFillProps, const PictureOptionsModel& rPicOptions )
582 bool bStacked = (rPicOptions.mnPictureFormat == XML_stack) || (rPicOptions.mnPictureFormat == XML_stackScale);
583 orFillProps.maBlipProps.moBitmapMode = bStacked ? XML_tile : XML_stretch;
586 } // namespace
588 struct ObjectFormatterData;
590 class DetailFormatterBase
592 public:
593 explicit DetailFormatterBase(
594 ObjectFormatterData& rData,
595 const AutoFormatEntry* pAutoFormatEntry );
596 explicit DetailFormatterBase(
597 ObjectFormatterData& rData,
598 const AutoTextEntry* pAutoTextEntry );
600 protected:
601 /** Returns the placeholder color which may depend on the passed series index. */
602 sal_Int32 getPhColor( sal_Int32 nSeriesIdx ) const;
604 private:
605 /** Resolves and returns the scheme color with the passed transformation. */
606 sal_Int32 getSchemeColor( sal_Int32 nColorToken, sal_Int32 nModToken, sal_Int32 nModValue ) const;
608 protected:
609 typedef ::std::vector< sal_Int32 > ColorPatternVec;
611 ObjectFormatterData& mrData; /// Shared formatter data.
612 sal_Int32 mnPhClr; /// RGB placeholder color for themed style.
613 ColorPatternVec maColorPattern; /// Different cycling colors for data series.
616 class LineFormatter : public DetailFormatterBase
618 public:
619 explicit LineFormatter(
620 ObjectFormatterData& rData,
621 const AutoFormatEntry* pAutoFormatEntry );
623 /** Converts line formatting to the passed property set. */
624 void convertFormatting(
625 ShapePropertyMap& rPropMap,
626 const ModelRef< Shape >& rxShapeProp,
627 sal_Int32 nSeriesIdx );
629 private:
630 LinePropertiesPtr mxAutoLine; /// Automatic line properties.
633 class FillFormatter : public DetailFormatterBase
635 public:
636 explicit FillFormatter(
637 ObjectFormatterData& rData,
638 const AutoFormatEntry* pAutoFormatEntry,
639 const ObjectType eObjType );
641 /** Converts area formatting to the passed property set. */
642 void convertFormatting(
643 ShapePropertyMap& rPropMap,
644 const ModelRef< Shape >& rxShapeProp,
645 const PictureOptionsModel* pPicOptions,
646 sal_Int32 nSeriesIdx );
648 private:
649 FillPropertiesPtr mxAutoFill; /// Automatic fill properties.
652 class EffectFormatter : public DetailFormatterBase
654 public:
655 explicit EffectFormatter(
656 ObjectFormatterData& rData,
657 const AutoFormatEntry* pAutoFormatEntry );
661 class TextFormatter : public DetailFormatterBase
663 public:
664 explicit TextFormatter(
665 ObjectFormatterData& rData,
666 const AutoTextEntry* pAutoTextEntry,
667 const ModelRef< TextBody >& rxGlobalTextProp );
669 /** Converts text formatting to the passed property set. */
670 void convertFormatting(
671 PropertySet& rPropSet,
672 const TextCharacterProperties* pTextProps );
673 /** Converts text formatting to the passed property set. */
674 void convertFormatting(
675 PropertySet& rPropSet,
676 const ModelRef< TextBody >& rxTextProp );
678 private:
679 TextCharacterPropertiesPtr mxAutoText; /// Automatic text properties.
682 /** Formatter for a specific object type. */
683 class ObjectTypeFormatter
685 public:
686 explicit ObjectTypeFormatter(
687 ObjectFormatterData& rData,
688 const ObjectTypeFormatEntry& rEntry,
689 const ChartSpaceModel& rChartSpace,
690 const ObjectType eObjType );
692 /** Sets frame formatting properties to the passed property set. */
693 void convertFrameFormatting(
694 PropertySet& rPropSet,
695 const ModelRef< Shape >& rxShapeProp,
696 const PictureOptionsModel* pPicOptions,
697 sal_Int32 nSeriesIdx );
699 /** Sets text formatting properties to the passed property set. */
700 void convertTextFormatting(
701 PropertySet& rPropSet,
702 const ModelRef< TextBody >& rxTextProp );
704 /** Sets frame/text formatting properties to the passed property set. */
705 void convertFormatting(
706 PropertySet& rPropSet,
707 const ModelRef< Shape >& rxShapeProp,
708 const ModelRef< TextBody >& rxTextProp );
710 /** Sets text formatting properties to the passed property set. */
711 void convertTextFormatting(
712 PropertySet& rPropSet,
713 const TextCharacterProperties& rTextProps );
715 /** Sets automatic fill properties to the passed property set. */
716 void convertAutomaticFill(
717 PropertySet& rPropSet,
718 sal_Int32 nSeriesIdx );
720 private:
721 LineFormatter maLineFormatter; /// Converter for line formatting.
722 FillFormatter maFillFormatter; /// Converter for fill formatting.
723 EffectFormatter maEffectFormatter; /// Converter for effect formatting.
724 TextFormatter maTextFormatter; /// Converter for text formatting.
725 ModelObjectHelper& mrModelObjHelper; /// Helper for named drawing formatting.
726 const ObjectTypeFormatEntry& mrEntry; /// Additional settings.
729 struct ObjectFormatterData
731 typedef RefMap< ObjectType, ObjectTypeFormatter > ObjectTypeFormatterMap;
733 const XmlFilterBase& mrFilter; /// Base filter object.
734 ObjectTypeFormatterMap maTypeFormatters; /// Formatters for all types of objects in a chart.
735 ModelObjectHelper maModelObjHelper; /// Helper for named drawing formatting (dashes, gradients, bitmaps).
736 Reference< XNumberFormats > mxNumFmts; /// Number formats collection of container document.
737 Reference< XNumberFormatTypes > mxNumTypes; /// Number format types collection of container document.
738 Locale maEnUsLocale; /// Locale struct containing en-US.
739 Locale maFromLocale; /// Empty locale struct.
740 sal_Int32 mnMaxSeriesIdx; /// Maximum series index used for color cycling/fading.
742 explicit ObjectFormatterData(
743 const XmlFilterBase& rFilter,
744 const Reference< XChartDocument >& rxChartDoc,
745 const ChartSpaceModel& rChartSpace );
747 ObjectTypeFormatter* getTypeFormatter( ObjectType eObjType );
750 DetailFormatterBase::DetailFormatterBase( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) :
751 mrData( rData ),
752 mnPhClr( -1 )
754 if( pAutoFormatEntry )
756 if( pAutoFormatEntry->mpPattern )
758 // prepare multi-color pattern
759 for( const AutoFormatPatternEntry* pPatternEntry = pAutoFormatEntry->mpPattern; pPatternEntry->mnColorToken != XML_TOKEN_INVALID; ++pPatternEntry )
760 maColorPattern.push_back( getSchemeColor( pPatternEntry->mnColorToken, pPatternEntry->mnModToken, pPatternEntry->mnModValue ) );
762 else if( pAutoFormatEntry->mnColorToken != XML_TOKEN_INVALID )
764 // prepare color or single-color pattern (color fading)
765 mnPhClr = getSchemeColor( pAutoFormatEntry->mnColorToken, pAutoFormatEntry->mnModToken, pAutoFormatEntry->mnModValue );
766 if( pAutoFormatEntry->mbFadedColor )
767 maColorPattern.push_back( mnPhClr );
772 DetailFormatterBase::DetailFormatterBase( ObjectFormatterData& rData, const AutoTextEntry* pAutoTextEntry ) :
773 mrData( rData ),
774 mnPhClr( -1 )
776 if( pAutoTextEntry && (pAutoTextEntry->mnColorToken != XML_TOKEN_INVALID) )
777 mnPhClr = getSchemeColor( pAutoTextEntry->mnColorToken, XML_TOKEN_INVALID, 0 );
780 sal_Int32 DetailFormatterBase::getPhColor( sal_Int32 nSeriesIdx ) const
782 if( maColorPattern.empty() || (mrData.mnMaxSeriesIdx < 0) || (nSeriesIdx < 0) )
783 return mnPhClr;
785 /* Apply tint/shade depending on the cycle index. The colors of leading
786 series are darkened (color shade), the colors of trailing series are
787 lightened (color tint). Shade/tint is applied in an exclusive range of
788 -70% to 70%.
790 Example 1: 3 data series using single-color shading with accent color 1
791 (e.g. automatic chart style #3). Shade/tint is applied per series.
792 Shade/tint changes in steps of 140%/(<series_count+1) = 140%/4 = 35%,
793 starting at -70%:
794 Step 1: -70% -> Not used.
795 Step 2: -35% -> Series 1 has 35% shade of accent color 1.
796 Step 3: 0% -> Series 2 has pure accent color 1.
797 Step 4: 35% -> Series 3 has 35% tint of accent color 1.
798 Step 5: 70% -> Not used.
800 Example 2: 20 data series using accent color pattern (e.g. automatic
801 chart style #2). Each color cycle has a size of 6 series (accent colors
802 1 to 6). Shade/tint is applied per color cycle.
803 Cycle #1: Series 1...6 are based on accent colors 1 to 6.
804 Cycle #2: Series 7...12 are based on accent colors 1 to 6.
805 Cycle #3: Series 13...18 are based on accent colors 1 to 6.
806 Cycle #4: Series 19...20 are based on accent colors 1 to 2.
807 Shade/tint changes in steps of 140%/(cycle_count+1) = 140%/5 = 28%,
808 starting at -70%:
809 Step 1: -70% -> Not used.
810 Step 2: -42% -> Cycle #1 has 42% shade of accent colors 1...6
811 step 3: -14% -> Cycle #2 has 14% shade of accent colors 1...6
812 step 4: 14% -> Cycle #3 has 14% tint of accent colors 1...6
813 step 5: 42% -> Cycle #4 has 42% tint of accent colors 1...6
814 step 6: 70% -> Not used.
816 sal_Int32 nPhClr = maColorPattern[ static_cast< size_t >( nSeriesIdx % maColorPattern.size() ) ];
817 size_t nCycleIdx = static_cast< size_t >( nSeriesIdx / maColorPattern.size() );
818 size_t nMaxCycleIdx = static_cast< size_t >( mrData.mnMaxSeriesIdx / maColorPattern.size() );
819 double fShadeTint = static_cast< double >( nCycleIdx + 1 ) / (nMaxCycleIdx + 2) * 1.4 - 0.7;
820 if( fShadeTint != 0.0 )
822 Color aColor;
823 aColor.setSrgbClr( nPhClr );
824 aColor.addChartTintTransformation( fShadeTint );
825 nPhClr = aColor.getColor( mrData.mrFilter.getGraphicHelper() );
828 return nPhClr;
831 sal_Int32 DetailFormatterBase::getSchemeColor( sal_Int32 nColorToken, sal_Int32 nModToken, sal_Int32 nModValue ) const
833 Color aColor;
834 aColor.setSchemeClr( nColorToken );
835 if( nModToken != XML_TOKEN_INVALID )
836 aColor.addTransformation( nModToken, nModValue );
837 return aColor.getColor( mrData.mrFilter.getGraphicHelper() );
840 LineFormatter::LineFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) :
841 DetailFormatterBase( rData, pAutoFormatEntry )
843 if( pAutoFormatEntry )
845 mxAutoLine.reset( new LineProperties );
846 mxAutoLine->maLineFill.moFillType = XML_noFill;
847 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
848 if( const LineProperties* pLineProps = pTheme->getLineStyle( pAutoFormatEntry->mnThemedIdx ) )
849 *mxAutoLine = *pLineProps;
850 // change line width according to chart auto style
851 if( mxAutoLine->moLineWidth.has() )
852 mxAutoLine->moLineWidth = mxAutoLine->moLineWidth.get() * pAutoFormatEntry->mnRelLineWidth / 100;
856 void LineFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, sal_Int32 nSeriesIdx )
858 LineProperties aLineProps;
859 if( mxAutoLine.get() )
860 aLineProps.assignUsed( *mxAutoLine );
861 if( rxShapeProp.is() )
862 aLineProps.assignUsed( rxShapeProp->getLineProperties() );
863 aLineProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), getPhColor( nSeriesIdx ) );
866 FillFormatter::FillFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry, const ObjectType eObjType ) :
867 DetailFormatterBase( rData, pAutoFormatEntry )
869 if( pAutoFormatEntry )
871 mxAutoFill.reset( new FillProperties );
872 if( eObjType != OBJECTTYPE_CHARTSPACE )
873 mxAutoFill->moFillType = XML_noFill;
874 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
875 if( const FillProperties* pFillProps = pTheme->getFillStyle( pAutoFormatEntry->mnThemedIdx ) )
876 *mxAutoFill = *pFillProps;
878 if (eObjType == OBJECTTYPE_CHARTSPACE)
880 mxAutoFill->moFillType = rData.mrFilter.getGraphicHelper().getDefaultChartAreaFillStyle();
885 void FillFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx )
887 FillProperties aFillProps;
888 if( mxAutoFill.get() )
889 aFillProps.assignUsed( *mxAutoFill );
890 if( rxShapeProp.is() )
891 aFillProps.assignUsed( rxShapeProp->getFillProperties() );
892 if( pPicOptions )
893 lclConvertPictureOptions( aFillProps, *pPicOptions );
894 aFillProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), 0, getPhColor( nSeriesIdx ) );
897 EffectFormatter::EffectFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) :
898 DetailFormatterBase( rData, pAutoFormatEntry )
902 namespace {
904 const TextCharacterProperties* lclGetTextProperties( const ModelRef< TextBody >& rxTextProp )
906 return (rxTextProp.is() && !rxTextProp->getParagraphs().empty()) ?
907 &rxTextProp->getParagraphs().front()->getProperties().getTextCharacterProperties() : 0;
910 } // namespace
912 TextFormatter::TextFormatter( ObjectFormatterData& rData, const AutoTextEntry* pAutoTextEntry, const ModelRef< TextBody >& rxGlobalTextProp ) :
913 DetailFormatterBase( rData, pAutoTextEntry )
915 if( pAutoTextEntry )
917 mxAutoText.reset( new TextCharacterProperties );
918 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
919 if( const TextCharacterProperties* pTextProps = pTheme->getFontStyle( pAutoTextEntry->mnThemedFont ) )
920 *mxAutoText = *pTextProps;
921 sal_Int32 nTextColor = getPhColor( -1 );
922 if( nTextColor >= 0 )
923 mxAutoText->maCharColor.setSrgbClr( nTextColor );
924 mxAutoText->moHeight = pAutoTextEntry->mnDefFontSize;
925 mxAutoText->moBold = pAutoTextEntry->mbBold;
927 if( const TextCharacterProperties* pTextProps = lclGetTextProperties( rxGlobalTextProp ) )
929 mxAutoText->assignUsed( *pTextProps );
930 if( pTextProps->moHeight.has() )
931 mxAutoText->moHeight = pTextProps->moHeight.get() * pAutoTextEntry->mnRelFontSize / 100;
936 void TextFormatter::convertFormatting( PropertySet& rPropSet, const TextCharacterProperties* pTextProps )
938 TextCharacterProperties aTextProps;
939 if( mxAutoText.get() )
940 aTextProps.assignUsed( *mxAutoText );
941 if( pTextProps )
942 aTextProps.assignUsed( *pTextProps );
943 aTextProps.pushToPropSet( rPropSet, mrData.mrFilter );
946 void TextFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp )
948 convertFormatting( rPropSet, lclGetTextProperties( rxTextProp ) );
951 ObjectTypeFormatter::ObjectTypeFormatter( ObjectFormatterData& rData, const ObjectTypeFormatEntry& rEntry, const ChartSpaceModel& rChartSpace, const ObjectType eObjType ) :
952 maLineFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoLines, rChartSpace.mnStyle ) ),
953 maFillFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoFills, rChartSpace.mnStyle ), eObjType ),
954 maEffectFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoEffects, rChartSpace.mnStyle ) ),
955 maTextFormatter( rData, lclGetAutoTextEntry( rEntry.mpAutoTexts, rChartSpace.mnStyle ), rChartSpace.mxTextProp ),
956 mrModelObjHelper( rData.maModelObjHelper ),
957 mrEntry( rEntry )
961 void ObjectTypeFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx )
963 ShapePropertyMap aPropMap( mrModelObjHelper, *mrEntry.mpPropInfo );
964 maLineFormatter.convertFormatting( aPropMap, rxShapeProp, nSeriesIdx );
965 if( mrEntry.mbIsFrame )
966 maFillFormatter.convertFormatting( aPropMap, rxShapeProp, pPicOptions, nSeriesIdx );
967 rPropSet.setProperties( aPropMap );
970 void ObjectTypeFormatter::convertTextFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp )
972 maTextFormatter.convertFormatting( rPropSet, rxTextProp );
975 void ObjectTypeFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const ModelRef< TextBody >& rxTextProp )
977 convertFrameFormatting( rPropSet, rxShapeProp, 0, -1 );
978 convertTextFormatting( rPropSet, rxTextProp );
981 void ObjectTypeFormatter::convertTextFormatting( PropertySet& rPropSet, const TextCharacterProperties& rTextProps )
983 maTextFormatter.convertFormatting( rPropSet, &rTextProps );
986 void ObjectTypeFormatter::convertAutomaticFill( PropertySet& rPropSet, sal_Int32 nSeriesIdx )
988 ShapePropertyMap aPropMap( mrModelObjHelper, *mrEntry.mpPropInfo );
989 ModelRef< Shape > xShapeProp;
990 maFillFormatter.convertFormatting( aPropMap, xShapeProp, 0, nSeriesIdx );
991 rPropSet.setProperties( aPropMap );
994 ObjectFormatterData::ObjectFormatterData( const XmlFilterBase& rFilter, const Reference< XChartDocument >& rxChartDoc, const ChartSpaceModel& rChartSpace ) :
995 mrFilter( rFilter ),
996 maModelObjHelper( Reference< XMultiServiceFactory >( rxChartDoc, UNO_QUERY ) ),
997 maEnUsLocale( "en", "US", OUString() ),
998 mnMaxSeriesIdx( -1 )
1000 const ObjectTypeFormatEntry* pEntryEnd = STATIC_ARRAY_END( spObjTypeFormatEntries );
1001 for( const ObjectTypeFormatEntry* pEntry = spObjTypeFormatEntries; pEntry != pEntryEnd; ++pEntry )
1002 maTypeFormatters[ pEntry->meObjType ].reset( new ObjectTypeFormatter( *this, *pEntry, rChartSpace, pEntry->meObjType ) );
1006 Reference< XNumberFormatsSupplier > xNumFmtsSupp( rxChartDoc, UNO_QUERY_THROW );
1007 mxNumFmts = xNumFmtsSupp->getNumberFormats();
1008 mxNumTypes.set( mxNumFmts, UNO_QUERY );
1010 catch( Exception& )
1013 OSL_ENSURE( mxNumFmts.is() && mxNumTypes.is(), "ObjectFormatterData::ObjectFormatterData - cannot get number formats" );
1016 ObjectTypeFormatter* ObjectFormatterData::getTypeFormatter( ObjectType eObjType )
1018 OSL_ENSURE( maTypeFormatters.has( eObjType ), "ObjectFormatterData::getTypeFormatter - unknown object type" );
1019 return maTypeFormatters.get( eObjType ).get();
1022 ObjectFormatter::ObjectFormatter( const XmlFilterBase& rFilter, const Reference< XChartDocument >& rxChartDoc, const ChartSpaceModel& rChartSpace ) :
1023 mxData( new ObjectFormatterData( rFilter, rxChartDoc, rChartSpace ) )
1027 ObjectFormatter::~ObjectFormatter()
1031 void ObjectFormatter::setMaxSeriesIndex( sal_Int32 nMaxSeriesIdx )
1033 mxData->mnMaxSeriesIdx = nMaxSeriesIdx;
1036 sal_Int32 ObjectFormatter::getMaxSeriesIndex() const
1038 return mxData->mnMaxSeriesIdx;
1041 void ObjectFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, ObjectType eObjType, sal_Int32 nSeriesIdx )
1043 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1044 pFormat->convertFrameFormatting( rPropSet, rxShapeProp, 0, nSeriesIdx );
1047 void ObjectFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel& rPicOptions, ObjectType eObjType, sal_Int32 nSeriesIdx )
1049 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1050 pFormat->convertFrameFormatting( rPropSet, rxShapeProp, &rPicOptions, nSeriesIdx );
1053 void ObjectFormatter::convertTextFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType )
1055 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1056 pFormat->convertTextFormatting( rPropSet, rxTextProp );
1059 void ObjectFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType )
1061 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1062 pFormat->convertFormatting( rPropSet, rxShapeProp, rxTextProp );
1065 void ObjectFormatter::convertTextFormatting( PropertySet& rPropSet, const TextCharacterProperties& rTextProps, ObjectType eObjType )
1067 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1068 pFormat->convertTextFormatting( rPropSet, rTextProps );
1071 void ObjectFormatter::convertTextRotation( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp, bool bSupportsStacked, sal_Int32 nDefaultRotation )
1073 if( rxTextProp.is() )
1075 bool bStacked = false;
1076 if( bSupportsStacked )
1078 sal_Int32 nVert = rxTextProp->getTextProperties().moVert.get( XML_horz );
1079 bStacked = (nVert == XML_wordArtVert) || (nVert == XML_wordArtVertRtl);
1080 rPropSet.setProperty( PROP_StackCharacters, bStacked );
1083 /* Chart2 expects rotation angle as double value in range of [0,360).
1084 OOXML counts clockwise, Chart2 counts counterclockwise. */
1085 double fAngle = static_cast< double >( bStacked ? 0 : rxTextProp->getTextProperties().moRotation.get( nDefaultRotation ) );
1086 // MS Office UI allows values only in range of [-90,90].
1087 if ( fAngle < -5400000.0 || fAngle > 5400000.0 )
1089 fAngle = 0.0;
1091 fAngle = getDoubleIntervalValue< double >( -fAngle / 60000.0, 0.0, 360.0 );
1092 rPropSet.setProperty( PROP_TextRotation, fAngle );
1096 void ObjectFormatter::convertNumberFormat( PropertySet& rPropSet, const NumberFormat& rNumberFormat, bool bAxis, bool bShowPercent )
1098 if( mxData->mxNumFmts.is() )
1100 const bool bGeneral = rNumberFormat.maFormatCode.equalsIgnoreAsciiCase("general");
1101 const bool bPercent = !bAxis && bShowPercent && !rNumberFormat.mbSourceLinked;
1102 sal_Int32 nPropId = bPercent ? PROP_PercentageNumberFormat : PROP_NumberFormat;
1103 OUString sFormatCode(rNumberFormat.maFormatCode);
1104 if (bPercent && bGeneral)
1105 sFormatCode = "0%";
1108 sal_Int32 nIndex = bGeneral && !bPercent ?
1109 mxData->mxNumTypes->getStandardIndex( mxData->maFromLocale ) :
1110 mxData->mxNumFmts->addNewConverted( sFormatCode, mxData->maEnUsLocale, mxData->maFromLocale );
1111 if( nIndex >= 0 )
1112 rPropSet.setProperty( nPropId, nIndex );
1114 catch( Exception& )
1116 OSL_FAIL( OStringBuffer( "ObjectFormatter::convertNumberFormat - cannot create number format '" ).
1117 append( OUStringToOString( rNumberFormat.maFormatCode, osl_getThreadTextEncoding() ) ).append( '\'' ).getStr() );
1120 // Setting "LinkNumberFormatToSource" does not really work, at least not for axis :-/
1121 if (!bAxis)
1122 rPropSet.setProperty(PROP_LinkNumberFormatToSource, makeAny(rNumberFormat.mbSourceLinked));
1123 else
1124 rPropSet.setProperty(PROP_LinkNumberFormatToSource, makeAny(rNumberFormat.maFormatCode.isEmpty()));
1128 void ObjectFormatter::convertAutomaticFill( PropertySet& rPropSet, ObjectType eObjType, sal_Int32 nSeriesIdx )
1130 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1131 pFormat->convertAutomaticFill( rPropSet, nSeriesIdx );
1134 bool ObjectFormatter::isAutomaticFill( const ModelRef< Shape >& rxShapeProp )
1136 return !rxShapeProp || !rxShapeProp->getFillProperties().moFillType.has();
1139 } // namespace chart
1140 } // namespace drawingml
1141 } // namespace oox
1143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */