vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / CharacterPropertyItemConverter.cxx
blob4e100bfb9822bf243d65060987ad01acca652b66
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 <CharacterPropertyItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <ItemPropertyMap.hxx>
23 #include <RelativeSizeHelper.hxx>
24 #include <editeng/memberids.h>
25 #include <editeng/eeitem.hxx>
26 #include <editeng/udlnitem.hxx>
27 #include <editeng/fontitem.hxx>
28 #include <editeng/postitem.hxx>
29 #include <editeng/wghtitem.hxx>
30 #include <editeng/fhgtitem.hxx>
31 #include <o3tl/any.hxx>
32 #include <svl/stritem.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/chart2/XFormattedString.hpp>
36 #include <tools/diagnose_ex.h>
38 using namespace ::com::sun::star;
40 namespace chart { namespace wrapper {
42 namespace {
44 ItemPropertyMapType & lcl_GetCharacterPropertyPropertyMap()
46 static ItemPropertyMapType aCharacterPropertyMap{
47 {EE_CHAR_COLOR, {"CharColor", 0}},
48 {EE_CHAR_LANGUAGE, {"CharLocale", MID_LANG_LOCALE}},
49 {EE_CHAR_LANGUAGE_CJK, {"CharLocaleAsian", MID_LANG_LOCALE}},
50 {EE_CHAR_LANGUAGE_CTL, {"CharLocaleComplex", MID_LANG_LOCALE}},
52 {EE_CHAR_STRIKEOUT, {"CharStrikeout", MID_CROSS_OUT}},
53 {EE_CHAR_WLM, {"CharWordMode", 0}},
54 {EE_CHAR_SHADOW, {"CharShadowed", 0}},
55 {EE_CHAR_RELIEF, {"CharRelief", 0}},
56 {EE_CHAR_OUTLINE, {"CharContoured", 0}},
57 {EE_CHAR_EMPHASISMARK, {"CharEmphasis", 0}},
59 {EE_PARA_WRITINGDIR, {"WritingMode", 0}},
61 {EE_PARA_ASIANCJKSPACING, {"ParaIsCharacterDistance", 0}}};
63 return aCharacterPropertyMap;
65 } // anonymous namespace
67 CharacterPropertyItemConverter::CharacterPropertyItemConverter(
68 const uno::Reference< beans::XPropertySet > & rPropertySet,
69 SfxItemPool& rItemPool ) :
70 ItemConverter( rPropertySet, rItemPool )
73 CharacterPropertyItemConverter::CharacterPropertyItemConverter(
74 const uno::Reference< beans::XPropertySet > & rPropertySet,
75 SfxItemPool& rItemPool,
76 const awt::Size* pRefSize,
77 const OUString & rRefSizePropertyName,
78 const uno::Reference< beans::XPropertySet > & rRefSizePropSet ) :
79 ItemConverter( rPropertySet, rItemPool ),
80 m_aRefSizePropertyName( rRefSizePropertyName ),
81 m_xRefSizePropSet( rRefSizePropSet.is() ? rRefSizePropSet : rPropertySet )
83 if (pRefSize)
84 m_pRefSize.reset(*pRefSize);
87 CharacterPropertyItemConverter::~CharacterPropertyItemConverter()
90 const sal_uInt16 * CharacterPropertyItemConverter::GetWhichPairs() const
92 return nCharacterPropertyWhichPairs;
95 bool CharacterPropertyItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
97 ItemPropertyMapType & rMap( lcl_GetCharacterPropertyPropertyMap());
98 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
100 if( aIt == rMap.end())
101 return false;
103 rOutProperty =(*aIt).second;
104 return true;
107 void CharacterPropertyItemConverter::FillSpecialItem(
108 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
110 switch( nWhichId )
112 case EE_CHAR_FONTINFO:
113 case EE_CHAR_FONTINFO_CJK:
114 case EE_CHAR_FONTINFO_CTL:
116 OUString aPostfix;
117 if( nWhichId == EE_CHAR_FONTINFO_CJK )
118 aPostfix = "Asian";
119 else if( nWhichId == EE_CHAR_FONTINFO_CTL )
120 aPostfix = "Complex";
122 SvxFontItem aItem( nWhichId );
124 aItem.PutValue( GetPropertySet()->getPropertyValue( "CharFontName" + aPostfix),
125 MID_FONT_FAMILY_NAME );
126 aItem.PutValue( GetPropertySet()->getPropertyValue( "CharFontFamily" + aPostfix),
127 MID_FONT_FAMILY );
128 aItem.PutValue( GetPropertySet()->getPropertyValue( "CharFontStyleName" + aPostfix),
129 MID_FONT_STYLE_NAME );
130 aItem.PutValue( GetPropertySet()->getPropertyValue( "CharFontCharSet" + aPostfix),
131 MID_FONT_CHAR_SET );
132 aItem.PutValue( GetPropertySet()->getPropertyValue( "CharFontPitch" + aPostfix),
133 MID_FONT_PITCH );
135 rOutItemSet.Put( aItem );
137 break;
139 case EE_CHAR_UNDERLINE:
141 SvxUnderlineItem aItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE);
142 bool bModified = false;
144 uno::Any aValue( GetPropertySet()->getPropertyValue( "CharUnderline" ));
145 if( aValue.hasValue())
147 aItem.PutValue( aValue, MID_TL_STYLE );
148 bModified = true;
151 aValue = GetPropertySet()->getPropertyValue( "CharUnderlineHasColor" );
152 if( aValue.hasValue() && *o3tl::doAccess<bool>(aValue) )
154 aItem.PutValue( aValue, MID_TL_HASCOLOR );
155 bModified = true;
158 aValue = GetPropertySet()->getPropertyValue( "CharUnderlineColor" );
159 if( aValue.hasValue())
161 aItem.PutValue( aValue, MID_TL_COLOR );
162 bModified = true;
165 if( bModified )
166 rOutItemSet.Put( aItem );
168 break;
170 case EE_CHAR_OVERLINE:
172 SvxOverlineItem aItem( LINESTYLE_NONE, EE_CHAR_OVERLINE );
173 bool bModified = false;
175 uno::Any aValue( GetPropertySet()->getPropertyValue( "CharOverline" ) );
176 if ( aValue.hasValue() )
178 aItem.PutValue( aValue, MID_TL_STYLE );
179 bModified = true;
182 aValue = GetPropertySet()->getPropertyValue( "CharOverlineHasColor" );
183 if ( aValue.hasValue() && *o3tl::doAccess<bool>(aValue) )
185 aItem.PutValue( aValue, MID_TL_HASCOLOR );
186 bModified = true;
189 aValue = GetPropertySet()->getPropertyValue( "CharOverlineColor" );
190 if ( aValue.hasValue() )
192 aItem.PutValue( aValue, MID_TL_COLOR );
193 bModified = true;
196 if ( bModified )
198 rOutItemSet.Put( aItem );
201 break;
203 case EE_CHAR_ITALIC:
204 case EE_CHAR_ITALIC_CJK:
205 case EE_CHAR_ITALIC_CTL:
207 OUString aPostfix;
208 if( nWhichId == EE_CHAR_ITALIC_CJK )
209 aPostfix = "Asian";
210 else if( nWhichId == EE_CHAR_ITALIC_CTL )
211 aPostfix = "Complex";
213 SvxPostureItem aItem( ITALIC_NONE, nWhichId );
215 uno::Any aValue( GetPropertySet()->getPropertyValue( "CharPosture" + aPostfix));
216 if( aValue.hasValue())
218 aItem.PutValue( aValue, MID_POSTURE );
219 rOutItemSet.Put( aItem );
222 break;
224 case EE_CHAR_WEIGHT:
225 case EE_CHAR_WEIGHT_CJK:
226 case EE_CHAR_WEIGHT_CTL:
228 OUString aPostfix;
229 if( nWhichId == EE_CHAR_WEIGHT_CJK )
230 aPostfix = "Asian";
231 else if( nWhichId == EE_CHAR_WEIGHT_CTL )
232 aPostfix = "Complex";
234 SvxWeightItem aItem( WEIGHT_NORMAL, nWhichId );
236 uno::Any aValue( GetPropertySet()->getPropertyValue( "CharWeight" + aPostfix));
237 if( aValue.hasValue())
239 aItem.PutValue( aValue, MID_WEIGHT );
240 rOutItemSet.Put( aItem );
243 break;
245 case EE_CHAR_FONTHEIGHT:
246 case EE_CHAR_FONTHEIGHT_CJK:
247 case EE_CHAR_FONTHEIGHT_CTL:
249 OUString aPostfix;
250 if( nWhichId == EE_CHAR_FONTHEIGHT_CJK )
251 aPostfix = "Asian";
252 else if( nWhichId == EE_CHAR_FONTHEIGHT_CTL )
253 aPostfix = "Complex";
255 SvxFontHeightItem aItem( 240, 100, nWhichId );
259 uno::Any aValue( GetPropertySet()->getPropertyValue( "CharHeight" + aPostfix ));
260 float fHeight;
261 if( aValue >>= fHeight )
263 if (m_pRefSize)
265 awt::Size aOldRefSize;
266 if( GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ) >>= aOldRefSize )
268 // calculate font height in view
269 fHeight = static_cast< float >(
270 RelativeSizeHelper::calculate( fHeight, aOldRefSize, *m_pRefSize ));
271 aValue <<= fHeight;
275 aItem.PutValue( aValue, MID_FONTHEIGHT );
276 rOutItemSet.Put( aItem );
279 catch( const uno::Exception & )
281 DBG_UNHANDLED_EXCEPTION("chart2");
284 break;
286 case SID_CHAR_DLG_PREVIEW_STRING:
288 uno::Reference< chart2::XFormattedString > xFormattedString( GetPropertySet(), uno::UNO_QUERY );
289 if( xFormattedString.is() )
291 OUString aString = xFormattedString->getString();
292 rOutItemSet.Put( SfxStringItem( nWhichId, aString ) );
294 else
295 rOutItemSet.Put( SfxStringItem( nWhichId, OUString() ) );
297 break;
299 case EE_PARA_FORBIDDENRULES:
300 case EE_PARA_HANGINGPUNCTUATION:
301 rOutItemSet.DisableItem( nWhichId );
302 break;
306 bool CharacterPropertyItemConverter::ApplySpecialItem(
307 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
309 bool bChanged = false;
310 uno::Any aValue;
312 switch( nWhichId )
314 case EE_CHAR_FONTINFO:
315 case EE_CHAR_FONTINFO_CJK:
316 case EE_CHAR_FONTINFO_CTL:
318 OUString aPostfix;
319 if( nWhichId == EE_CHAR_FONTINFO_CJK )
320 aPostfix = "Asian";
321 else if( nWhichId == EE_CHAR_FONTINFO_CTL )
322 aPostfix = "Complex";
324 const SvxFontItem & rItem =
325 static_cast< const SvxFontItem & >(
326 rItemSet.Get( nWhichId ));
328 if( rItem.QueryValue( aValue, MID_FONT_FAMILY_NAME ))
330 if( aValue != GetPropertySet()->getPropertyValue( "CharFontName" + aPostfix ))
332 GetPropertySet()->setPropertyValue( "CharFontName" + aPostfix, aValue );
333 bChanged = true;
336 if( rItem.QueryValue( aValue, MID_FONT_FAMILY ))
338 if( aValue != GetPropertySet()->getPropertyValue( "CharFontFamily" + aPostfix ))
340 GetPropertySet()->setPropertyValue( "CharFontFamily" + aPostfix, aValue );
341 bChanged = true;
344 if( rItem.QueryValue( aValue, MID_FONT_STYLE_NAME ))
346 if( aValue != GetPropertySet()->getPropertyValue( "CharFontStyleName" + aPostfix ))
348 GetPropertySet()->setPropertyValue( "CharFontStyleName" + aPostfix, aValue );
349 bChanged = true;
352 if( rItem.QueryValue( aValue, MID_FONT_CHAR_SET ))
354 if( aValue != GetPropertySet()->getPropertyValue( "CharFontCharSet" + aPostfix ))
356 GetPropertySet()->setPropertyValue( "CharFontCharSet" + aPostfix, aValue );
357 bChanged = true;
360 if( rItem.QueryValue( aValue, MID_FONT_PITCH ))
362 if( aValue != GetPropertySet()->getPropertyValue( "CharFontPitch" + aPostfix ))
364 GetPropertySet()->setPropertyValue( "CharFontPitch" + aPostfix, aValue );
365 bChanged = true;
369 break;
371 case EE_CHAR_UNDERLINE:
373 const SvxUnderlineItem & rItem =
374 static_cast< const SvxUnderlineItem & >(
375 rItemSet.Get( nWhichId ));
377 if( rItem.QueryValue( aValue, MID_TL_STYLE ))
379 if( aValue != GetPropertySet()->getPropertyValue( "CharUnderline" ))
381 GetPropertySet()->setPropertyValue( "CharUnderline" , aValue );
382 bChanged = true;
386 if( rItem.QueryValue( aValue, MID_TL_COLOR ))
388 if( aValue != GetPropertySet()->getPropertyValue( "CharUnderlineColor" ))
390 GetPropertySet()->setPropertyValue( "CharUnderlineColor" , aValue );
391 bChanged = true;
395 if( rItem.QueryValue( aValue, MID_TL_HASCOLOR ))
397 if( aValue != GetPropertySet()->getPropertyValue( "CharUnderlineHasColor" ))
399 GetPropertySet()->setPropertyValue( "CharUnderlineHasColor" , aValue );
400 bChanged = true;
404 break;
406 case EE_CHAR_OVERLINE:
408 const SvxOverlineItem& rItem = static_cast< const SvxOverlineItem & >( rItemSet.Get( nWhichId ) );
410 if ( rItem.QueryValue( aValue, MID_TL_STYLE ) )
412 if ( aValue != GetPropertySet()->getPropertyValue( "CharOverline" ) )
414 GetPropertySet()->setPropertyValue( "CharOverline" , aValue );
415 bChanged = true;
419 if ( rItem.QueryValue( aValue, MID_TL_COLOR ) )
421 if ( aValue != GetPropertySet()->getPropertyValue( "CharOverlineColor" ) )
423 GetPropertySet()->setPropertyValue( "CharOverlineColor" , aValue );
424 bChanged = true;
428 if ( rItem.QueryValue( aValue, MID_TL_HASCOLOR ) )
430 if ( aValue != GetPropertySet()->getPropertyValue( "CharOverlineHasColor" ) )
432 GetPropertySet()->setPropertyValue( "CharOverlineHasColor" , aValue );
433 bChanged = true;
437 break;
439 case EE_CHAR_ITALIC:
440 case EE_CHAR_ITALIC_CJK:
441 case EE_CHAR_ITALIC_CTL:
443 OUString aPostfix;
444 if( nWhichId == EE_CHAR_ITALIC_CJK )
445 aPostfix = "Asian";
446 else if( nWhichId == EE_CHAR_ITALIC_CTL )
447 aPostfix = "Complex";
449 const SvxPostureItem & rItem =
450 static_cast< const SvxPostureItem & >(
451 rItemSet.Get( nWhichId ));
453 if( rItem.QueryValue( aValue, MID_POSTURE ))
455 if( aValue != GetPropertySet()->getPropertyValue( "CharPosture" + aPostfix))
457 GetPropertySet()->setPropertyValue( "CharPosture" + aPostfix, aValue );
458 bChanged = true;
462 break;
464 case EE_CHAR_WEIGHT:
465 case EE_CHAR_WEIGHT_CJK:
466 case EE_CHAR_WEIGHT_CTL:
468 OUString aPostfix;
469 if( nWhichId == EE_CHAR_WEIGHT_CJK )
470 aPostfix = "Asian" ;
471 else if( nWhichId == EE_CHAR_WEIGHT_CTL )
472 aPostfix = "Complex";
474 const SvxWeightItem & rItem =
475 static_cast< const SvxWeightItem & >(
476 rItemSet.Get( nWhichId ));
478 if( rItem.QueryValue( aValue, MID_WEIGHT ))
480 if( aValue != GetPropertySet()->getPropertyValue( "CharWeight" + aPostfix))
482 GetPropertySet()->setPropertyValue( "CharWeight" + aPostfix, aValue );
483 bChanged = true;
487 break;
489 case EE_CHAR_FONTHEIGHT:
490 case EE_CHAR_FONTHEIGHT_CJK:
491 case EE_CHAR_FONTHEIGHT_CTL:
493 OUString aPostfix;
494 if( nWhichId == EE_CHAR_FONTHEIGHT_CJK )
495 aPostfix = "Asian";
496 else if( nWhichId == EE_CHAR_FONTHEIGHT_CTL )
497 aPostfix = "Complex";
499 const SvxFontHeightItem & rItem =
500 static_cast< const SvxFontHeightItem & >(
501 rItemSet.Get( nWhichId ));
505 if( rItem.QueryValue( aValue, MID_FONTHEIGHT ) )
507 bool bSetValue = false;
508 if( aValue != GetPropertySet()->getPropertyValue( "CharHeight" + aPostfix ))
509 bSetValue = true;
510 else
512 if (m_pRefSize)
514 awt::Size aNewRefSize = *m_pRefSize;
515 awt::Size aOldRefSize;
516 if( GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ) >>= aOldRefSize )
518 if( aNewRefSize.Width != aOldRefSize.Width
519 || aNewRefSize.Height != aOldRefSize.Height )
520 bSetValue = true;
524 if( bSetValue )
526 // set new reference size only if there was a reference size before (auto-scaling on)
527 if (m_pRefSize && GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ).hasValue())
529 GetRefSizePropertySet()->setPropertyValue(
530 m_aRefSizePropertyName, uno::Any(*m_pRefSize));
533 GetPropertySet()->setPropertyValue( "CharHeight" + aPostfix, aValue );
534 bChanged = true;
538 catch( const uno::Exception & )
540 DBG_UNHANDLED_EXCEPTION("chart2");
543 break;
546 return bChanged;
549 const uno::Reference<beans::XPropertySet>& CharacterPropertyItemConverter::GetRefSizePropertySet() const
551 return m_xRefSizePropSet;
556 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */