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/drawing/LineStyle.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 <comphelper/sequence.hxx>
32 using namespace ::com::sun::star
;
37 void lcl_overwriteOrAppendValues(
38 tPropertyNameValueMap
&rMap
, const tPropertyNameValueMap
& rOverwriteMap
)
40 for (auto const& elem
: rOverwriteMap
)
41 rMap
[ elem
.first
] = elem
.second
;
44 } // anonymous namespace
46 void PropertyMapper::setMappedProperties(
47 const uno::Reference
< beans::XPropertySet
>& xTarget
48 , const uno::Reference
< beans::XPropertySet
>& xSource
49 , const tPropertyNameMap
& rMap
50 , tPropertyNameValueMap
const * pOverwriteMap
)
52 if( !xTarget
.is() || !xSource
.is() )
57 getMultiPropertyLists(aNames
, aValues
, xSource
, rMap
);
58 if(pOverwriteMap
&& (aNames
.getLength() == aValues
.getLength()))
60 tPropertyNameValueMap aNewMap
;
61 for( sal_Int32 nI
=0; nI
<aNames
.getLength(); ++nI
)
62 aNewMap
[ aNames
[nI
] ] = aValues
[nI
];
63 lcl_overwriteOrAppendValues( aNewMap
, *pOverwriteMap
);
64 aNames
= comphelper::mapKeysToSequence( aNewMap
);
65 aValues
= comphelper::mapValuesToSequence( aNewMap
);
68 PropertyMapper::setMultiProperties( aNames
, aValues
, xTarget
);
71 void PropertyMapper::getValueMap(
72 tPropertyNameValueMap
& rValueMap
73 , const tPropertyNameMap
& rNameMap
74 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
77 uno::Reference
< beans::XMultiPropertySet
> xMultiPropSet(xSourceProp
, uno::UNO_QUERY
);
78 if((false) && xMultiPropSet
.is())
80 uno::Sequence
< rtl::OUString
> aPropSourceNames(rNameMap
.size());
81 uno::Sequence
< rtl::OUString
> aPropTargetNames(rNameMap
.size());
83 for (auto const& elem
: rNameMap
)
85 aPropTargetNames
[i
] = elem
.first
;
86 aPropSourceNames
[i
] = elem
.second
;
90 uno::Sequence
< uno::Any
> xValues
= xMultiPropSet
->getPropertyValues(aPropSourceNames
);
91 sal_Int32 n
= rNameMap
.size();
94 if( xValues
[i
].hasValue() )
95 rValueMap
.emplace( aPropTargetNames
[i
], xValues
[i
] );
100 for (auto const& elem
: rNameMap
)
102 OUString aTarget
= elem
.first
;
103 OUString aSource
= elem
.second
;
106 uno::Any
aAny( xSourceProp
->getPropertyValue(aSource
) );
107 if( aAny
.hasValue() )
108 rValueMap
.emplace( aTarget
, aAny
);
110 catch( const uno::Exception
& e
)
112 SAL_WARN("chart2", "Exception caught. " << e
);
118 void PropertyMapper::getMultiPropertyLists(
119 tNameSequence
& rNames
120 , tAnySequence
& rValues
121 , const uno::Reference
< beans::XPropertySet
>& xSourceProp
122 , const tPropertyNameMap
& rNameMap
125 tPropertyNameValueMap aValueMap
;
126 getValueMap( aValueMap
, rNameMap
, xSourceProp
);
127 getMultiPropertyListsFromValueMap( rNames
, rValues
, aValueMap
);
130 void PropertyMapper::getMultiPropertyListsFromValueMap(
131 tNameSequence
& rNames
132 , tAnySequence
& rValues
133 , const tPropertyNameValueMap
& rValueMap
136 sal_Int32 nPropertyCount
= rValueMap
.size();
137 rNames
.realloc(nPropertyCount
);
138 rValues
.realloc(nPropertyCount
);
142 for (auto const& elem
: rValueMap
)
144 const uno::Any
& rAny
= elem
.second
;
145 if( rAny
.hasValue() )
147 //do not set empty anys because of performance (otherwise SdrAttrObj::ItemChange will take much longer)
148 rNames
[nN
] = elem
.first
;
153 //reduce to real property count
158 uno::Any
* PropertyMapper::getValuePointer( tAnySequence
& rPropValues
159 , const tNameSequence
& rPropNames
160 , const OUString
& rPropName
)
162 sal_Int32 nCount
= rPropNames
.getLength();
163 for( sal_Int32 nN
= 0; nN
< nCount
; nN
++ )
165 if(rPropNames
[nN
] == rPropName
)
166 return &rPropValues
[nN
];
171 uno::Any
* PropertyMapper::getValuePointerForLimitedSpace( tAnySequence
& rPropValues
172 , const tNameSequence
& rPropNames
173 , bool bLimitedHeight
)
175 return PropertyMapper::getValuePointer( rPropValues
, rPropNames
176 , bLimitedHeight
? OUString("TextMaximumFrameHeight") : OUString("TextMaximumFrameWidth") );
179 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForCharacterProperties()
181 //shape property -- chart model object property
182 static tPropertyNameMap s_aShapePropertyMapForCharacterProperties
{
183 {"CharColor", "CharColor"},
184 {"CharContoured", "CharContoured"},
185 {"CharEmphasis", "CharEmphasis"},//the service style::CharacterProperties describes a property called 'CharEmphasize' which is nowhere implemented
187 {"CharFontFamily", "CharFontFamily"},
188 {"CharFontFamilyAsian", "CharFontFamilyAsian"},
189 {"CharFontFamilyComplex", "CharFontFamilyComplex"},
190 {"CharFontCharSet", "CharFontCharSet"},
191 {"CharFontCharSetAsian", "CharFontCharSetAsian"},
192 {"CharFontCharSetComplex", "CharFontCharSetComplex"},
193 {"CharFontName", "CharFontName"},
194 {"CharFontNameAsian", "CharFontNameAsian"},
195 {"CharFontNameComplex", "CharFontNameComplex"},
196 {"CharFontPitch", "CharFontPitch"},
197 {"CharFontPitchAsian", "CharFontPitchAsian"},
198 {"CharFontPitchComplex", "CharFontPitchComplex"},
199 {"CharFontStyleName", "CharFontStyleName"},
200 {"CharFontStyleNameAsian", "CharFontStyleNameAsian"},
201 {"CharFontStyleNameComplex", "CharFontStyleNameComplex"},
203 {"CharHeight", "CharHeight"},
204 {"CharHeightAsian", "CharHeightAsian"},
205 {"CharHeightComplex", "CharHeightComplex"},
206 {"CharKerning", "CharKerning"},
207 {"CharLocale", "CharLocale"},
208 {"CharLocaleAsian", "CharLocaleAsian"},
209 {"CharLocaleComplex", "CharLocaleComplex"},
210 {"CharPosture", "CharPosture"},
211 {"CharPostureAsian", "CharPostureAsian"},
212 {"CharPostureComplex", "CharPostureComplex"},
213 {"CharRelief", "CharRelief"},
214 {"CharShadowed", "CharShadowed"},
215 {"CharStrikeout", "CharStrikeout"},
216 {"CharUnderline", "CharUnderline"},
217 {"CharUnderlineColor", "CharUnderlineColor"},
218 {"CharUnderlineHasColor", "CharUnderlineHasColor"},
219 {"CharOverline", "CharOverline"},
220 {"CharOverlineColor", "CharOverlineColor"},
221 {"CharOverlineHasColor", "CharOverlineHasColor"},
222 {"CharWeight", "CharWeight"},
223 {"CharWeightAsian", "CharWeightAsian"},
224 {"CharWeightComplex", "CharWeightComplex"},
225 {"CharWordMode", "CharWordMode"},
227 {"WritingMode", "WritingMode"},
229 {"ParaIsCharacterDistance", "ParaIsCharacterDistance"}};
231 return s_aShapePropertyMapForCharacterProperties
;
234 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForParagraphProperties()
236 //shape property -- chart model object property
237 static tPropertyNameMap s_aShapePropertyMapForParagraphProperties
{
238 {"ParaAdjust", "ParaAdjust"},
239 {"ParaBottomMargin", "ParaBottomMargin"},
240 {"ParaIsHyphenation", "ParaIsHyphenation"},
241 {"ParaLastLineAdjust", "ParaLastLineAdjust"},
242 {"ParaLeftMargin", "ParaLeftMargin"},
243 {"ParaRightMargin", "ParaRightMargin"},
244 {"ParaTopMargin", "ParaTopMargin"}};
245 return s_aShapePropertyMapForParagraphProperties
;
248 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForFillProperties()
250 //shape property -- chart model object property
251 static tPropertyNameMap s_aShapePropertyMapForFillProperties
{
252 {"FillBackground", "FillBackground"},
253 {"FillBitmapName", "FillBitmapName"},
254 {"FillColor", "FillColor"},
255 {"FillGradientName", "FillGradientName"},
256 {"FillGradientStepCount", "FillGradientStepCount"},
257 {"FillHatchName", "FillHatchName"},
258 {"FillStyle", "FillStyle"},
259 {"FillTransparence", "FillTransparence"},
260 {"FillTransparenceGradientName", "FillTransparenceGradientName"},
262 {"FillBitmapMode", "FillBitmapMode"},
263 {"FillBitmapSizeX", "FillBitmapSizeX"},
264 {"FillBitmapSizeY", "FillBitmapSizeY"},
265 {"FillBitmapLogicalSize", "FillBitmapLogicalSize"},
266 {"FillBitmapOffsetX", "FillBitmapOffsetX"},
267 {"FillBitmapOffsetY", "FillBitmapOffsetY"},
268 {"FillBitmapRectanglePoint", "FillBitmapRectanglePoint"},
269 {"FillBitmapPositionOffsetX", "FillBitmapPositionOffsetX"},
270 {"FillBitmapPositionOffsetY", "FillBitmapPositionOffsetY"}};
271 return s_aShapePropertyMapForFillProperties
;
274 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForLineProperties()
276 //shape property -- chart model object property
277 static tPropertyNameMap s_aShapePropertyMapForLineProperties
{
278 {"LineColor", "LineColor"},
279 {"LineDashName", "LineDashName"},
280 {"LineJoint", "LineJoint"},
281 {"LineStyle", "LineStyle"},
282 {"LineTransparence", "LineTransparence"},
283 {"LineWidth", "LineWidth"}};
284 return s_aShapePropertyMapForLineProperties
;
288 tPropertyNameMap
getPropertyNameMapForFillAndLineProperties_() {
289 auto map
= PropertyMapper::getPropertyNameMapForFillProperties();
291 = PropertyMapper::getPropertyNameMapForLineProperties();
292 map
.insert(add
.begin(), add
.end());
296 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForFillAndLineProperties()
298 static tPropertyNameMap s_aShapePropertyMapForFillAndLineProperties
299 = getPropertyNameMapForFillAndLineProperties_();
300 return s_aShapePropertyMapForFillAndLineProperties
;
304 tPropertyNameMap
getPropertyNameMapForTextShapeProperties_() {
305 auto map
= PropertyMapper::getPropertyNameMapForCharacterProperties();
307 = PropertyMapper::getPropertyNameMapForFillProperties();
308 map
.insert(add1
.begin(), add1
.end());
310 = PropertyMapper::getPropertyNameMapForLineProperties();
311 map
.insert(add2
.begin(), add2
.end());
315 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForTextShapeProperties()
317 static tPropertyNameMap s_aShapePropertyMapForTextShapeProperties
318 = getPropertyNameMapForTextShapeProperties_();
319 return s_aShapePropertyMapForTextShapeProperties
;
322 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForLineSeriesProperties()
324 //shape property -- chart model object property
325 static tPropertyNameMap s_aShapePropertyMapForLineSeriesProperties
{
326 {"LineColor", "Color"},
327 {"LineDashName", "LineDashName"},
328 {"LineStyle", "LineStyle"},
329 {"LineTransparence", "Transparency"},
330 {"LineWidth", "LineWidth"}};
331 return s_aShapePropertyMapForLineSeriesProperties
;
335 tPropertyNameMap
getPropertyNameMapForTextLabelProperties_() {
336 auto map
= PropertyMapper::getPropertyNameMapForCharacterProperties();
338 {"LineStyle", CHART_UNONAME_LABEL_BORDER_STYLE
},
339 {"LineWidth", CHART_UNONAME_LABEL_BORDER_WIDTH
},
340 {"LineColor", CHART_UNONAME_LABEL_BORDER_COLOR
},
341 {"LineTransparence", CHART_UNONAME_LABEL_BORDER_TRANS
}});
346 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForTextLabelProperties()
348 // target name (drawing layer) : source name (chart model)
349 static tPropertyNameMap aMap
= getPropertyNameMapForTextLabelProperties_();
353 const tPropertyNameMap
& PropertyMapper::getPropertyNameMapForFilledSeriesProperties()
355 //shape property -- chart model object property
356 static tPropertyNameMap s_aShapePropertyMapForFilledSeriesProperties
{
357 {"FillBackground", "FillBackground"},
358 {"FillBitmapName", "FillBitmapName"},
359 {"FillColor", "Color"},
360 {"FillGradientName", "GradientName"},
361 {"FillGradientStepCount", "GradientStepCount"},
362 {"FillHatchName", "HatchName"},
363 {"FillStyle", "FillStyle"},
364 {"FillTransparence", "Transparency"},
365 {"FillTransparenceGradientName", "TransparencyGradientName"},
367 {"FillBitmapMode", "FillBitmapMode"},
368 {"FillBitmapSizeX", "FillBitmapSizeX"},
369 {"FillBitmapSizeY", "FillBitmapSizeY"},
370 {"FillBitmapLogicalSize", "FillBitmapLogicalSize"},
371 {"FillBitmapOffsetX", "FillBitmapOffsetX"},
372 {"FillBitmapOffsetY", "FillBitmapOffsetY"},
373 {"FillBitmapRectanglePoint", "FillBitmapRectanglePoint"},
374 {"FillBitmapPositionOffsetX", "FillBitmapPositionOffsetX"},
375 {"FillBitmapPositionOffsetY", "FillBitmapPositionOffsetY"},
377 {"LineColor", "BorderColor"},
378 {"LineDashName", "BorderDashName"},
379 {"LineStyle", "BorderStyle"},
380 {"LineTransparence", "BorderTransparency"},
381 {"LineWidth", "BorderWidth"}};
382 return s_aShapePropertyMapForFilledSeriesProperties
;
385 void PropertyMapper::setMultiProperties(
386 const tNameSequence
& rNames
387 , const tAnySequence
& rValues
388 , const css::uno::Reference
<
389 css::beans::XPropertySet
>& xTarget
)
391 bool bSuccess
= false;
394 uno::Reference
< beans::XMultiPropertySet
> xShapeMultiProp( xTarget
, uno::UNO_QUERY
);
395 if( xShapeMultiProp
.is() )
397 xShapeMultiProp
->setPropertyValues( rNames
, rValues
);
401 catch( const uno::Exception
& e
)
403 SAL_WARN("chart2", "Exception caught. " << e
); //if this occurs more often think of removing the XMultiPropertySet completely for better performance
409 sal_Int32 nCount
= std::max( rNames
.getLength(), rValues
.getLength() );
412 for( sal_Int32 nN
= 0; nN
< nCount
; nN
++ )
414 aPropName
= rNames
[nN
];
415 aValue
= rValues
[nN
];
419 xTarget
->setPropertyValue( aPropName
, aValue
);
421 catch( const uno::Exception
& e
)
423 SAL_WARN("chart2", "Exception caught. " << e
);
427 catch( const uno::Exception
& e
)
429 SAL_WARN("chart2", "Exception caught. " << e
);
433 void PropertyMapper::getTextLabelMultiPropertyLists(
434 const uno::Reference
< beans::XPropertySet
>& xSourceProp
435 , tNameSequence
& rPropNames
, tAnySequence
& rPropValues
437 , sal_Int32 nLimitedSpace
438 , bool bLimitedHeight
439 , bool bSupportsLabelBorder
)
441 //fill character properties into the ValueMap
442 tPropertyNameValueMap aValueMap
;
443 tPropertyNameMap
const & aNameMap
= bSupportsLabelBorder
? PropertyMapper::getPropertyNameMapForTextLabelProperties() : getPropertyNameMapForCharacterProperties();
445 PropertyMapper::getValueMap(aValueMap
, aNameMap
, xSourceProp
);
447 //some more shape properties apart from character properties, position-matrix and label string
448 aValueMap
.emplace( "TextHorizontalAdjust", uno::Any(drawing::TextHorizontalAdjust_CENTER
) ); // drawing::TextHorizontalAdjust - needs to be overwritten
449 aValueMap
.emplace( "TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_CENTER
) ); //drawing::TextVerticalAdjust - needs to be overwritten
450 aValueMap
.emplace( "TextAutoGrowHeight", uno::Any(true) ); // sal_Bool
451 aValueMap
.emplace( "TextAutoGrowWidth", uno::Any(true) ); // sal_Bool
453 aValueMap
.emplace( "Name", uno::Any( OUString() ) ); //CID OUString - needs to be overwritten for each point
455 if( nLimitedSpace
> 0 )
458 aValueMap
.emplace( "TextMaximumFrameHeight", uno::Any(nLimitedSpace
) ); //sal_Int32
460 aValueMap
.emplace( "TextMaximumFrameWidth", uno::Any(nLimitedSpace
) ); //sal_Int32
461 aValueMap
.emplace( "ParaIsHyphenation", uno::Any(true) );
464 PropertyMapper::getMultiPropertyListsFromValueMap( rPropNames
, rPropValues
, aValueMap
);
467 void PropertyMapper::getPreparedTextShapePropertyLists(
468 const uno::Reference
< beans::XPropertySet
>& xSourceProp
469 , tNameSequence
& rPropNames
, tAnySequence
& rPropValues
)
471 //fill character, line and fill properties into the ValueMap
472 tPropertyNameValueMap aValueMap
;
473 PropertyMapper::getValueMap( aValueMap
474 , PropertyMapper::getPropertyNameMapForTextShapeProperties()
477 // auto-grow makes sure the shape has the correct size after setting text
478 aValueMap
.emplace( "TextHorizontalAdjust", uno::Any( drawing::TextHorizontalAdjust_CENTER
));
479 aValueMap
.emplace( "TextVerticalAdjust", uno::Any( drawing::TextVerticalAdjust_CENTER
));
480 aValueMap
.emplace( "TextAutoGrowHeight", uno::Any( true ));
481 aValueMap
.emplace( "TextAutoGrowWidth", uno::Any( true ));
483 // set some distance to the border, in case it is shown
484 const sal_Int32 nWidthDist
= 250;
485 const sal_Int32 nHeightDist
= 125;
486 aValueMap
.emplace( "TextLeftDistance", uno::Any( nWidthDist
));
487 aValueMap
.emplace( "TextRightDistance", uno::Any( nWidthDist
));
488 aValueMap
.emplace( "TextUpperDistance", uno::Any( nHeightDist
));
489 aValueMap
.emplace( "TextLowerDistance", uno::Any( nHeightDist
));
491 // use a line-joint showing the border of thick lines like two rectangles
492 // filled in between.
493 aValueMap
["LineJoint"] <<= drawing::LineJoint_ROUND
;
495 PropertyMapper::getMultiPropertyListsFromValueMap( rPropNames
, rPropValues
, aValueMap
);
500 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */