LibreOffice Module oox (master) 1
objectformatter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21
22#include <com/sun/star/chart2/XChartDocument.hpp>
23#include <com/sun/star/lang/XMultiServiceFactory.hpp>
24#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
25#include <com/sun/star/util/XNumberFormatTypes.hpp>
26#include <osl/thread.h>
27#include <osl/diagnose.h>
28#include <rtl/strbuf.hxx>
39#include <oox/token/properties.hxx>
40#include <oox/token/tokens.hxx>
41
43
44namespace oox::drawingml::chart {
45
46using namespace ::com::sun::star::chart2;
47using namespace ::com::sun::star::graphic;
48using namespace ::com::sun::star::lang;
49using namespace ::com::sun::star::uno;
50using namespace ::com::sun::star::util;
51
52using ::oox::core::XmlFilterBase;
53
54namespace {
55
56struct AutoFormatPatternEntry
57{
58 sal_Int32 mnColorToken;
59 sal_Int32 mnModToken;
60 sal_Int32 mnModValue;
61};
62
63#define AUTOFORMAT_PATTERN_COLOR( color_token ) \
64 { color_token, XML_TOKEN_INVALID, 0 }
65
66#define AUTOFORMAT_PATTERN_COLORMOD( color_token, mod_token, mod_value ) \
67 { color_token, mod_token, mod_value }
68
69#define AUTOFORMAT_PATTERN_END() \
70 AUTOFORMAT_PATTERN_COLOR( XML_TOKEN_INVALID )
71
72const AutoFormatPatternEntry spAutoFormatPattern1[] =
73{
74 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 88500 ),
75 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 55000 ),
76 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 78000 ),
77 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 92500 ),
78 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 70000 ),
79 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 30000 ),
81};
82
83const AutoFormatPatternEntry spAutoFormatPattern2[] =
84{
85 AUTOFORMAT_PATTERN_COLOR( XML_accent1 ),
86 AUTOFORMAT_PATTERN_COLOR( XML_accent2 ),
87 AUTOFORMAT_PATTERN_COLOR( XML_accent3 ),
88 AUTOFORMAT_PATTERN_COLOR( XML_accent4 ),
89 AUTOFORMAT_PATTERN_COLOR( XML_accent5 ),
90 AUTOFORMAT_PATTERN_COLOR( XML_accent6 ),
92};
93
94const AutoFormatPatternEntry spAutoFormatPattern3[] =
95{
96 AUTOFORMAT_PATTERN_COLORMOD( XML_accent1, XML_shade, 50000 ),
97 AUTOFORMAT_PATTERN_COLORMOD( XML_accent2, XML_shade, 50000 ),
98 AUTOFORMAT_PATTERN_COLORMOD( XML_accent3, XML_shade, 50000 ),
99 AUTOFORMAT_PATTERN_COLORMOD( XML_accent4, XML_shade, 50000 ),
100 AUTOFORMAT_PATTERN_COLORMOD( XML_accent5, XML_shade, 50000 ),
101 AUTOFORMAT_PATTERN_COLORMOD( XML_accent6, XML_shade, 50000 ),
103};
104
105const AutoFormatPatternEntry spAutoFormatPattern4[] =
106{
107 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 5000 ),
108 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 55000 ),
109 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 78000 ),
110 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 15000 ),
111 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 70000 ),
112 AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 30000 ),
114};
115
116#undef AUTOFORMAT_PATTERN_COLOR
117#undef AUTOFORMAT_PATTERN_COLORMOD
118#undef AUTOFORMAT_PATTERN_END
119
120struct AutoFormatEntry
121{
122 sal_Int32 mnFirstStyleIdx;
123 sal_Int32 mnLastStyleIdx;
124 sal_Int32 mnThemedIdx;
125 sal_Int32 mnColorToken;
126 sal_Int32 mnModToken;
127 sal_Int32 mnModValue;
128 sal_Int32 mnRelLineWidth;
129 const AutoFormatPatternEntry* mpPattern;
131};
132
133#define AUTOFORMAT_COLOR( first, last, themed_style, color_token ) \
134 { first, last, themed_style, color_token, XML_TOKEN_INVALID, 0, 100, nullptr, false }
135
136#define AUTOFORMAT_COLORMOD( first, last, themed_style, color_token, mod_token, mod_value ) \
137 { first, last, themed_style, color_token, mod_token, mod_value, 100, nullptr, false }
138
139#define AUTOFORMAT_ACCENTSMOD( first, themed_style, mod_token, mod_value ) \
140 AUTOFORMAT_COLORMOD( first, first, themed_style, XML_accent1, mod_token, mod_value ), \
141 AUTOFORMAT_COLORMOD( first + 1, first + 1, themed_style, XML_accent2, mod_token, mod_value ), \
142 AUTOFORMAT_COLORMOD( first + 2, first + 2, themed_style, XML_accent3, mod_token, mod_value ), \
143 AUTOFORMAT_COLORMOD( first + 3, first + 3, themed_style, XML_accent4, mod_token, mod_value ), \
144 AUTOFORMAT_COLORMOD( first + 4, first + 4, themed_style, XML_accent5, mod_token, mod_value ), \
145 AUTOFORMAT_COLORMOD( first + 5, first + 5, themed_style, XML_accent6, mod_token, mod_value )
146
147#define AUTOFORMAT_PATTERN( first, last, themed_style, line_width, pattern ) \
148 { first, last, themed_style, XML_TOKEN_INVALID, XML_TOKEN_INVALID, 0, line_width, pattern, false }
149
150#define AUTOFORMAT_FADED( first, last, themed_style, color_token, line_width ) \
151 { first, last, themed_style, color_token, XML_TOKEN_INVALID, 0, line_width, nullptr, true }
152
153#define AUTOFORMAT_FADEDACCENTS( first, themed_style, line_width ) \
154 AUTOFORMAT_FADED( first, first, themed_style, XML_accent1, line_width ), \
155 AUTOFORMAT_FADED( first + 1, first + 1, themed_style, XML_accent2, line_width ), \
156 AUTOFORMAT_FADED( first + 2, first + 2, themed_style, XML_accent3, line_width ), \
157 AUTOFORMAT_FADED( first + 3, first + 3, themed_style, XML_accent4, line_width ), \
158 AUTOFORMAT_FADED( first + 4, first + 4, themed_style, XML_accent5, line_width ), \
159 AUTOFORMAT_FADED( first + 5, first + 5, themed_style, XML_accent6, line_width )
160
161#define AUTOFORMAT_INVISIBLE( first, last ) \
162 AUTOFORMAT_COLOR( first, last, -1, XML_TOKEN_INVALID )
163
164#define AUTOFORMAT_END() \
165 AUTOFORMAT_INVISIBLE( -1, -1 )
166
167const AutoFormatEntry spNoFormats[] =
168{
169 AUTOFORMAT_INVISIBLE( 1, 48 ),
171};
172
173const AutoFormatEntry spChartSpaceFill[] =
174{
175 AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_bg1 ),
176 AUTOFORMAT_COLOR( 33, 40, THEMED_STYLE_SUBTLE, XML_lt1 ),
177 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1 ),
179};
180
181const AutoFormatEntry spDataTableLines[] =
182{
183 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ),
184 AUTOFORMAT_COLORMOD( 33, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ),
185 // 41...48: no line, same as Chart2
187};
188
189const AutoFormatEntry spPlotArea2dFills[] =
190{
191 AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_bg1 ),
192 AUTOFORMAT_COLORMOD( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 20000 ),
193 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_tint, 20000 ), // tint not documented!?
194 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
196};
197
198const AutoFormatEntry spWallFloorLines[] =
199{
200 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ),
201 AUTOFORMAT_COLORMOD( 33, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ),
202 // 41...48: no line, same as Chart2
204};
205
206const AutoFormatEntry spWallFloorFills[] =
207{
208 AUTOFORMAT_INVISIBLE( 1, 32 ),
209 AUTOFORMAT_COLORMOD( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 20000 ),
210 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_tint, 20000 ), // tint not documented!?
211 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
213};
214
215const AutoFormatEntry spAxisLines[] =
216{
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!?
220};
221
222const AutoFormatEntry spMajorGridLines[] =
223{
224 AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), // tint not documented!?
225 AUTOFORMAT_COLORMOD( 33, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), // tint not documented!?
227};
228
229const AutoFormatEntry spMinorGridLines[] =
230{
231 AUTOFORMAT_COLORMOD( 1, 40, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 50000 ),
232 AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 90000 ),
234};
235
236const AutoFormatEntry spOtherLines[] =
237{
238 AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1 ),
239 AUTOFORMAT_COLOR( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1 ),
240 AUTOFORMAT_COLORMOD( 35, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_shade, 25000 ),
241 AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_SUBTLE, XML_lt1 ),
243};
244
245const AutoFormatEntry spLinearSeriesLines[] =
246{
247 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 300, spAutoFormatPattern1 ),
248 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 300, spAutoFormatPattern2 ),
250 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
251 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
253 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
254 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
256 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_SUBTLE, 700, spAutoFormatPattern1 ),
257 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_SUBTLE, 700, spAutoFormatPattern2 ),
259 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ),
260 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
262 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern4 ),
263 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ),
266};
267
268const AutoFormatEntry spFilledSeriesLines[] =
269{
270 AUTOFORMAT_INVISIBLE( 1, 8 ),
271 AUTOFORMAT_COLOR( 9, 16, THEMED_STYLE_SUBTLE, XML_lt1 ),
272 AUTOFORMAT_INVISIBLE( 17, 32 ),
273 AUTOFORMAT_COLORMOD( 33, 33, THEMED_STYLE_SUBTLE, XML_dk1, XML_shade, 50000 ),
274 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern3 ),
275 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 50000 ),
276 AUTOFORMAT_INVISIBLE( 41, 48 ),
278};
279
280const AutoFormatEntry spFilledSeries2dFills[] =
281{
282 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
283 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
285 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
286 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
288 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern1 ),
289 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
291 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern1 ),
292 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
294 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
295 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
297 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern4 ),
298 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
301};
302
303const AutoFormatEntry spFilledSeries3dFills[] =
304{
305 AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
306 AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
308 AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
309 AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
311 AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
312 AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
314 AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
315 AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
317 AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ),
318 AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ),
320 AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern4 ),
321 AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ),
324};
325
326const AutoFormatEntry spUpDownBarLines[] =
327{
328 AUTOFORMAT_COLOR( 1, 16, THEMED_STYLE_SUBTLE, XML_tx1 ),
329 AUTOFORMAT_INVISIBLE( 17, 32 ),
330 AUTOFORMAT_COLOR( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1 ),
331 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
332 AUTOFORMAT_INVISIBLE( 41, 48 ),
334};
335
336const AutoFormatEntry spUpBarFills[] =
337{
338 AUTOFORMAT_COLORMOD( 1, 1, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 25000 ),
339 AUTOFORMAT_COLORMOD( 2, 2, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 5000 ),
340 AUTOFORMAT_ACCENTSMOD( 3, THEMED_STYLE_SUBTLE, XML_tint, 25000 ),
341 AUTOFORMAT_COLORMOD( 9, 9, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 25000 ),
342 AUTOFORMAT_COLORMOD( 10, 10, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 5000 ),
343 AUTOFORMAT_ACCENTSMOD( 11, THEMED_STYLE_SUBTLE, XML_tint, 25000 ),
344 AUTOFORMAT_COLORMOD( 17, 17, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
345 AUTOFORMAT_COLORMOD( 18, 18, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 5000 ),
346 AUTOFORMAT_ACCENTSMOD( 19, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
347 AUTOFORMAT_COLORMOD( 25, 25, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
348 AUTOFORMAT_COLORMOD( 26, 26, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 5000 ),
349 AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
350 AUTOFORMAT_COLOR( 33, 40, THEMED_STYLE_SUBTLE, XML_lt1 ),
351 AUTOFORMAT_COLORMOD( 41, 41, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ),
352 AUTOFORMAT_COLOR( 42, 42, THEMED_STYLE_INTENSE, XML_lt1 ),
353 AUTOFORMAT_ACCENTSMOD( 43, THEMED_STYLE_INTENSE, XML_tint, 25000 ),
355};
356
357const AutoFormatEntry spDownBarFills[] =
358{
359 AUTOFORMAT_COLORMOD( 1, 1, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
360 AUTOFORMAT_COLORMOD( 2, 2, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
361 AUTOFORMAT_ACCENTSMOD( 3, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
362 AUTOFORMAT_COLORMOD( 9, 9, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
363 AUTOFORMAT_COLORMOD( 10, 10, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
364 AUTOFORMAT_ACCENTSMOD( 11, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
365 AUTOFORMAT_COLORMOD( 17, 17, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
366 AUTOFORMAT_COLORMOD( 18, 18, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 95000 ),
367 AUTOFORMAT_ACCENTSMOD( 19, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
368 AUTOFORMAT_COLORMOD( 25, 25, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
369 AUTOFORMAT_COLORMOD( 26, 26, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 95000 ),
370 AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
371 AUTOFORMAT_COLORMOD( 33, 33, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ),
372 AUTOFORMAT_COLORMOD( 34, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ),
373 AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 25000 ),
374 AUTOFORMAT_COLORMOD( 41, 41, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ),
375 AUTOFORMAT_COLOR( 42, 42, THEMED_STYLE_INTENSE, XML_dk1 ),
376 AUTOFORMAT_ACCENTSMOD( 43, THEMED_STYLE_INTENSE, XML_shade, 25000 ),
378};
379
380#undef AUTOFORMAT_COLOR
381#undef AUTOFORMAT_COLORMOD
382#undef AUTOFORMAT_ACCENTSMOD
383#undef AUTOFORMAT_PATTERN
384#undef AUTOFORMAT_FADED
385#undef AUTOFORMAT_FADEDACCENTS
386#undef AUTOFORMAT_INVISIBLE
387#undef AUTOFORMAT_END
388
389const AutoFormatEntry* lclGetAutoFormatEntry( const AutoFormatEntry* pEntries, sal_Int32 nStyle )
390{
391 for( ; pEntries && (pEntries->mnFirstStyleIdx >= 0); ++pEntries )
392 if( (pEntries->mnFirstStyleIdx <= nStyle) && (nStyle <= pEntries->mnLastStyleIdx) )
393 return pEntries;
394 return nullptr;
395}
396
397struct AutoTextEntry
398{
399 sal_Int32 mnFirstStyleIdx;
400 sal_Int32 mnLastStyleIdx;
401 sal_Int32 mnThemedFont;
402 sal_Int32 mnColorToken;
403 sal_Int32 mnDefFontSize;
404 sal_Int32 mnRelFontSize;
405 bool mbBold;
406};
407
408#define AUTOTEXT_COLOR( first, last, themed_font, color_token, def_font_size, rel_font_size, bold ) \
409 { first, last, themed_font, color_token, def_font_size, rel_font_size, bold }
410
411#define AUTOTEXT_END() \
412 AUTOTEXT_COLOR( -1, -1, XML_none, XML_TOKEN_INVALID, 1000, 100, false )
413
414const AutoTextEntry spChartTitleTexts[] =
415{
416 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1800, 120, true ),
417 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1800, 120, true ),
419};
420
421const AutoTextEntry spAxisTitleTexts[] =
422{
423 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1000, 100, true ),
424 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1000, 100, true ),
426};
427
428const AutoTextEntry spOtherTexts[] =
429{
430 AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1000, 100, false ),
431 AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1000, 100, false ),
433};
434
435#undef AUTOTEXT_COLOR
436#undef AUTOTEXT_END
437
438const AutoTextEntry* lclGetAutoTextEntry( const AutoTextEntry* pEntries, sal_Int32 nStyle )
439{
440 for( ; pEntries && (pEntries->mnFirstStyleIdx >= 0); ++pEntries )
441 if( (pEntries->mnFirstStyleIdx <= nStyle) && (nStyle <= pEntries->mnLastStyleIdx) )
442 return pEntries;
443 return nullptr;
444}
445
446// These PropIds arrays will be indexed into using a ShapeProperty enum
447
448const ShapePropertyIds spnCommonPropIds =
449{
451 PROP_LineCap, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
456 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID
457};
458
459const ShapePropertyIds spnLinearPropIds =
460{
462 PROP_LineCap, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
463 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
464 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID,
465 PROP_INVALID, PROP_INVALID, PROP_INVALID,
466 PROP_INVALID, PROP_INVALID,
467 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID
468};
469
470const ShapePropertyIds spnFilledPropIds =
471{
472 PROP_BorderStyle,
473 PROP_BorderWidth,
475 PROP_BorderTransparency,
476 PROP_BorderDashName,
478 PROP_INVALID,
479 PROP_INVALID,
480 PROP_INVALID,
481 PROP_INVALID,
482 PROP_INVALID,
483 PROP_INVALID,
484 PROP_INVALID,
486 PROP_Color,
489 PROP_GradientName,
497 PROP_HatchName,
499 PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID
500};
501
503const ShapePropertyInfo saCommonPropInfo( spnCommonPropIds, false, true, true, true, true );
505const ShapePropertyInfo saLinearPropInfo( spnLinearPropIds, false, true, true, true, true );
507const ShapePropertyInfo saFilledPropInfo( spnFilledPropIds, false, true, true, true, true );
508
510struct ObjectTypeFormatEntry
511{
513 const ShapePropertyInfo& mrPropInfo;
514 const AutoFormatEntry* mpAutoLines;
515 const AutoFormatEntry* mpAutoFills;
516 const AutoTextEntry* mpAutoTexts;
518 ObjectTypeFormatEntry(ObjectType eObjType, const ShapePropertyInfo& rPropInfo,
519 const AutoFormatEntry* pAutoLines,
520 const AutoFormatEntry* pAutoFills,
521 const AutoTextEntry* pAutoTexts,
522 bool bIsFrame)
523 :meObjType(eObjType), mrPropInfo(rPropInfo), mpAutoLines(pAutoLines)
524 ,mpAutoFills(pAutoFills), mpAutoTexts(pAutoTexts), mbIsFrame(bIsFrame)
525 {} // prevent creation of implicit default ctor which fails in MSVC
526};
527
528#define TYPEFORMAT_FRAME( obj_type, prop_type, auto_texts, auto_lines, auto_fills ) \
529 { obj_type, prop_type, auto_lines, auto_fills, auto_texts, true }
530
531#define TYPEFORMAT_LINE( obj_type, prop_type, auto_texts, auto_lines ) \
532 { obj_type, prop_type, auto_lines, nullptr, auto_texts, false }
533
534const ObjectTypeFormatEntry spObjTypeFormatEntries[] =
535{
536 // object type property info auto text auto line auto fill
537 TYPEFORMAT_FRAME( OBJECTTYPE_CHARTSPACE, saCommonPropInfo, nullptr, spNoFormats, spChartSpaceFill ),
538 TYPEFORMAT_FRAME( OBJECTTYPE_CHARTTITLE, saCommonPropInfo, spChartTitleTexts, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */),
539 TYPEFORMAT_FRAME( OBJECTTYPE_LEGEND, saCommonPropInfo, spOtherTexts, spNoFormats, spNoFormats ),
540 TYPEFORMAT_FRAME( OBJECTTYPE_PLOTAREA2D, saCommonPropInfo, nullptr, nullptr /* eq to Ch2 */, spPlotArea2dFills ),
541 TYPEFORMAT_FRAME( OBJECTTYPE_PLOTAREA3D, saCommonPropInfo, nullptr, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */ ),
542 TYPEFORMAT_FRAME( OBJECTTYPE_WALL, saCommonPropInfo, nullptr, spWallFloorLines, spWallFloorFills ),
543 TYPEFORMAT_FRAME( OBJECTTYPE_FLOOR, saCommonPropInfo, nullptr, spWallFloorLines, spWallFloorFills ),
544 TYPEFORMAT_LINE( OBJECTTYPE_AXIS, saCommonPropInfo, spOtherTexts, spAxisLines ),
545 TYPEFORMAT_FRAME( OBJECTTYPE_AXISTITLE, saCommonPropInfo, spAxisTitleTexts, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */ ),
546 TYPEFORMAT_FRAME( OBJECTTYPE_AXISUNIT, saCommonPropInfo, spAxisTitleTexts, nullptr /* eq in Ch2 */, nullptr /* eq in Ch2 */ ),
547 TYPEFORMAT_LINE( OBJECTTYPE_MAJORGRIDLINE, saCommonPropInfo, nullptr, spMajorGridLines ),
548 TYPEFORMAT_LINE( OBJECTTYPE_MINORGRIDLINE, saCommonPropInfo, nullptr, spMinorGridLines ),
549 TYPEFORMAT_LINE( OBJECTTYPE_LINEARSERIES2D, saLinearPropInfo, nullptr, spLinearSeriesLines ),
550 TYPEFORMAT_FRAME( OBJECTTYPE_FILLEDSERIES2D, saFilledPropInfo, nullptr, spFilledSeriesLines, spFilledSeries2dFills ),
551 TYPEFORMAT_FRAME( OBJECTTYPE_FILLEDSERIES3D, saFilledPropInfo, nullptr, spFilledSeriesLines, spFilledSeries3dFills ),
552 TYPEFORMAT_FRAME( OBJECTTYPE_DATALABEL, saCommonPropInfo, spOtherTexts, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */ ),
553 TYPEFORMAT_LINE( OBJECTTYPE_TRENDLINE, saCommonPropInfo, nullptr, spOtherLines ),
554 TYPEFORMAT_FRAME( OBJECTTYPE_TRENDLINELABEL, saCommonPropInfo, spOtherTexts, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */ ),
555 TYPEFORMAT_LINE( OBJECTTYPE_ERRORBAR, saCommonPropInfo, nullptr, spOtherLines ),
556 TYPEFORMAT_LINE( OBJECTTYPE_SERLINE, saCommonPropInfo, nullptr, spOtherLines ),
557 TYPEFORMAT_LINE( OBJECTTYPE_LEADERLINE, saCommonPropInfo, nullptr, spOtherLines ),
558 TYPEFORMAT_LINE( OBJECTTYPE_DROPLINE, saCommonPropInfo, nullptr, spOtherLines ),
559 TYPEFORMAT_LINE( OBJECTTYPE_HILOLINE, saLinearPropInfo, nullptr, spOtherLines ),
560 TYPEFORMAT_FRAME( OBJECTTYPE_UPBAR, saCommonPropInfo, nullptr, spUpDownBarLines, spUpBarFills ),
561 TYPEFORMAT_FRAME( OBJECTTYPE_DOWNBAR, saCommonPropInfo, nullptr, spUpDownBarLines, spDownBarFills ),
562 TYPEFORMAT_FRAME( OBJECTTYPE_DATATABLE, saCommonPropInfo, spOtherTexts, spDataTableLines, nullptr )
563};
564
565#undef TYPEFORMAT_FRAME
566#undef TYPEFORMAT_LINE
567
568void lclConvertPictureOptions( FillProperties& orFillProps, const PictureOptionsModel& rPicOptions )
569{
570 bool bStacked = (rPicOptions.mnPictureFormat == XML_stack) || (rPicOptions.mnPictureFormat == XML_stackScale);
571 orFillProps.maBlipProps.moBitmapMode = bStacked ? XML_tile : XML_stretch;
572}
573
574} // namespace
575
576struct ObjectFormatterData;
577
578namespace {
579
580class DetailFormatterBase
581{
582public:
583 explicit DetailFormatterBase(
584 ObjectFormatterData& rData,
585 const AutoFormatEntry* pAutoFormatEntry );
586 explicit DetailFormatterBase(
587 ObjectFormatterData& rData,
588 const AutoTextEntry* pAutoTextEntry );
589
590protected:
592 ::Color getPhColor( sal_Int32 nSeriesIdx ) const;
593
594private:
596 ::Color getSchemeColor( sal_Int32 nColorToken, sal_Int32 nModToken, sal_Int32 nModValue ) const;
597
598protected:
599 typedef ::std::vector< ::Color > ColorPatternVec;
600
603 ColorPatternVec maColorPattern;
604};
605
606class LineFormatter : public DetailFormatterBase
607{
608public:
609 explicit LineFormatter(
610 ObjectFormatterData& rData,
611 const AutoFormatEntry* pAutoFormatEntry,
612 const ObjectType eObjType );
613
615 void convertFormatting(
616 ShapePropertyMap& rPropMap,
617 const ModelRef< Shape >& rxShapeProp,
618 sal_Int32 nSeriesIdx );
619
620private:
622};
623
624class FillFormatter : public DetailFormatterBase
625{
626public:
627 explicit FillFormatter(
628 ObjectFormatterData& rData,
629 const AutoFormatEntry* pAutoFormatEntry,
630 const ObjectType eObjType );
631
633 void convertFormatting(
634 ShapePropertyMap& rPropMap,
635 const ModelRef< Shape >& rxShapeProp,
636 const PictureOptionsModel* pPicOptions,
637 sal_Int32 nSeriesIdx );
638
639private:
641};
642
643class TextFormatter : public DetailFormatterBase
644{
645public:
646 explicit TextFormatter(
647 ObjectFormatterData& rData,
648 const AutoTextEntry* pAutoTextEntry,
649 const ModelRef< TextBody >& rxGlobalTextProp );
650
652 void convertFormatting(
653 PropertySet& rPropSet,
654 const TextCharacterProperties* pTextProps );
656 void convertFormatting(
657 PropertySet& rPropSet,
658 const ModelRef< TextBody >& rxTextProp );
659
660private:
662};
663
665class ObjectTypeFormatter
666{
667public:
668 explicit ObjectTypeFormatter(
669 ObjectFormatterData& rData,
670 const ObjectTypeFormatEntry& rEntry,
671 const ChartSpaceModel& rChartSpace,
672 const ObjectType eObjType );
673
675 void convertFrameFormatting(
676 PropertySet& rPropSet,
677 const ModelRef< Shape >& rxShapeProp,
678 const PictureOptionsModel* pPicOptions,
679 sal_Int32 nSeriesIdx );
680
682 void convertTextFormatting(
683 PropertySet& rPropSet,
684 const ModelRef< TextBody >& rxTextProp );
685
687 void convertFormatting(
688 PropertySet& rPropSet,
689 const ModelRef< Shape >& rxShapeProp,
690 const ModelRef< TextBody >& rxTextProp );
691
693 void convertTextFormatting(
694 PropertySet& rPropSet,
695 const TextCharacterProperties& rTextProps );
696
698 void convertAutomaticFill(
699 PropertySet& rPropSet,
700 sal_Int32 nSeriesIdx );
701
702private:
703 LineFormatter maLineFormatter;
704 FillFormatter maFillFormatter;
705 TextFormatter maTextFormatter;
706 ModelObjectHelper& mrModelObjHelper;
707 const ObjectTypeFormatEntry& mrEntry;
708};
709
710}
711
713{
715
723 sal_Int32 mnMaxSeriesIdx;
724
725 explicit ObjectFormatterData(
726 const XmlFilterBase& rFilter,
727 const Reference< XChartDocument >& rxChartDoc,
728 const ChartSpaceModel& rChartSpace );
729
730 ObjectTypeFormatter* getTypeFormatter( ObjectType eObjType );
731};
732
733DetailFormatterBase::DetailFormatterBase( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) :
734 mrData( rData ),
735 mnPhClr( ColorTransparency, 0xffffffff )
736{
737 if( !pAutoFormatEntry )
738 return;
739
740 if( pAutoFormatEntry->mpPattern )
741 {
742 // prepare multi-color pattern
743 for( const AutoFormatPatternEntry* pPatternEntry = pAutoFormatEntry->mpPattern; pPatternEntry->mnColorToken != XML_TOKEN_INVALID; ++pPatternEntry )
744 maColorPattern.push_back( getSchemeColor( pPatternEntry->mnColorToken, pPatternEntry->mnModToken, pPatternEntry->mnModValue ) );
745 }
746 else if( pAutoFormatEntry->mnColorToken != XML_TOKEN_INVALID )
747 {
748 // prepare color or single-color pattern (color fading)
749 mnPhClr = getSchemeColor( pAutoFormatEntry->mnColorToken, pAutoFormatEntry->mnModToken, pAutoFormatEntry->mnModValue );
750 if( pAutoFormatEntry->mbFadedColor )
751 maColorPattern.push_back( mnPhClr );
752 }
753}
754
755DetailFormatterBase::DetailFormatterBase( ObjectFormatterData& rData, const AutoTextEntry* pAutoTextEntry ) :
756 mrData( rData ),
757 mnPhClr( ColorTransparency, 0xffffffff )
758{
759 if( pAutoTextEntry && (pAutoTextEntry->mnColorToken != XML_TOKEN_INVALID) )
760 mnPhClr = getSchemeColor( pAutoTextEntry->mnColorToken, XML_TOKEN_INVALID, 0 );
761}
762
763::Color DetailFormatterBase::getPhColor( sal_Int32 nSeriesIdx ) const
764{
765 if( maColorPattern.empty() || (mrData.mnMaxSeriesIdx < 0) || (nSeriesIdx < 0) )
766 return mnPhClr;
767
768 /* Apply tint/shade depending on the cycle index. The colors of leading
769 series are darkened (color shade), the colors of trailing series are
770 lightened (color tint). Shade/tint is applied in an exclusive range of
771 -70% to 70%.
772
773 Example 1: 3 data series using single-color shading with accent color 1
774 (e.g. automatic chart style #3). Shade/tint is applied per series.
775 Shade/tint changes in steps of 140%/(<series_count+1) = 140%/4 = 35%,
776 starting at -70%:
777 Step 1: -70% -> Not used.
778 Step 2: -35% -> Series 1 has 35% shade of accent color 1.
779 Step 3: 0% -> Series 2 has pure accent color 1.
780 Step 4: 35% -> Series 3 has 35% tint of accent color 1.
781 Step 5: 70% -> Not used.
782
783 Example 2: 20 data series using accent color pattern (e.g. automatic
784 chart style #2). Each color cycle has a size of 6 series (accent colors
785 1 to 6). Shade/tint is applied per color cycle.
786 Cycle #1: Series 1...6 are based on accent colors 1 to 6.
787 Cycle #2: Series 7...12 are based on accent colors 1 to 6.
788 Cycle #3: Series 13...18 are based on accent colors 1 to 6.
789 Cycle #4: Series 19...20 are based on accent colors 1 to 2.
790 Shade/tint changes in steps of 140%/(cycle_count+1) = 140%/5 = 28%,
791 starting at -70%:
792 Step 1: -70% -> Not used.
793 Step 2: -42% -> Cycle #1 has 42% shade of accent colors 1...6
794 step 3: -14% -> Cycle #2 has 14% shade of accent colors 1...6
795 step 4: 14% -> Cycle #3 has 14% tint of accent colors 1...6
796 step 5: 42% -> Cycle #4 has 42% tint of accent colors 1...6
797 step 6: 70% -> Not used.
798 */
799 ::Color nPhClr = maColorPattern[ static_cast< size_t >( nSeriesIdx % maColorPattern.size() ) ];
800 size_t nCycleIdx = static_cast< size_t >( nSeriesIdx / maColorPattern.size() );
801 size_t nMaxCycleIdx = static_cast< size_t >( mrData.mnMaxSeriesIdx / maColorPattern.size() );
802 double fShadeTint = static_cast< double >( nCycleIdx + 1 ) / (nMaxCycleIdx + 2) * 1.4 - 0.7;
803 if( fShadeTint != 0.0 )
804 {
805 Color aColor;
806 aColor.setSrgbClr( nPhClr );
807 aColor.addChartTintTransformation( fShadeTint );
808 nPhClr = aColor.getColor( mrData.mrFilter.getGraphicHelper() );
809 }
810
811 return nPhClr;
812}
813
814::Color DetailFormatterBase::getSchemeColor( sal_Int32 nColorToken, sal_Int32 nModToken, sal_Int32 nModValue ) const
815{
816 Color aColor;
817 aColor.setSchemeClr( nColorToken );
818 if( nModToken != XML_TOKEN_INVALID )
819 aColor.addTransformation( nModToken, nModValue );
820 return aColor.getColor( mrData.mrFilter.getGraphicHelper() );
821}
822
823LineFormatter::LineFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry, const ObjectType eObjType ) :
824 DetailFormatterBase(rData, pAutoFormatEntry)
825{
826 if( !pAutoFormatEntry )
827 return;
828
829 mxAutoLine = std::make_shared<LineProperties>();
830 mxAutoLine->maLineFill.moFillType = XML_noFill;
831 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
832 if( const LineProperties* pLineProps = pTheme->getLineStyle( pAutoFormatEntry->mnThemedIdx ) )
833 *mxAutoLine = *pLineProps;
834 // set automatic border property for chartarea, because of tdf#81437 and tdf#82217, except for Impress (tdf#150176)
835 if ( eObjType == OBJECTTYPE_CHARTSPACE )
836 {
837 OUString aFilterName;
838 rData.mrFilter.getMediaDescriptor()[utl::MediaDescriptor::PROP_FILTERNAME] >>= aFilterName;
839 if (!aFilterName.startsWithIgnoreAsciiCase("Impress"))
840 {
843 // this value is what MSO 2016 use as a default color for chartspace border
844 mxAutoLine->maLineFill.maFillColor.setSrgbClr(0xD9D9D9);
845 }
846 }
847 // change line width according to chart auto style
848 if( mxAutoLine->moLineWidth.has_value() )
849 mxAutoLine->moLineWidth = mxAutoLine->moLineWidth.value() * pAutoFormatEntry->mnRelLineWidth / 100;
850}
851
852void LineFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, sal_Int32 nSeriesIdx )
853{
854 LineProperties aLineProps;
855 if( mxAutoLine )
856 aLineProps.assignUsed( *mxAutoLine );
857 if( rxShapeProp.is() )
858 aLineProps.assignUsed( rxShapeProp->getLineProperties() );
859 aLineProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), getPhColor( nSeriesIdx ) );
860}
861
862FillFormatter::FillFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry, const ObjectType eObjType ) :
863 DetailFormatterBase( rData, pAutoFormatEntry )
864{
865 if( !pAutoFormatEntry )
866 return;
867
868 mxAutoFill = std::make_shared<FillProperties>();
869 if( eObjType != OBJECTTYPE_CHARTSPACE )
870 mxAutoFill->moFillType = XML_noFill;
871 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
872 if( const FillProperties* pFillProps = pTheme->getFillStyle( pAutoFormatEntry->mnThemedIdx ) )
873 *mxAutoFill = *pFillProps;
874
875 if (eObjType == OBJECTTYPE_CHARTSPACE)
876 {
877 mxAutoFill->moFillType = rData.mrFilter.getGraphicHelper().getDefaultChartAreaFillStyle();
878 }
879}
880
881void FillFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx )
882{
883 FillProperties aFillProps;
884 if( mxAutoFill )
885 aFillProps.assignUsed( *mxAutoFill );
886 if (rxShapeProp)
887 aFillProps.assignUsed( rxShapeProp->getFillProperties() );
888 if( pPicOptions )
889 lclConvertPictureOptions( aFillProps, *pPicOptions );
890 aFillProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), 0, getPhColor( nSeriesIdx ) );
891}
892
893namespace {
894
895const TextCharacterProperties* lclGetTextProperties( const ModelRef< TextBody >& rxTextProp )
896{
897 return (rxTextProp.is() && !rxTextProp->getParagraphs().empty()) ?
898 &rxTextProp->getParagraphs().front()->getProperties().getTextCharacterProperties() : nullptr;
899}
900
901} // namespace
902
903TextFormatter::TextFormatter( ObjectFormatterData& rData, const AutoTextEntry* pAutoTextEntry, const ModelRef< TextBody >& rxGlobalTextProp ) :
904 DetailFormatterBase( rData, pAutoTextEntry )
905{
906 if( !pAutoTextEntry )
907 return;
908
909 mxAutoText = std::make_shared<TextCharacterProperties>();
910 if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() )
911 if( const TextCharacterProperties* pTextProps = pTheme->getFontStyle( pAutoTextEntry->mnThemedFont ) )
912 *mxAutoText = *pTextProps;
913 ::Color nTextColor = getPhColor( -1 );
914 if( sal_Int32(nTextColor) >= 0 ) {
915 mxAutoText->maFillProperties.maFillColor.setSrgbClr( nTextColor );
916 mxAutoText->maFillProperties.moFillType = XML_solidFill;
917 }
918 mxAutoText->moHeight = pAutoTextEntry->mnDefFontSize;
919 mxAutoText->moBold = pAutoTextEntry->mbBold;
920
921 if( const TextCharacterProperties* pTextProps = lclGetTextProperties( rxGlobalTextProp ) )
922 {
923 mxAutoText->assignUsed( *pTextProps );
924 if( pTextProps->moHeight.has_value() )
925 mxAutoText->moHeight = pTextProps->moHeight.value() * pAutoTextEntry->mnRelFontSize / 100;
926 }
927}
928
929void TextFormatter::convertFormatting( PropertySet& rPropSet, const TextCharacterProperties* pTextProps )
930{
931 TextCharacterProperties aTextProps;
932 if( mxAutoText )
933 aTextProps.assignUsed( *mxAutoText );
934 if( pTextProps )
935 aTextProps.assignUsed( *pTextProps );
936 aTextProps.pushToPropSet( rPropSet, mrData.mrFilter );
937}
938
939void TextFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp )
940{
941 convertFormatting( rPropSet, lclGetTextProperties( rxTextProp ) );
942}
943
944ObjectTypeFormatter::ObjectTypeFormatter( ObjectFormatterData& rData, const ObjectTypeFormatEntry& rEntry, const ChartSpaceModel& rChartSpace, const ObjectType eObjType ) :
945 maLineFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoLines, rChartSpace.mnStyle ), eObjType ),
946 maFillFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoFills, rChartSpace.mnStyle ), eObjType ),
947 maTextFormatter( rData, lclGetAutoTextEntry( rEntry.mpAutoTexts, rChartSpace.mnStyle ), rChartSpace.mxTextProp ),
948 mrModelObjHelper( rData.maModelObjHelper ),
949 mrEntry( rEntry )
950{
951}
952
953void ObjectTypeFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx )
954{
955 ShapePropertyMap aPropMap( mrModelObjHelper, mrEntry.mrPropInfo );
956 maLineFormatter.convertFormatting( aPropMap, rxShapeProp, nSeriesIdx );
957 if( mrEntry.mbIsFrame )
958 maFillFormatter.convertFormatting( aPropMap, rxShapeProp, pPicOptions, nSeriesIdx );
959 rPropSet.setProperties( aPropMap );
960}
961
962void ObjectTypeFormatter::convertTextFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp )
963{
964 maTextFormatter.convertFormatting( rPropSet, rxTextProp );
965}
966
967void ObjectTypeFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const ModelRef< TextBody >& rxTextProp )
968{
969 convertFrameFormatting( rPropSet, rxShapeProp, nullptr, -1 );
970 convertTextFormatting( rPropSet, rxTextProp );
971}
972
973void ObjectTypeFormatter::convertTextFormatting( PropertySet& rPropSet, const TextCharacterProperties& rTextProps )
974{
975 maTextFormatter.convertFormatting( rPropSet, &rTextProps );
976}
977
978void ObjectTypeFormatter::convertAutomaticFill( PropertySet& rPropSet, sal_Int32 nSeriesIdx )
979{
980 ShapePropertyMap aPropMap( mrModelObjHelper, mrEntry.mrPropInfo );
981 ModelRef< Shape > xShapeProp;
982 maFillFormatter.convertFormatting( aPropMap, xShapeProp, nullptr, nSeriesIdx );
983 rPropSet.setProperties( aPropMap );
984}
985
987 mrFilter( rFilter ),
988 maModelObjHelper( Reference< XMultiServiceFactory >( rxChartDoc, UNO_QUERY ) ),
989 maEnUsLocale( "en", "US", OUString() ),
990 mnMaxSeriesIdx( -1 )
991{
992 for(auto const &rEntry : spObjTypeFormatEntries)
993 maTypeFormatters[ rEntry.meObjType ] = std::make_shared<ObjectTypeFormatter>( *this, rEntry, rChartSpace, rEntry.meObjType );
994
995 try
996 {
997 Reference< XNumberFormatsSupplier > xNumFmtsSupp( rxChartDoc, UNO_QUERY_THROW );
998 mxNumFmts = xNumFmtsSupp->getNumberFormats();
999 mxNumTypes.set( mxNumFmts, UNO_QUERY );
1000 }
1001 catch( Exception& )
1002 {
1003 }
1004 OSL_ENSURE( mxNumFmts.is() && mxNumTypes.is(), "ObjectFormatterData::ObjectFormatterData - cannot get number formats" );
1005}
1006
1008{
1009 OSL_ENSURE( maTypeFormatters.has( eObjType ), "ObjectFormatterData::getTypeFormatter - unknown object type" );
1010 return maTypeFormatters.get( eObjType ).get();
1011}
1012
1013ObjectFormatter::ObjectFormatter( const XmlFilterBase& rFilter, const Reference< XChartDocument >& rxChartDoc, const ChartSpaceModel& rChartSpace ) :
1014 mxData( std::make_shared<ObjectFormatterData>( rFilter, rxChartDoc, rChartSpace ) )
1015{
1016}
1017
1019{
1020}
1021
1022void ObjectFormatter::setMaxSeriesIndex( sal_Int32 nMaxSeriesIdx )
1023{
1024 mxData->mnMaxSeriesIdx = nMaxSeriesIdx;
1025}
1026
1028{
1029 return mxData->mnMaxSeriesIdx;
1030}
1031
1032void ObjectFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, ObjectType eObjType, sal_Int32 nSeriesIdx )
1033{
1034 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1035 pFormat->convertFrameFormatting( rPropSet, rxShapeProp, nullptr, nSeriesIdx );
1036}
1037
1038void ObjectFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel& rPicOptions, ObjectType eObjType, sal_Int32 nSeriesIdx )
1039{
1040 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1041 pFormat->convertFrameFormatting( rPropSet, rxShapeProp, &rPicOptions, nSeriesIdx );
1042}
1043
1045{
1046 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1047 pFormat->convertTextFormatting( rPropSet, rxTextProp );
1048}
1049
1050void ObjectFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType )
1051{
1052 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1053 pFormat->convertFormatting( rPropSet, rxShapeProp, rxTextProp );
1054}
1055
1057{
1058 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1059 pFormat->convertTextFormatting( rPropSet, rTextProps );
1060}
1061
1062void ObjectFormatter::convertTextRotation( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp, bool bSupportsStacked, sal_Int32 nDefaultRotation )
1063{
1064 if( !rxTextProp.is() )
1065 return;
1066
1067 bool bStacked = false;
1068 if( bSupportsStacked )
1069 {
1070 sal_Int32 nVert = rxTextProp->getTextProperties().moVert.value_or( XML_horz );
1071 bStacked = (nVert == XML_wordArtVert) || (nVert == XML_wordArtVertRtl);
1072 rPropSet.setProperty( PROP_StackCharacters, bStacked );
1073 }
1074
1075 /* Chart2 expects rotation angle as double value in range of [0,360).
1076 OOXML counts clockwise, Chart2 counts counterclockwise. */
1077 double fAngle = static_cast< double >( bStacked ? 0 : rxTextProp->getTextProperties().moTextAreaRotation.value_or( nDefaultRotation ) );
1078 // MS Office UI allows values only in range of [-90,90].
1079 if ( fAngle < -5400000.0 || fAngle > 5400000.0 )
1080 {
1081 fAngle = 0.0;
1082 }
1083 fAngle = getDoubleIntervalValue< double >( -fAngle / 60000.0, 0.0, 360.0 );
1084 rPropSet.setProperty( PROP_TextRotation, fAngle );
1085}
1086
1088{
1089 if( !rxTextProp.is() )
1090 {
1091 // set default value (in OOXML the default value is true)
1092 rPropSet.setProperty( PROP_TextWordWrap, true );
1093 return;
1094 }
1095
1096 PropertyMap& aPropMap = rxTextProp->getTextProperties().maPropertyMap;
1097 if( aPropMap.hasProperty(PROP_TextWordWrap) )
1098 {
1099 Any aValue = aPropMap.getProperty( PROP_TextWordWrap );
1100 if( aValue.hasValue() )
1101 {
1102 bool bValue = false;
1103 aValue >>= bValue;
1104 rPropSet.setProperty( PROP_TextWordWrap, bValue );
1105 }
1106 }
1107}
1108
1109void ObjectFormatter::convertNumberFormat( PropertySet& rPropSet, const NumberFormat& rNumberFormat, bool bAxis, bool bShowPercent )
1110{
1111 if( !mxData->mxNumFmts.is() )
1112 return;
1113
1114 const bool bGeneral = rNumberFormat.maFormatCode.equalsIgnoreAsciiCase("general");
1115 const bool bPercent = !bAxis && bShowPercent && !rNumberFormat.mbSourceLinked;
1116 sal_Int32 nPropId = bPercent ? PROP_PercentageNumberFormat : PROP_NumberFormat;
1117 OUString sFormatCode(rNumberFormat.maFormatCode);
1118 if (bPercent && bGeneral)
1119 sFormatCode = "0%";
1120 try
1121 {
1122 sal_Int32 nIndex = bGeneral && !bPercent ?
1123 mxData->mxNumTypes->getStandardIndex( mxData->maFromLocale ) :
1124 mxData->mxNumFmts->addNewConverted( sFormatCode, mxData->maEnUsLocale, mxData->maFromLocale );
1125 if( nIndex >= 0 )
1126 rPropSet.setProperty( nPropId, nIndex );
1127 }
1128 catch( Exception& )
1129 {
1130 OSL_FAIL( OStringBuffer( "ObjectFormatter::convertNumberFormat - cannot create number format '" +
1131 OUStringToOString( rNumberFormat.maFormatCode, osl_getThreadTextEncoding() ) + "'" ).getStr() );
1132 }
1133
1134 // Setting "LinkNumberFormatToSource" does not really work, at least not for axis :-/
1135 if (!bAxis)
1137 else
1138 rPropSet.setProperty(PROP_LinkNumberFormatToSource, Any(rNumberFormat.maFormatCode.isEmpty()));
1139}
1140
1141void ObjectFormatter::convertAutomaticFill( PropertySet& rPropSet, ObjectType eObjType, sal_Int32 nSeriesIdx )
1142{
1143 if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) )
1144 pFormat->convertAutomaticFill( rPropSet, nSeriesIdx );
1145}
1146
1148{
1149 return !rxShapeProp || !rxShapeProp->getFillProperties().moFillType.has_value();
1150}
1151
1152} // namespace oox
1153
1154/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static sal_Int32 getDefaultChartAreaLineStyle()
Returns chartspace automatic default border style.
static sal_Int16 getDefaultChartAreaLineWidth()
Returns chartspace automatic default border width in Emu.
Contains tables for named drawing objects for a document model.
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
css::uno::Any getProperty(sal_Int32 nPropId)
bool hasProperty(sal_Int32 nPropId) const
Returns true, if the map contains a property with the passed identifier.
A wrapper for a UNO property set.
Definition: propertyset.hxx:58
bool setProperty(sal_Int32 nPropId, const Type &rValue)
Puts the passed value into the property set.
bool has(key_type nKey) const
Returns true, if the object associated to the passed key exists.
Definition: refmap.hxx:52
mapped_type get(key_type nKey) const
Returns a reference to the object associated to the passed key, or an empty reference on error.
Definition: refmap.hxx:60
GraphicHelper & getGraphicHelper() const
Returns a helper for the handling of graphics and graphic objects.
Definition: filterbase.cxx:346
void convertFrameFormatting(PropertySet &rPropSet, const ModelRef< Shape > &rxShapeProp, ObjectType eObjType, sal_Int32 nSeriesIdx=-1)
Sets frame formatting properties to the passed property set.
sal_Int32 getMaxSeriesIndex() const
Returns the current maximum series index used for color cycling/fading.
void convertAutomaticFill(PropertySet &rPropSet, ObjectType eObjType, sal_Int32 nSeriesIdx)
Sets automatic fill properties to the passed property set.
void convertTextFormatting(PropertySet &rPropSet, const ModelRef< TextBody > &rxTextProp, ObjectType eObjType)
Sets text formatting properties to the passed property set.
std::shared_ptr< ObjectFormatterData > mxData
ObjectFormatter(const ::oox::core::XmlFilterBase &rFilter, const css::uno::Reference< css::chart2::XChartDocument > &rxChartDoc, const ChartSpaceModel &rChartSpace)
void convertFormatting(PropertySet &rPropSet, const ModelRef< Shape > &rxShapeProp, const ModelRef< TextBody > &rxTextProp, ObjectType eObjType)
Sets frame/text formatting properties to the passed property set.
void convertNumberFormat(PropertySet &rPropSet, const NumberFormat &rNumberFormat, bool bAxis, bool bShowPercent=false)
Sets number format properties to the passed property set.
void setMaxSeriesIndex(sal_Int32 nMaxSeriesIdx)
Sets the maximum series index used for color cycling/fading.
static void convertTextWrap(PropertySet &rPropSet, const ModelRef< TextBody > &rxTextProp)
Sets text wrap properties to the passed property set.
static void convertTextRotation(PropertySet &rPropSet, const ModelRef< TextBody > &rxTextProp, bool bSupportsStacked, sal_Int32 nDefaultRotation=0)
Sets text rotation properties to the passed property set.
static bool isAutomaticFill(const ModelRef< Shape > &rxShapeProp)
Returns true, if the passed shape properties have automatic fill mode.
static constexpr OUStringLiteral PROP_FILTERNAME
ColorTransparency
sal_Int32 nIndex
@ Exception
std::shared_ptr< T > make_shared(Args &&... args)
ObjectType
Enumerates different object types for specific automatic formatting behaviour.
@ OBJECTTYPE_PLOTAREA3D
Plot area containing axes and data series in 2D charts.
@ OBJECTTYPE_ERRORBAR
Trend line label.
@ OBJECTTYPE_FILLEDSERIES2D
Linear series in 2D line/radarline/scatter charts.
@ OBJECTTYPE_FLOOR
Background and side wall in 3D charts.
@ OBJECTTYPE_AXIS
Floor in 3D charts.
@ OBJECTTYPE_MINORGRIDLINE
Axis major grid line.
@ OBJECTTYPE_TRENDLINELABEL
Data series trend line.
@ OBJECTTYPE_DATATABLE
Down-bar in line/stock charts.
@ OBJECTTYPE_HILOLINE
Drop lines between data points and X axis.
@ OBJECTTYPE_AXISTITLE
Axis line, labels, tick marks.
@ OBJECTTYPE_FILLEDSERIES3D
Filled series in 2D bar/area/radararea/bubble/pie/surface charts.
@ OBJECTTYPE_DATALABEL
Filled series in 3D charts.
@ OBJECTTYPE_LINEARSERIES2D
Axis minor grid line.
@ OBJECTTYPE_WALL
Plot area containing axes and data series in 3D charts.
@ OBJECTTYPE_LEGEND
Chart title.
@ OBJECTTYPE_CHARTTITLE
Chart background.
@ OBJECTTYPE_UPBAR
High/low lines in line/stock charts.
@ OBJECTTYPE_AXISUNIT
Axis title.
@ OBJECTTYPE_MAJORGRIDLINE
Axis unit label.
@ OBJECTTYPE_LEADERLINE
Data point connector lines.
@ OBJECTTYPE_SERLINE
Data series error indicator line.
@ OBJECTTYPE_DROPLINE
Leader lines between pie slice and data label.
@ OBJECTTYPE_DOWNBAR
Up-bar in line/stock charts.
@ OBJECTTYPE_TRENDLINE
Labels for data points.
const sal_Int32 THEMED_STYLE_INTENSE
Definition: theme.hxx:52
const sal_Int32 THEMED_STYLE_SUBTLE
Definition: theme.hxx:50
std::shared_ptr< TextCharacterProperties > TextCharacterPropertiesPtr
o3tl::enumarray< ShapeProperty, sal_Int32 > ShapePropertyIds
std::shared_ptr< FillProperties > FillPropertiesPtr
std::shared_ptr< LineProperties > LinePropertiesPtr
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Locale maEnUsLocale
ObjectType
#define AUTOFORMAT_COLORMOD(first, last, themed_style, color_token, mod_token, mod_value)
#define AUTOFORMAT_END()
#define AUTOFORMAT_FADEDACCENTS(first, themed_style, line_width)
#define AUTOFORMAT_PATTERN_COLOR(color_token)
#define AUTOTEXT_COLOR(first, last, themed_font, color_token, def_font_size, rel_font_size, bold)
const AutoTextEntry * mpAutoTexts
Automatic fill formatting for all chart styles.
const ShapePropertyInfo & mrPropInfo
Object type for automatic format.
sal_Int32 mnModToken
Theme color token.
sal_Int32 mnLastStyleIdx
First chart style index.
#define AUTOFORMAT_PATTERN(first, last, themed_style, line_width, pattern)
#define AUTOTEXT_END()
sal_Int32 mnModValue
Color modification token.
LineFormatter maLineFormatter
ModelObjectHelper & mrModelObjHelper
Converter for text formatting.
bool mbFadedColor
Color cycling pattern for data series.
sal_Int32 mnThemedFont
Last chart style index.
sal_Int32 mnThemedIdx
Last chart style index.
sal_Int32 mnDefFontSize
Theme color token.
bool mbBold
Font size relative to chart global font (percent).
#define AUTOFORMAT_ACCENTSMOD(first, themed_style, mod_token, mod_value)
#define AUTOFORMAT_COLOR(first, last, themed_style, color_token)
TextFormatter maTextFormatter
Converter for fill formatting.
TextCharacterPropertiesPtr mxAutoText
ObjectFormatterData & mrData
#define AUTOFORMAT_PATTERN_END()
ColorPatternVec maColorPattern
RGB placeholder color for themed style.
#define AUTOFORMAT_INVISIBLE(first, last)
const ObjectTypeFormatEntry & mrEntry
Helper for named drawing formatting.
#define TYPEFORMAT_FRAME(obj_type, prop_type, auto_texts, auto_lines, auto_fills)
sal_Int32 mnRelFontSize
Default font size (1/100 points).
const AutoFormatEntry * mpAutoLines
Property info for the ShapePropertyMap class.
LinePropertiesPtr mxAutoLine
sal_Int32 mnFirstStyleIdx
sal_Int32 mnRelLineWidth
Color modification value.
ObjectType meObjType
FillPropertiesPtr mxAutoFill
#define TYPEFORMAT_LINE(obj_type, prop_type, auto_texts, auto_lines)
const AutoFormatPatternEntry * mpPattern
Relative line width (percent).
FillFormatter maFillFormatter
Converter for line formatting.
#define AUTOFORMAT_PATTERN_COLORMOD(color_token, mod_token, mod_value)
bool mbIsFrame
Automatic text attributes for all chart styles.
::Color mnPhClr
Shared formatter data.
const AutoFormatEntry * mpAutoFills
Automatic line formatting for all chart styles.
sal_Int32 mnColorToken
Themed style index.
const PowerPointImport & mrFilter
Definition: pptimport.cxx:264
bool mbSourceLinked
Number format code.
Definition: modelbase.hxx:94
ObjectTypeFormatter * getTypeFormatter(ObjectType eObjType)
Locale maFromLocale
Locale struct containing en-US.
sal_Int32 mnMaxSeriesIdx
Empty locale struct.
Locale maEnUsLocale
Number format types collection of container document.
RefMap< ObjectType, ObjectTypeFormatter > ObjectTypeFormatterMap
Reference< XNumberFormatTypes > mxNumTypes
Number formats collection of container document.
ObjectFormatterData(const XmlFilterBase &rFilter, const Reference< XChartDocument > &rxChartDoc, const ChartSpaceModel &rChartSpace)
Maximum series index used for color cycling/fading.
ObjectTypeFormatterMap maTypeFormatters
Base filter object.
Reference< XNumberFormats > mxNumFmts
Helper for named drawing formatting (dashes, gradients, bitmaps).
ModelObjectHelper maModelObjHelper
Formatters for all types of objects in a chart.
constexpr OUStringLiteral PROP_LineDashName
constexpr OUStringLiteral PROP_FillBitmapMode
constexpr OUStringLiteral PROP_FillTransparence
constexpr OUStringLiteral PROP_TextWordWrap
constexpr OUStringLiteral PROP_FillTransparenceGradientName
constexpr OUStringLiteral PROP_FillBitmapPositionOffsetX
constexpr OUStringLiteral PROP_FillGradientName
constexpr OUStringLiteral PROP_FillBackground
constexpr OUStringLiteral PROP_Transparency
constexpr OUStringLiteral PROP_LineColor
constexpr OUStringLiteral PROP_LineWidth
constexpr OUStringLiteral PROP_FillHatchName
constexpr OUStringLiteral PROP_TextRotation
constexpr OUStringLiteral PROP_FillBitmapPositionOffsetY
constexpr OUStringLiteral PROP_BorderColor
constexpr OUStringLiteral PROP_FillColor
constexpr OUStringLiteral PROP_FillBitmapName
constexpr OUStringLiteral PROP_LinkNumberFormatToSource
constexpr OUStringLiteral PROP_FillBitmapRectanglePoint
constexpr OUStringLiteral PROP_PercentageNumberFormat
constexpr OUStringLiteral PROP_NumberFormat
constexpr OUStringLiteral PROP_LineStyle
constexpr OUStringLiteral PROP_FillBitmapSizeX
constexpr OUStringLiteral PROP_LineCap
constexpr OUStringLiteral PROP_FillBitmapSizeY
constexpr OUStringLiteral PROP_LineTransparence
constexpr OUStringLiteral PROP_FillStyle