1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <PropertyMapper.hxx>
21 #include <unonames.hxx>
23 #include <com/sun/star/beans/XMultiPropertySet.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
26 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
27 #include <com/sun/star/drawing/LineJoint.hpp>
28 #include <com/sun/star/style/ParagraphAdjust.hpp>
29 #include <comphelper/diagnose_ex.hxx>
30 #include <svx/unoshape.hxx>
34 using namespace ::com::sun::star
;
36 void PropertyMapper::setMappedProperties(
38 , const uno::Reference
< beans::XPropertySet
>& xSource
39 , const tPropertyNameMap
& rMap
)
44 sal_Int32 nPropertyCount
= rMap
.size();
45 tNameSequence
aNames(nPropertyCount
);
46 tAnySequence
aValues(nPropertyCount
);
47 auto pNames
= aNames
.getArray();
48 auto pValues
= aValues
.getArray();
51 for (auto const& elem
: rMap
)
53 const OUString
& rTarget
= elem
.first
;
54 const OUString
& rSource
= elem
.second
;
57 uno::Any
aAny( xSource
->getPropertyValue(rSource
) );
60 //do not set empty anys because of performance (otherwise SdrAttrObj::ItemChange will take much longer)
62 pValues
[nN
] = std::move(aAny
);
66 catch( const uno::Exception
& )
68 TOOLS_WARN_EXCEPTION("chart2", "" );
73 //reduce to real property count
77 uno::Reference
< beans::XMultiPropertySet
> xShapeMultiProp( xTarget
, uno::UNO_QUERY_THROW
);
80 xShapeMultiProp
->setPropertyValues( aNames
, aValues
);
82 catch( const uno::Exception
& )
84 TOOLS_WARN_EXCEPTION("chart2", "" ); //if this occurs more often think of removing the XMultiPropertySet completely for better performance
88 void PropertyMapper::setMappedProperties(
89 const uno::Reference
< beans::XPropertySet
>& xTarget
90 , const uno::Reference
< beans::XPropertySet
>& xSource
91 , const tPropertyNameMap
& rMap
)
93 if( !xTarget
.is() || !xSource
.is() )
99 sal_Int32 nPropertyCount
= rMap
.size();
100 aNames
.realloc(nPropertyCount
);
101 auto pNames
= aNames
.getArray();
102 aValues
.realloc(nPropertyCount
);
103 auto pValues
= aValues
.getArray();
105 for (auto const& elem
: rMap
)
107 const OUString
& rTarget
= elem
.first
;
108 const OUString
& rSource
= elem
.second
;
111 uno::Any
aAny( xSource
->getPropertyValue(rSource
) );
112 if( aAny
.hasValue() )
114 //do not set empty anys because of performance (otherwise SdrAttrObj::ItemChange will take much longer)
115 pNames
[nN
] = rTarget
;
116 pValues
[nN
] = std::move(aAny
);
120 catch( const uno::Exception
& )
122 TOOLS_WARN_EXCEPTION("chart2", "exception mapping property from " << rSource
<< " to " << rTarget
);
128 uno::Reference
< beans::XMultiPropertySet
> xShapeMultiProp( xTarget
, uno::UNO_QUERY
);
132 //reduce to real property count
135 xShapeMultiProp
->setPropertyValues( aNames
, aValues
);
136 return; // successful
138 catch( const uno::Exception
& )
140 TOOLS_WARN_EXCEPTION("chart2", "" ); //if this occurs more often think of removing the XMultiPropertySet completely for better performance
143 // fall back to one at a time
146 for( sal_Int32 i
= 0; i
< nN
; i
++ )
150 xTarget
->setPropertyValue( aNames
[i
], aValues
[i
] );
152 catch( const uno::Exception
& )
154 TOOLS_WARN_EXCEPTION("chart2", "" );
158 catch( const uno::Exception
& )
160 TOOLS_WARN_EXCEPTION("chart2", "" );
164 void PropertyMapper::getValueMap(
165 tPropertyNameValueMap
& rValueMap
166 , const tPropertyNameMap
& rNameMap
167 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
170 uno::Reference
< beans::XMultiPropertySet
> xMultiPropSet(xSourceProp
, uno::UNO_QUERY
);
171 if((false) && xMultiPropSet
.is())
173 uno::Sequence
< OUString
> aPropSourceNames(rNameMap
.size());
174 auto aPropSourceNamesRange
= asNonConstRange(aPropSourceNames
);
175 uno::Sequence
< OUString
> aPropTargetNames(rNameMap
.size());
176 auto aPropTargetNamesRange
= asNonConstRange(aPropTargetNames
);
178 for (auto const& elem
: rNameMap
)
180 aPropTargetNamesRange
[i
] = elem
.first
;
181 aPropSourceNamesRange
[i
] = elem
.second
;
185 uno::Sequence
< uno::Any
> xValues
= xMultiPropSet
->getPropertyValues(aPropSourceNames
);
186 sal_Int32 n
= rNameMap
.size();
187 for(i
= 0;i
< n
; ++i
)
189 if( xValues
[i
].hasValue() )
190 rValueMap
.emplace( aPropTargetNames
[i
], xValues
[i
] );
195 for (auto const& elem
: rNameMap
)
197 const OUString
& rTarget
= elem
.first
;
198 const OUString
& rSource
= elem
.second
;
201 uno::Any
aAny( xSourceProp
->getPropertyValue(rSource
) );
202 if( aAny
.hasValue() )
203 rValueMap
.emplace( rTarget
, aAny
);
205 catch( const uno::Exception
& )
207 TOOLS_WARN_EXCEPTION("chart2", "" );
213 void PropertyMapper::getMultiPropertyListsFromValueMap(
214 tNameSequence
& rNames
215 , tAnySequence
& rValues
216 , const tPropertyNameValueMap
& rValueMap
219 sal_Int32 nPropertyCount
= rValueMap
.size();
220 rNames
.realloc(nPropertyCount
);
221 auto pNames
= rNames
.getArray();
222 rValues
.realloc(nPropertyCount
);
223 auto pValues
= rValues
.getArray();
227 for (auto const& elem
: rValueMap
)
229 const uno::Any
& rAny
= elem
.second
;
230 if( rAny
.hasValue() )
232 //do not set empty anys because of performance (otherwise SdrAttrObj::ItemChange will take much longer)
233 pNames
[nN
] = elem
.first
;
238 //reduce to real property count
243 uno::Any
* PropertyMapper::getValuePointer( tAnySequence
& rPropValues
244 , const tNameSequence
& rPropNames
245 , std::u16string_view rPropName
)
247 sal_Int32 nCount
= rPropNames
.getLength();
248 for( sal_Int32 nN
= 0; nN
< nCount
; nN
++ )
250 if(rPropNames
[nN
] == rPropName
)
251 return &rPropValues
.getArray()[nN
];
256 uno::Any
* PropertyMapper::getValuePointerForLimitedSpace( tAnySequence
& rPropValues
257 , const tNameSequence
& rPropNames
258 , bool bLimitedHeight
)
260 return PropertyMapper::getValuePointer( rPropValues
, rPropNames
261 , bLimitedHeight
? u
"TextMaximumFrameHeight"_ustr
: u
"TextMaximumFrameWidth"_ustr
);
264 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForCharacterProperties()
266 //shape property -- chart model object property
267 static tPropertyNameMap s_aShapePropertyMapForCharacterProperties
{
268 {"CharColor", "CharColor"},
269 {"CharContoured", "CharContoured"},
270 {"CharEmphasis", "CharEmphasis"},//the service style::CharacterProperties describes a property called 'CharEmphasize' which is nowhere implemented
271 {"CharEscapement", "CharEscapement"},
272 {"CharEscapementHeight", "CharEscapementHeight"},
273 {"CharFontFamily", "CharFontFamily"},
274 {"CharFontFamilyAsian", "CharFontFamilyAsian"},
275 {"CharFontFamilyComplex", "CharFontFamilyComplex"},
276 {"CharFontCharSet", "CharFontCharSet"},
277 {"CharFontCharSetAsian", "CharFontCharSetAsian"},
278 {"CharFontCharSetComplex", "CharFontCharSetComplex"},
279 {"CharFontName", "CharFontName"},
280 {"CharFontNameAsian", "CharFontNameAsian"},
281 {"CharFontNameComplex", "CharFontNameComplex"},
282 {"CharFontPitch", "CharFontPitch"},
283 {"CharFontPitchAsian", "CharFontPitchAsian"},
284 {"CharFontPitchComplex", "CharFontPitchComplex"},
285 {"CharFontStyleName", "CharFontStyleName"},
286 {"CharFontStyleNameAsian", "CharFontStyleNameAsian"},
287 {"CharFontStyleNameComplex", "CharFontStyleNameComplex"},
289 {"CharHeight", "CharHeight"},
290 {"CharHeightAsian", "CharHeightAsian"},
291 {"CharHeightComplex", "CharHeightComplex"},
292 {"CharKerning", "CharKerning"},
293 {"CharLocale", "CharLocale"},
294 {"CharLocaleAsian", "CharLocaleAsian"},
295 {"CharLocaleComplex", "CharLocaleComplex"},
296 {"CharPosture", "CharPosture"},
297 {"CharPostureAsian", "CharPostureAsian"},
298 {"CharPostureComplex", "CharPostureComplex"},
299 {"CharRelief", "CharRelief"},
300 {"CharShadowed", "CharShadowed"},
301 {"CharStrikeout", "CharStrikeout"},
302 {"CharUnderline", "CharUnderline"},
303 {"CharUnderlineColor", "CharUnderlineColor"},
304 {"CharUnderlineHasColor", "CharUnderlineHasColor"},
305 {"CharOverline", "CharOverline"},
306 {"CharOverlineColor", "CharOverlineColor"},
307 {"CharOverlineHasColor", "CharOverlineHasColor"},
308 {"CharWeight", "CharWeight"},
309 {"CharWeightAsian", "CharWeightAsian"},
310 {"CharWeightComplex", "CharWeightComplex"},
311 {"CharWordMode", "CharWordMode"},
313 {"WritingMode", "WritingMode"},
315 {"ParaIsCharacterDistance", "ParaIsCharacterDistance"}};
317 return s_aShapePropertyMapForCharacterProperties
;
320 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForParagraphProperties()
322 //shape property -- chart model object property
323 static tPropertyNameMap s_aShapePropertyMapForParagraphProperties
{
324 {"ParaAdjust", "ParaAdjust"},
325 {"ParaBottomMargin", "ParaBottomMargin"},
326 {"ParaIsHyphenation", "ParaIsHyphenation"},
327 {"ParaLastLineAdjust", "ParaLastLineAdjust"},
328 {"ParaLeftMargin", "ParaLeftMargin"},
329 {"ParaRightMargin", "ParaRightMargin"},
330 {"ParaTopMargin", "ParaTopMargin"}};
331 return s_aShapePropertyMapForParagraphProperties
;
334 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForFillProperties()
336 //shape property -- chart model object property
337 static tPropertyNameMap s_aShapePropertyMapForFillProperties
{
338 {"FillBackground", "FillBackground"},
339 {"FillBitmapName", "FillBitmapName"},
340 {"FillColor", "FillColor"},
341 {"FillGradientName", "FillGradientName"},
342 {"FillGradientStepCount", "FillGradientStepCount"},
343 {"FillHatchName", "FillHatchName"},
344 {"FillStyle", "FillStyle"},
345 {"FillTransparence", "FillTransparence"},
346 {"FillTransparenceGradientName", "FillTransparenceGradientName"},
348 {"FillBitmapMode", "FillBitmapMode"},
349 {"FillBitmapSizeX", "FillBitmapSizeX"},
350 {"FillBitmapSizeY", "FillBitmapSizeY"},
351 {"FillBitmapLogicalSize", "FillBitmapLogicalSize"},
352 {"FillBitmapOffsetX", "FillBitmapOffsetX"},
353 {"FillBitmapOffsetY", "FillBitmapOffsetY"},
354 {"FillBitmapRectanglePoint", "FillBitmapRectanglePoint"},
355 {"FillBitmapPositionOffsetX", "FillBitmapPositionOffsetX"},
356 {"FillBitmapPositionOffsetY", "FillBitmapPositionOffsetY"}};
357 return s_aShapePropertyMapForFillProperties
;
360 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForLineProperties()
362 //shape property -- chart model object property
363 static tPropertyNameMap s_aShapePropertyMapForLineProperties
{
364 {"LineColor", "LineColor"},
365 {"LineDashName", "LineDashName"},
366 {"LineJoint", "LineJoint"},
367 {"LineStyle", "LineStyle"},
368 {"LineTransparence", "LineTransparence"},
369 {"LineWidth", "LineWidth"},
370 {"LineCap", "LineCap"}};
371 return s_aShapePropertyMapForLineProperties
;
375 tPropertyNameMap
getPropertyNameMapForFillAndLineProperties_() {
376 auto map
= PropertyMapper::getPropertyNameMapForFillProperties();
378 = PropertyMapper::getPropertyNameMapForLineProperties();
379 map
.insert(add
.begin(), add
.end());
383 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForFillAndLineProperties()
385 static tPropertyNameMap s_aShapePropertyMapForFillAndLineProperties
386 = getPropertyNameMapForFillAndLineProperties_();
387 return s_aShapePropertyMapForFillAndLineProperties
;
391 tPropertyNameMap
getPropertyNameMapForTextShapeProperties_() {
392 auto map
= PropertyMapper::getPropertyNameMapForCharacterProperties();
394 = PropertyMapper::getPropertyNameMapForFillProperties();
395 map
.insert(add1
.begin(), add1
.end());
397 = PropertyMapper::getPropertyNameMapForLineProperties();
398 map
.insert(add2
.begin(), add2
.end());
402 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForTextShapeProperties()
404 static tPropertyNameMap s_aShapePropertyMapForTextShapeProperties
405 = getPropertyNameMapForTextShapeProperties_();
406 return s_aShapePropertyMapForTextShapeProperties
;
409 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForLineSeriesProperties()
411 //shape property -- chart model object property
412 static tPropertyNameMap s_aShapePropertyMapForLineSeriesProperties
{
413 {"LineColor", "Color"},
414 {"LineDashName", "LineDashName"},
415 {"LineStyle", "LineStyle"},
416 {"LineTransparence", "Transparency"},
417 {"LineWidth", "LineWidth"},
418 {"LineCap", "LineCap"}};
419 return s_aShapePropertyMapForLineSeriesProperties
;
423 tPropertyNameMap
getPropertyNameMapForTextLabelProperties_() {
424 auto map
= PropertyMapper::getPropertyNameMapForCharacterProperties();
426 {"LineStyle", CHART_UNONAME_LABEL_BORDER_STYLE
},
427 {"LineWidth", CHART_UNONAME_LABEL_BORDER_WIDTH
},
428 {"LineColor", CHART_UNONAME_LABEL_BORDER_COLOR
},
429 {"LineTransparence", CHART_UNONAME_LABEL_BORDER_TRANS
},
430 {"FillStyle", CHART_UNONAME_LABEL_FILL_STYLE
},
431 {"FillColor", CHART_UNONAME_LABEL_FILL_COLOR
},
432 {"FillBackground", CHART_UNONAME_LABEL_FILL_BACKGROUND
},
433 {"FillHatchName", CHART_UNONAME_LABEL_FILL_HATCH_NAME
}
439 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForTextLabelProperties()
441 // target name (drawing layer) : source name (chart model)
442 static tPropertyNameMap aMap
= getPropertyNameMapForTextLabelProperties_();
446 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForFilledSeriesProperties()
448 //shape property -- chart model object property
449 static tPropertyNameMap s_aShapePropertyMapForFilledSeriesProperties
{
450 {"FillBackground", "FillBackground"},
451 {"FillBitmapName", "FillBitmapName"},
452 {"FillColor", "Color"},
453 {"FillGradientName", "GradientName"},
454 {"FillGradientStepCount", "GradientStepCount"},
455 {"FillHatchName", "HatchName"},
456 {"FillStyle", "FillStyle"},
457 {"FillTransparence", "Transparency"},
458 {"FillTransparenceGradientName", "TransparencyGradientName"},
460 {"FillBitmapMode", "FillBitmapMode"},
461 {"FillBitmapSizeX", "FillBitmapSizeX"},
462 {"FillBitmapSizeY", "FillBitmapSizeY"},
463 {"FillBitmapLogicalSize", "FillBitmapLogicalSize"},
464 {"FillBitmapOffsetX", "FillBitmapOffsetX"},
465 {"FillBitmapOffsetY", "FillBitmapOffsetY"},
466 {"FillBitmapRectanglePoint", "FillBitmapRectanglePoint"},
467 {"FillBitmapPositionOffsetX", "FillBitmapPositionOffsetX"},
468 {"FillBitmapPositionOffsetY", "FillBitmapPositionOffsetY"},
470 {"LineColor", "BorderColor"},
471 {"LineDashName", "BorderDashName"},
472 {"LineStyle", "BorderStyle"},
473 {"LineTransparence", "BorderTransparency"},
474 {"LineWidth", "BorderWidth"},
475 {"LineCap", "LineCap"}};
476 return s_aShapePropertyMapForFilledSeriesProperties
;
479 void PropertyMapper::setMultiProperties(
480 const tNameSequence
& rNames
481 , const tAnySequence
& rValues
482 , SvxShape
& xTarget
)
486 xTarget
.setPropertyValues( rNames
, rValues
);
488 catch( const uno::Exception
& )
490 TOOLS_WARN_EXCEPTION("chart2", "" ); //if this occurs more often think of removing the XMultiPropertySet completely for better performance
494 void PropertyMapper::getTextLabelMultiPropertyLists(
495 const uno::Reference
< beans::XPropertySet
>& xSourceProp
496 , tNameSequence
& rPropNames
, tAnySequence
& rPropValues
498 , sal_Int32 nLimitedSpace
499 , bool bLimitedHeight
500 , bool bSupportsLabelBorder
)
502 //fill character properties into the ValueMap
503 tPropertyNameValueMap aValueMap
;
504 tPropertyNameMap
const & aNameMap
= bSupportsLabelBorder
? PropertyMapper::getPropertyNameMapForTextLabelProperties() : getPropertyNameMapForCharacterProperties();
506 PropertyMapper::getValueMap(aValueMap
, aNameMap
, xSourceProp
);
508 //some more shape properties apart from character properties, position-matrix and label string
509 aValueMap
.emplace( "TextHorizontalAdjust", uno::Any(drawing::TextHorizontalAdjust_CENTER
) ); // drawing::TextHorizontalAdjust - needs to be overwritten
510 aValueMap
.emplace( "TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_CENTER
) ); //drawing::TextVerticalAdjust - needs to be overwritten
511 aValueMap
.emplace( "TextAutoGrowHeight", uno::Any(true) ); // sal_Bool
512 aValueMap
.emplace( "TextAutoGrowWidth", uno::Any(true) ); // sal_Bool
513 aValueMap
.emplace( "ParaAdjust", uno::Any(style::ParagraphAdjust_CENTER
) ); // style::ParagraphAdjust_CENTER - needs to be overwritten
515 aValueMap
.emplace( "Name", uno::Any( OUString() ) ); //CID OUString - needs to be overwritten for each point
517 if( nLimitedSpace
> 0 )
520 aValueMap
.emplace( "TextMaximumFrameHeight", uno::Any(nLimitedSpace
) ); //sal_Int32
522 aValueMap
.emplace( "TextMaximumFrameWidth", uno::Any(nLimitedSpace
) ); //sal_Int32
523 aValueMap
.emplace( "ParaIsHyphenation", uno::Any(true) );
526 PropertyMapper::getMultiPropertyListsFromValueMap( rPropNames
, rPropValues
, aValueMap
);
529 void PropertyMapper::getPreparedTextShapePropertyLists(
530 const uno::Reference
< beans::XPropertySet
>& xSourceProp
531 , tNameSequence
& rPropNames
, tAnySequence
& rPropValues
)
533 //fill character, line and fill properties into the ValueMap
534 tPropertyNameValueMap aValueMap
;
535 PropertyMapper::getValueMap( aValueMap
536 , PropertyMapper::getPropertyNameMapForTextShapeProperties()
539 // auto-grow makes sure the shape has the correct size after setting text
540 aValueMap
.emplace( "TextHorizontalAdjust", uno::Any( drawing::TextHorizontalAdjust_CENTER
));
541 aValueMap
.emplace( "TextVerticalAdjust", uno::Any( drawing::TextVerticalAdjust_CENTER
));
542 aValueMap
.emplace( "TextAutoGrowHeight", uno::Any( true ));
543 aValueMap
.emplace( "TextAutoGrowWidth", uno::Any( true ));
545 // set some distance to the border, in case it is shown
546 const sal_Int32 nWidthDist
= 250;
547 const sal_Int32 nHeightDist
= 125;
548 aValueMap
.emplace( "TextLeftDistance", uno::Any( nWidthDist
));
549 aValueMap
.emplace( "TextRightDistance", uno::Any( nWidthDist
));
550 aValueMap
.emplace( "TextUpperDistance", uno::Any( nHeightDist
));
551 aValueMap
.emplace( "TextLowerDistance", uno::Any( nHeightDist
));
553 // use a line-joint showing the border of thick lines like two rectangles
554 // filled in between.
555 aValueMap
[u
"LineJoint"_ustr
] <<= drawing::LineJoint_ROUND
;
557 PropertyMapper::getMultiPropertyListsFromValueMap( rPropNames
, rPropValues
, aValueMap
);
562 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */