bump product version to 6.4.0.3
[LibreOffice.git] / editeng / source / items / textitem.cxx
blobafd053da51e72ce069e820ce380eb013e10ea914
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 <com/sun/star/style/CaseMap.hpp>
21 #include <com/sun/star/awt/FontDescriptor.hpp>
22 #include <com/sun/star/frame/status/FontHeight.hpp>
23 #include <vcl/bitmapex.hxx>
24 #include <tools/stream.hxx>
25 #include <math.h>
26 #include <rtl/math.hxx>
27 #include <sal/log.hxx>
28 #include <osl/diagnose.h>
29 #include <unotools/fontdefs.hxx>
30 #include <unotools/intlwrapper.hxx>
31 #include <unotools/syslocale.hxx>
32 #include <vcl/outdev.hxx>
33 #include <vcl/unohelp.hxx>
34 #include <editeng/eeitem.hxx>
35 #include <svtools/unitconv.hxx>
37 #include <editeng/editids.hrc>
38 #include <editeng/editrids.hrc>
39 #include <vcl/vclenum.hxx>
40 #include <tools/tenccvt.hxx>
41 #include <tools/mapunit.hxx>
43 #include <rtl/ustring.hxx>
44 #include <i18nlangtag/languagetag.hxx>
45 #include <svl/itemset.hxx>
47 #include <comphelper/fileformat.h>
48 #include <svtools/langtab.hxx>
49 #include <svl/itempool.hxx>
50 #include <svtools/ctrltool.hxx>
51 #include <vcl/settings.hxx>
52 #include <vcl/svapp.hxx>
53 #include <com/sun/star/awt/SimpleFontMetric.hpp>
54 #include <com/sun/star/awt/FontWeight.hpp>
55 #include <com/sun/star/awt/FontSlant.hpp>
56 #include <com/sun/star/awt/CharSet.hpp>
57 #include <com/sun/star/awt/FontWidth.hpp>
58 #include <com/sun/star/awt/XFont.hpp>
59 #include <com/sun/star/awt/FontType.hpp>
60 #include <com/sun/star/awt/FontUnderline.hpp>
61 #include <com/sun/star/awt/FontStrikeout.hpp>
62 #include <com/sun/star/awt/FontFamily.hpp>
63 #include <com/sun/star/awt/FontPitch.hpp>
64 #include <com/sun/star/lang/Locale.hpp>
65 #include <com/sun/star/text/FontEmphasis.hpp>
66 #include <com/sun/star/i18n/ScriptType.hpp>
67 #include <editeng/rsiditem.hxx>
68 #include <editeng/memberids.h>
69 #include <editeng/flstitem.hxx>
70 #include <editeng/fontitem.hxx>
71 #include <editeng/postitem.hxx>
72 #include <editeng/wghtitem.hxx>
73 #include <editeng/fhgtitem.hxx>
74 #include <editeng/udlnitem.hxx>
75 #include <editeng/crossedoutitem.hxx>
76 #include <editeng/shdditem.hxx>
77 #include <editeng/autokernitem.hxx>
78 #include <editeng/wrlmitem.hxx>
79 #include <editeng/contouritem.hxx>
80 #include <editeng/colritem.hxx>
81 #include <editeng/kernitem.hxx>
82 #include <editeng/cmapitem.hxx>
83 #include <editeng/escapementitem.hxx>
84 #include <editeng/langitem.hxx>
85 #include <editeng/nhypitem.hxx>
86 #include <editeng/blinkitem.hxx>
87 #include <editeng/emphasismarkitem.hxx>
88 #include <editeng/twolinesitem.hxx>
89 #include <editeng/scripttypeitem.hxx>
90 #include <editeng/charrotateitem.hxx>
91 #include <editeng/charscaleitem.hxx>
92 #include <editeng/charreliefitem.hxx>
93 #include <editeng/itemtype.hxx>
94 #include <editeng/eerdll.hxx>
95 #include <libxml/xmlwriter.h>
97 using namespace ::com::sun::star;
98 using namespace ::com::sun::star::text;
100 SfxPoolItem* SvxFontItem::CreateDefault() {return new SvxFontItem(0);}
101 SfxPoolItem* SvxPostureItem::CreateDefault() { return new SvxPostureItem(ITALIC_NONE, 0);}
102 SfxPoolItem* SvxWeightItem::CreateDefault() {return new SvxWeightItem(WEIGHT_NORMAL, 0);}
103 SfxPoolItem* SvxFontHeightItem::CreateDefault() {return new SvxFontHeightItem(240, 100, 0);}
104 SfxPoolItem* SvxUnderlineItem::CreateDefault() {return new SvxUnderlineItem(LINESTYLE_NONE, 0);}
105 SfxPoolItem* SvxOverlineItem::CreateDefault() {return new SvxOverlineItem(LINESTYLE_NONE, 0);}
106 SfxPoolItem* SvxCrossedOutItem::CreateDefault() {return new SvxCrossedOutItem(STRIKEOUT_NONE, 0);}
107 SfxPoolItem* SvxShadowedItem::CreateDefault() {return new SvxShadowedItem(false, 0);}
108 SfxPoolItem* SvxAutoKernItem::CreateDefault() {return new SvxAutoKernItem(false, 0);}
109 SfxPoolItem* SvxWordLineModeItem::CreateDefault() {return new SvxWordLineModeItem(false, 0);}
110 SfxPoolItem* SvxContourItem::CreateDefault() {return new SvxContourItem(false, 0);}
111 SfxPoolItem* SvxColorItem::CreateDefault() {return new SvxColorItem(0);}
112 SfxPoolItem* SvxBackgroundColorItem::CreateDefault() {return new SvxBackgroundColorItem(0);}
113 SfxPoolItem* SvxKerningItem::CreateDefault() {return new SvxKerningItem(0, 0);}
114 SfxPoolItem* SvxCaseMapItem::CreateDefault() {return new SvxCaseMapItem(SvxCaseMap::NotMapped, 0);}
115 SfxPoolItem* SvxEscapementItem::CreateDefault() {return new SvxEscapementItem(0);}
116 SfxPoolItem* SvxLanguageItem::CreateDefault() {return new SvxLanguageItem(LANGUAGE_GERMAN, 0);}
117 SfxPoolItem* SvxBlinkItem::CreateDefault() {return new SvxBlinkItem(false, 0);}
118 SfxPoolItem* SvxEmphasisMarkItem::CreateDefault() {return new SvxEmphasisMarkItem(FontEmphasisMark::NONE, 0);}
119 SfxPoolItem* SvxCharRotateItem::CreateDefault() {return new SvxCharRotateItem(0, false, 0);}
120 SfxPoolItem* SvxCharScaleWidthItem::CreateDefault() {return new SvxCharScaleWidthItem(100, 0);}
121 SfxPoolItem* SvxCharReliefItem::CreateDefault() {return new SvxCharReliefItem(FontRelief::NONE, 0);}
124 // class SvxFontListItem -------------------------------------------------
126 SvxFontListItem::SvxFontListItem( const FontList* pFontLst,
127 const sal_uInt16 nId ) :
128 SfxPoolItem( nId ),
129 pFontList( pFontLst )
131 if ( pFontList )
133 sal_Int32 nCount = pFontList->GetFontNameCount();
134 aFontNameSeq.realloc( nCount );
136 for ( sal_Int32 i = 0; i < nCount; i++ )
137 aFontNameSeq[i] = pFontList->GetFontName(i).GetFamilyName();
142 SfxPoolItem* SvxFontListItem::Clone( SfxItemPool* ) const
144 return new SvxFontListItem( *this );
148 bool SvxFontListItem::operator==( const SfxPoolItem& rAttr ) const
150 assert(SfxPoolItem::operator==(rAttr));
152 return( pFontList == static_cast<const SvxFontListItem&>(rAttr).pFontList );
155 bool SvxFontListItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
157 rVal <<= aFontNameSeq;
158 return true;
162 bool SvxFontListItem::GetPresentation
164 SfxItemPresentation /*ePres*/,
165 MapUnit /*eCoreUnit*/,
166 MapUnit /*ePresUnit*/,
167 OUString& rText, const IntlWrapper& /*rIntl*/
168 ) const
170 rText.clear();
171 return false;
174 // class SvxFontItem -----------------------------------------------------
176 SvxFontItem::SvxFontItem( const sal_uInt16 nId ) :
177 SfxPoolItem( nId )
179 eFamily = FAMILY_SWISS;
180 ePitch = PITCH_VARIABLE;
181 eTextEncoding = RTL_TEXTENCODING_DONTKNOW;
185 SvxFontItem::SvxFontItem( const FontFamily eFam, const OUString& aName,
186 const OUString& aStName, const FontPitch eFontPitch,
187 const rtl_TextEncoding eFontTextEncoding, const sal_uInt16 nId ) :
189 SfxPoolItem( nId ),
191 aFamilyName(aName),
192 aStyleName(aStName)
194 eFamily = eFam;
195 ePitch = eFontPitch;
196 eTextEncoding = eFontTextEncoding;
200 bool SvxFontItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
202 nMemberId &= ~CONVERT_TWIPS;
203 switch(nMemberId)
205 case 0:
207 css::awt::FontDescriptor aFontDescriptor;
208 aFontDescriptor.Name = aFamilyName;
209 aFontDescriptor.StyleName = aStyleName;
210 aFontDescriptor.Family = static_cast<sal_Int16>(eFamily);
211 aFontDescriptor.CharSet = static_cast<sal_Int16>(eTextEncoding);
212 aFontDescriptor.Pitch = static_cast<sal_Int16>(ePitch);
213 rVal <<= aFontDescriptor;
215 break;
216 case MID_FONT_FAMILY_NAME:
217 rVal <<= aFamilyName;
218 break;
219 case MID_FONT_STYLE_NAME:
220 rVal <<= aStyleName;
221 break;
222 case MID_FONT_FAMILY : rVal <<= static_cast<sal_Int16>(eFamily); break;
223 case MID_FONT_CHAR_SET : rVal <<= static_cast<sal_Int16>(eTextEncoding); break;
224 case MID_FONT_PITCH : rVal <<= static_cast<sal_Int16>(ePitch); break;
226 return true;
229 bool SvxFontItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId)
231 nMemberId &= ~CONVERT_TWIPS;
232 switch(nMemberId)
234 case 0:
236 css::awt::FontDescriptor aFontDescriptor;
237 if ( !( rVal >>= aFontDescriptor ))
238 return false;
240 aFamilyName = aFontDescriptor.Name;
241 aStyleName = aFontDescriptor.StyleName;
242 eFamily = static_cast<FontFamily>(aFontDescriptor.Family);
243 eTextEncoding = static_cast<rtl_TextEncoding>(aFontDescriptor.CharSet);
244 ePitch = static_cast<FontPitch>(aFontDescriptor.Pitch);
246 break;
247 case MID_FONT_FAMILY_NAME :
249 OUString aStr;
250 if(!(rVal >>= aStr))
251 return false;
252 aFamilyName = aStr;
254 break;
255 case MID_FONT_STYLE_NAME:
257 OUString aStr;
258 if(!(rVal >>= aStr))
259 return false;
260 aStyleName = aStr;
262 break;
263 case MID_FONT_FAMILY :
265 sal_Int16 nFamily = sal_Int16();
266 if(!(rVal >>= nFamily))
267 return false;
268 eFamily = static_cast<FontFamily>(nFamily);
270 break;
271 case MID_FONT_CHAR_SET :
273 sal_Int16 nSet = sal_Int16();
274 if(!(rVal >>= nSet))
275 return false;
276 eTextEncoding = static_cast<rtl_TextEncoding>(nSet);
278 break;
279 case MID_FONT_PITCH :
281 sal_Int16 nPitch = sal_Int16();
282 if(!(rVal >>= nPitch))
283 return false;
284 ePitch = static_cast<FontPitch>(nPitch);
286 break;
288 return true;
292 bool SvxFontItem::operator==( const SfxPoolItem& rAttr ) const
294 assert(SfxPoolItem::operator==(rAttr));
296 const SvxFontItem& rItem = static_cast<const SvxFontItem&>(rAttr);
298 bool bRet = ( eFamily == rItem.eFamily &&
299 aFamilyName == rItem.aFamilyName &&
300 aStyleName == rItem.aStyleName );
302 if ( bRet )
304 if ( ePitch != rItem.ePitch || eTextEncoding != rItem.eTextEncoding )
306 bRet = false;
307 SAL_INFO( "editeng.items", "FontItem::operator==(): only pitch or rtl_TextEncoding different ");
310 return bRet;
314 SfxPoolItem* SvxFontItem::Clone( SfxItemPool * ) const
316 return new SvxFontItem( *this );
320 bool SvxFontItem::GetPresentation
322 SfxItemPresentation /*ePres*/,
323 MapUnit /*eCoreUnit*/,
324 MapUnit /*ePresUnit*/,
325 OUString& rText, const IntlWrapper& /*rIntl*/
326 ) const
328 rText = aFamilyName;
329 return true;
333 void SvxFontItem::dumpAsXml(xmlTextWriterPtr pWriter) const
335 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFontItem"));
336 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
337 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("familyName"), BAD_CAST(aFamilyName.toUtf8().getStr()));
338 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("styleName"), BAD_CAST(aStyleName.toUtf8().getStr()));
339 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("family"), BAD_CAST(OString::number(eFamily).getStr()));
340 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("pitch"), BAD_CAST(OString::number(ePitch).getStr()));
341 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("textEncoding"), BAD_CAST(OString::number(eTextEncoding).getStr()));
342 xmlTextWriterEndElement(pWriter);
345 // class SvxPostureItem --------------------------------------------------
347 SvxPostureItem::SvxPostureItem( const FontItalic ePosture, const sal_uInt16 nId ) :
348 SfxEnumItem( nId, ePosture )
353 SfxPoolItem* SvxPostureItem::Clone( SfxItemPool * ) const
355 return new SvxPostureItem( *this );
359 sal_uInt16 SvxPostureItem::GetValueCount() const
361 return ITALIC_NORMAL + 1; // ITALIC_NONE also belongs here
365 bool SvxPostureItem::GetPresentation
367 SfxItemPresentation /*ePres*/,
368 MapUnit /*eCoreUnit*/,
369 MapUnit /*ePresUnit*/,
370 OUString& rText, const IntlWrapper& /*rIntl*/
371 ) const
373 rText = GetValueTextByPos( GetValue() );
374 return true;
378 OUString SvxPostureItem::GetValueTextByPos( sal_uInt16 nPos )
380 DBG_ASSERT( nPos <= sal_uInt16(ITALIC_NORMAL), "enum overflow!" );
382 FontItalic eItalic = static_cast<FontItalic>(nPos);
383 const char* pId = nullptr;
385 switch ( eItalic )
387 case ITALIC_NONE: pId = RID_SVXITEMS_ITALIC_NONE; break;
388 case ITALIC_OBLIQUE: pId = RID_SVXITEMS_ITALIC_OBLIQUE; break;
389 case ITALIC_NORMAL: pId = RID_SVXITEMS_ITALIC_NORMAL; break;
390 default: ;//prevent warning
393 return pId ? EditResId(pId) : OUString();
396 bool SvxPostureItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
398 nMemberId &= ~CONVERT_TWIPS;
399 switch( nMemberId )
401 case MID_ITALIC:
402 rVal <<= GetBoolValue();
403 break;
404 case MID_POSTURE:
405 rVal <<= vcl::unohelper::ConvertFontSlant(GetValue());
406 break;
408 return true;
411 bool SvxPostureItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
413 nMemberId &= ~CONVERT_TWIPS;
414 switch( nMemberId )
416 case MID_ITALIC:
417 SetBoolValue(Any2Bool(rVal));
418 break;
419 case MID_POSTURE:
421 awt::FontSlant eSlant;
422 if(!(rVal >>= eSlant))
424 sal_Int32 nValue = 0;
425 if(!(rVal >>= nValue))
426 return false;
428 eSlant = static_cast<awt::FontSlant>(nValue);
430 SetValue(vcl::unohelper::ConvertFontSlant(eSlant));
433 return true;
436 bool SvxPostureItem::HasBoolValue() const
438 return true;
441 bool SvxPostureItem::GetBoolValue() const
443 return ( GetValue() >= ITALIC_OBLIQUE );
446 void SvxPostureItem::SetBoolValue( bool bVal )
448 SetValue( bVal ? ITALIC_NORMAL : ITALIC_NONE );
451 void SvxPostureItem::dumpAsXml(xmlTextWriterPtr pWriter) const
453 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxPostureItem"));
454 xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("whichId"), "%d", Which());
455 xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("value"), "%d", GetValue());
456 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(GetValueTextByPos(GetValue()).toUtf8().getStr()));
457 xmlTextWriterEndElement(pWriter);
460 // class SvxWeightItem ---------------------------------------------------
462 SvxWeightItem::SvxWeightItem( const FontWeight eWght, const sal_uInt16 nId ) :
463 SfxEnumItem( nId, eWght )
468 bool SvxWeightItem::HasBoolValue() const
470 return true;
474 bool SvxWeightItem::GetBoolValue() const
476 return GetValue() >= WEIGHT_BOLD;
480 void SvxWeightItem::SetBoolValue( bool bVal )
482 SetValue( bVal ? WEIGHT_BOLD : WEIGHT_NORMAL );
486 sal_uInt16 SvxWeightItem::GetValueCount() const
488 return WEIGHT_BLACK; // WEIGHT_DONTKNOW does not belong
492 SfxPoolItem* SvxWeightItem::Clone( SfxItemPool * ) const
494 return new SvxWeightItem( *this );
498 bool SvxWeightItem::GetPresentation
500 SfxItemPresentation /*ePres*/,
501 MapUnit /*eCoreUnit*/,
502 MapUnit /*ePresUnit*/,
503 OUString& rText, const IntlWrapper& /*rIntl*/
504 ) const
506 rText = GetValueTextByPos( GetValue() );
507 return true;
510 OUString SvxWeightItem::GetValueTextByPos( sal_uInt16 nPos )
512 static const char* RID_SVXITEMS_WEIGHTS[] =
514 RID_SVXITEMS_WEIGHT_DONTKNOW,
515 RID_SVXITEMS_WEIGHT_THIN,
516 RID_SVXITEMS_WEIGHT_ULTRALIGHT,
517 RID_SVXITEMS_WEIGHT_LIGHT,
518 RID_SVXITEMS_WEIGHT_SEMILIGHT,
519 RID_SVXITEMS_WEIGHT_NORMAL,
520 RID_SVXITEMS_WEIGHT_MEDIUM,
521 RID_SVXITEMS_WEIGHT_SEMIBOLD,
522 RID_SVXITEMS_WEIGHT_BOLD,
523 RID_SVXITEMS_WEIGHT_ULTRABOLD,
524 RID_SVXITEMS_WEIGHT_BLACK
527 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_WEIGHTS) - 1 == WEIGHT_BLACK, "must match");
528 assert(nPos <= sal_uInt16(WEIGHT_BLACK) && "enum overflow!" );
529 return EditResId(RID_SVXITEMS_WEIGHTS[nPos]);
532 bool SvxWeightItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
534 nMemberId &= ~CONVERT_TWIPS;
535 switch( nMemberId )
537 case MID_BOLD :
538 rVal <<= GetBoolValue();
539 break;
540 case MID_WEIGHT:
542 rVal <<= vcl::unohelper::ConvertFontWeight( GetValue() );
544 break;
546 return true;
549 bool SvxWeightItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
551 nMemberId &= ~CONVERT_TWIPS;
552 switch( nMemberId )
554 case MID_BOLD :
555 SetBoolValue(Any2Bool(rVal));
556 break;
557 case MID_WEIGHT:
559 double fValue = 0;
560 if(!(rVal >>= fValue))
562 sal_Int32 nValue = 0;
563 if(!(rVal >>= nValue))
564 return false;
565 fValue = static_cast<float>(nValue);
567 SetValue( vcl::unohelper::ConvertFontWeight(static_cast<float>(fValue)) );
569 break;
571 return true;
574 void SvxWeightItem::dumpAsXml(xmlTextWriterPtr pWriter) const
576 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxWeightItem"));
577 xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("whichId"), "%d", Which());
578 xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("value"), "%d", GetValue());
579 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(GetValueTextByPos(GetValue()).toUtf8().getStr()));
580 xmlTextWriterEndElement(pWriter);
583 // class SvxFontHeightItem -----------------------------------------------
585 SvxFontHeightItem::SvxFontHeightItem( const sal_uLong nSz,
586 const sal_uInt16 nPrp,
587 const sal_uInt16 nId ) :
588 SfxPoolItem( nId )
590 SetHeight( nSz,nPrp ); // calculate in percentage
594 SfxPoolItem* SvxFontHeightItem::Clone( SfxItemPool * ) const
596 return new SvxFontHeightItem( *this );
600 bool SvxFontHeightItem::operator==( const SfxPoolItem& rItem ) const
602 assert(SfxPoolItem::operator==(rItem));
603 return GetHeight() == static_cast<const SvxFontHeightItem&>(rItem).GetHeight() &&
604 GetProp() == static_cast<const SvxFontHeightItem&>(rItem).GetProp() &&
605 GetPropUnit() == static_cast<const SvxFontHeightItem&>(rItem).GetPropUnit();
608 bool SvxFontHeightItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
610 // In StarOne is the uno::Any always 1/100mm. Through the MemberId it is
611 // controlled if the value in the Item should be 1/100mm or Twips.
613 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
614 nMemberId &= ~CONVERT_TWIPS;
615 switch( nMemberId )
617 case 0:
619 css::frame::status::FontHeight aFontHeight;
621 // Point (i.e. Twips) is asked for, thus re-calculate if
622 // CONVERT_TWIPS is not set.
623 if( bConvert )
625 aFontHeight.Height = static_cast<float>( nHeight / 20.0 );
627 else
629 double fPoints = convertMm100ToTwip(nHeight) / 20.0;
630 float fRoundPoints =
631 static_cast<float>(::rtl::math::round(fPoints, 1));
632 aFontHeight.Height = fRoundPoints;
635 aFontHeight.Prop = static_cast<sal_Int16>(MapUnit::MapRelative == ePropUnit ? nProp : 100);
637 float fRet = static_cast<float>(static_cast<short>(nProp));
638 switch( ePropUnit )
640 case MapUnit::MapRelative:
641 fRet = 0.;
642 break;
643 case MapUnit::Map100thMM:
644 fRet = convertMm100ToTwip(fRet);
645 fRet /= 20.;
646 break;
647 case MapUnit::MapPoint:
649 break;
650 case MapUnit::MapTwip:
651 fRet /= 20.;
652 break;
653 default: ;//prevent warning
655 aFontHeight.Diff = fRet;
656 rVal <<= aFontHeight;
658 break;
659 case MID_FONTHEIGHT:
661 // Point (i.e. Twips) is asked for, thus re-calculate if
662 // CONVERT_TWIPS is not set.
663 if( bConvert )
665 rVal <<= static_cast<float>( nHeight / 20.0 );
667 else
669 double fPoints = convertMm100ToTwip(nHeight) / 20.0;
670 float fRoundPoints =
671 static_cast<float>(::rtl::math::round(fPoints, 1));
672 rVal <<= fRoundPoints;
675 break;
676 case MID_FONTHEIGHT_PROP:
677 rVal <<= static_cast<sal_Int16>(MapUnit::MapRelative == ePropUnit ? nProp : 100);
678 break;
679 case MID_FONTHEIGHT_DIFF:
681 float fRet = static_cast<float>(static_cast<short>(nProp));
682 switch( ePropUnit )
684 case MapUnit::MapRelative:
685 fRet = 0.;
686 break;
687 case MapUnit::Map100thMM:
688 fRet = convertMm100ToTwip(fRet);
689 fRet /= 20.;
690 break;
691 case MapUnit::MapPoint:
693 break;
694 case MapUnit::MapTwip:
695 fRet /= 20.;
696 break;
697 default: ;//prevent warning
699 rVal <<= fRet;
701 break;
703 return true;
706 // Try to reconstruct the original height input value from the modified height
707 // and the prop data; this seems somewhat futile given the various ways how the
708 // modified height is calculated (with and without conversion between twips and
709 // 100th mm; with an additional eCoreMetric input in one of the SetHeight
710 // overloads), and indeed known to occasionally produce nRet values that would
711 // be negative, so just guard against negative results here and throw the hands
712 // up in despair:
713 static sal_uInt32 lcl_GetRealHeight_Impl(sal_uInt32 nHeight, sal_uInt16 nProp, MapUnit eProp, bool bCoreInTwip)
715 sal_uInt32 nRet = nHeight;
716 short nDiff = 0;
717 switch( eProp )
719 case MapUnit::MapRelative:
720 if (nProp)
722 nRet *= 100;
723 nRet /= nProp;
725 break;
726 case MapUnit::MapPoint:
728 short nTemp = static_cast<short>(nProp);
729 nDiff = nTemp * 20;
730 if(!bCoreInTwip)
731 nDiff = static_cast<short>(convertTwipToMm100(static_cast<long>(nDiff)));
732 break;
734 case MapUnit::Map100thMM:
735 //then the core is surely also in 1/100 mm
736 nDiff = static_cast<short>(nProp);
737 break;
738 case MapUnit::MapTwip:
739 // Here surely TWIP
740 nDiff = static_cast<short>(nProp);
741 break;
742 default:
743 break;
745 nRet = (nDiff < 0 || nRet >= static_cast<unsigned short>(nDiff))
746 ? nRet - nDiff : 0;
747 //TODO: overflow in case nDiff < 0 and nRet - nDiff > SAL_MAX_UINT32
749 return nRet;
752 bool SvxFontHeightItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
754 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
755 nMemberId &= ~CONVERT_TWIPS;
756 switch( nMemberId )
758 case 0:
760 css::frame::status::FontHeight aFontHeight;
761 if ( rVal >>= aFontHeight )
763 // Height
764 ePropUnit = MapUnit::MapRelative;
765 nProp = 100;
766 double fPoint = aFontHeight.Height;
767 if( fPoint < 0. || fPoint > 10000. )
768 return false;
770 nHeight = static_cast<long>( fPoint * 20.0 + 0.5 ); // Twips
771 if (!bConvert)
772 nHeight = convertTwipToMm100(nHeight); // Convert, if the item contains 1/100mm
774 nProp = aFontHeight.Prop;
776 else
777 return false;
779 break;
780 case MID_FONTHEIGHT:
782 ePropUnit = MapUnit::MapRelative;
783 nProp = 100;
784 double fPoint = 0;
785 if(!(rVal >>= fPoint))
787 sal_Int32 nValue = 0;
788 if(!(rVal >>= nValue))
789 return false;
790 fPoint = static_cast<float>(nValue);
792 if(fPoint < 0. || fPoint > 10000.)
793 return false;
795 nHeight = static_cast<long>( fPoint * 20.0 + 0.5 ); // Twips
796 if (!bConvert)
797 nHeight = convertTwipToMm100(nHeight); // Convert, if the item contains 1/100mm
799 break;
800 case MID_FONTHEIGHT_PROP:
802 sal_Int16 nNew = sal_Int16();
803 if(!(rVal >>= nNew))
804 return true;
806 nHeight = lcl_GetRealHeight_Impl(nHeight, nProp, ePropUnit, bConvert);
808 nHeight *= nNew;
809 nHeight /= 100;
810 nProp = nNew;
811 ePropUnit = MapUnit::MapRelative;
813 break;
814 case MID_FONTHEIGHT_DIFF:
816 nHeight = lcl_GetRealHeight_Impl(nHeight, nProp, ePropUnit, bConvert);
817 float fValue = 0;
818 if(!(rVal >>= fValue))
820 sal_Int32 nValue = 0;
821 if(!(rVal >>= nValue))
822 return false;
823 fValue = static_cast<float>(nValue);
825 sal_Int16 nCoreDiffValue = static_cast<sal_Int16>(fValue * 20.);
826 nHeight += bConvert ? nCoreDiffValue : convertTwipToMm100(nCoreDiffValue);
827 nProp = static_cast<sal_uInt16>(static_cast<sal_Int16>(fValue));
828 ePropUnit = MapUnit::MapPoint;
830 break;
832 return true;
836 bool SvxFontHeightItem::GetPresentation
838 SfxItemPresentation /*ePres*/,
839 MapUnit eCoreUnit,
840 MapUnit /*ePresUnit*/,
841 OUString& rText, const IntlWrapper& rIntl
842 ) const
844 if( MapUnit::MapRelative != ePropUnit )
846 rText = OUString::number( static_cast<short>(nProp) ) +
847 " " + EditResId( GetMetricId( ePropUnit ) );
848 if( 0 <= static_cast<short>(nProp) )
849 rText = "+" + rText;
851 else if( 100 == nProp )
853 rText = GetMetricText( static_cast<long>(nHeight),
854 eCoreUnit, MapUnit::MapPoint, &rIntl ) +
855 " " + EditResId(GetMetricId(MapUnit::MapPoint));
857 else
858 rText = OUString::number( nProp ) + "%";
859 return true;
863 void SvxFontHeightItem::ScaleMetrics( long nMult, long nDiv )
865 nHeight = static_cast<sal_uInt32>(Scale( nHeight, nMult, nDiv ));
869 bool SvxFontHeightItem::HasMetrics() const
871 return true;
874 void SvxFontHeightItem::SetHeight( sal_uInt32 nNewHeight, const sal_uInt16 nNewProp,
875 MapUnit eUnit )
877 DBG_ASSERT( GetRefCount() == 0, "SetValue() with pooled item" );
879 if( MapUnit::MapRelative != eUnit )
880 nHeight = nNewHeight + ::ItemToControl( short(nNewProp), eUnit,
881 FieldUnit::TWIP );
882 else if( 100 != nNewProp )
883 nHeight = sal_uInt32(( nNewHeight * nNewProp ) / 100 );
884 else
885 nHeight = nNewHeight;
887 nProp = nNewProp;
888 ePropUnit = eUnit;
891 void SvxFontHeightItem::SetHeight( sal_uInt32 nNewHeight, sal_uInt16 nNewProp,
892 MapUnit eMetric, MapUnit eCoreMetric )
894 DBG_ASSERT( GetRefCount() == 0, "SetValue() with pooled item" );
896 if( MapUnit::MapRelative != eMetric )
897 nHeight = nNewHeight +
898 ::ControlToItem( ::ItemToControl(static_cast<short>(nNewProp), eMetric,
899 FieldUnit::TWIP ), FieldUnit::TWIP,
900 eCoreMetric );
901 else if( 100 != nNewProp )
902 nHeight = sal_uInt32(( nNewHeight * nNewProp ) / 100 );
903 else
904 nHeight = nNewHeight;
906 nProp = nNewProp;
907 ePropUnit = eMetric;
910 void SvxFontHeightItem::dumpAsXml(xmlTextWriterPtr pWriter) const
912 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFontHeightItem"));
913 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
914 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("height"), BAD_CAST(OString::number(nHeight).getStr()));
915 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("prop"), BAD_CAST(OString::number(nProp).getStr()));
916 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("propUnit"), BAD_CAST(OString::number(static_cast<int>(ePropUnit)).getStr()));
917 xmlTextWriterEndElement(pWriter);
920 // class SvxTextLineItem ------------------------------------------------
922 SvxTextLineItem::SvxTextLineItem( const FontLineStyle eSt, const sal_uInt16 nId )
923 : SfxEnumItem( nId, eSt ), mColor( COL_TRANSPARENT )
928 bool SvxTextLineItem::HasBoolValue() const
930 return true;
934 bool SvxTextLineItem::GetBoolValue() const
936 return GetValue() != LINESTYLE_NONE;
940 void SvxTextLineItem::SetBoolValue( bool bVal )
942 SetValue( bVal ? LINESTYLE_SINGLE : LINESTYLE_NONE );
946 SfxPoolItem* SvxTextLineItem::Clone( SfxItemPool * ) const
948 return new SvxTextLineItem( *this );
952 sal_uInt16 SvxTextLineItem::GetValueCount() const
954 return LINESTYLE_DOTTED + 1; // LINESTYLE_NONE also belongs here
958 bool SvxTextLineItem::GetPresentation
960 SfxItemPresentation /*ePres*/,
961 MapUnit /*eCoreUnit*/,
962 MapUnit /*ePresUnit*/,
963 OUString& rText, const IntlWrapper& /*rIntl*/
964 ) const
966 rText = GetValueTextByPos( GetValue() );
967 if( !mColor.GetTransparency() )
968 rText += cpDelim + ::GetColorString( mColor );
969 return true;
973 OUString SvxTextLineItem::GetValueTextByPos( sal_uInt16 /*nPos*/ ) const
975 OSL_FAIL("SvxTextLineItem::GetValueTextByPos: Pure virtual method");
976 return OUString();
979 bool SvxTextLineItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
981 nMemberId &= ~CONVERT_TWIPS;
982 switch(nMemberId)
984 case MID_TEXTLINED:
985 rVal <<= GetBoolValue();
986 break;
987 case MID_TL_STYLE:
988 rVal <<= static_cast<sal_Int16>(GetValue());
989 break;
990 case MID_TL_COLOR:
991 rVal <<= mColor;
992 break;
993 case MID_TL_HASCOLOR:
994 rVal <<= !mColor.GetTransparency();
995 break;
997 return true;
1001 bool SvxTextLineItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1003 nMemberId &= ~CONVERT_TWIPS;
1004 bool bRet = true;
1005 switch(nMemberId)
1007 case MID_TEXTLINED:
1008 SetBoolValue(Any2Bool(rVal));
1009 break;
1010 case MID_TL_STYLE:
1012 sal_Int32 nValue = 0;
1013 if(!(rVal >>= nValue))
1014 bRet = false;
1015 else
1016 SetValue(static_cast<FontLineStyle>(nValue));
1018 break;
1019 case MID_TL_COLOR:
1021 sal_Int32 nCol = 0;
1022 if( !( rVal >>= nCol ) )
1023 bRet = false;
1024 else
1026 // Keep transparence, because it contains the information
1027 // whether the font color or the stored color should be used
1028 sal_uInt8 nTrans = mColor.GetTransparency();
1029 mColor = Color( nCol );
1030 mColor.SetTransparency( nTrans );
1033 break;
1034 case MID_TL_HASCOLOR:
1035 mColor.SetTransparency( Any2Bool( rVal ) ? 0 : 0xff );
1036 break;
1038 return bRet;
1041 bool SvxTextLineItem::operator==( const SfxPoolItem& rItem ) const
1043 return SfxEnumItem::operator==( rItem ) &&
1044 GetColor() == static_cast<const SvxTextLineItem&>(rItem).GetColor();
1047 // class SvxUnderlineItem ------------------------------------------------
1050 SvxUnderlineItem::SvxUnderlineItem( const FontLineStyle eSt, const sal_uInt16 nId )
1051 : SvxTextLineItem( eSt, nId )
1056 SfxPoolItem* SvxUnderlineItem::Clone( SfxItemPool * ) const
1058 return new SvxUnderlineItem( *this );
1062 OUString SvxUnderlineItem::GetValueTextByPos( sal_uInt16 nPos ) const
1064 static const char* RID_SVXITEMS_UL[] =
1066 RID_SVXITEMS_UL_NONE,
1067 RID_SVXITEMS_UL_SINGLE,
1068 RID_SVXITEMS_UL_DOUBLE,
1069 RID_SVXITEMS_UL_DOTTED,
1070 RID_SVXITEMS_UL_DONTKNOW,
1071 RID_SVXITEMS_UL_DASH,
1072 RID_SVXITEMS_UL_LONGDASH,
1073 RID_SVXITEMS_UL_DASHDOT,
1074 RID_SVXITEMS_UL_DASHDOTDOT,
1075 RID_SVXITEMS_UL_SMALLWAVE,
1076 RID_SVXITEMS_UL_WAVE,
1077 RID_SVXITEMS_UL_DOUBLEWAVE,
1078 RID_SVXITEMS_UL_BOLD,
1079 RID_SVXITEMS_UL_BOLDDOTTED,
1080 RID_SVXITEMS_UL_BOLDDASH,
1081 RID_SVXITEMS_UL_BOLDLONGDASH,
1082 RID_SVXITEMS_UL_BOLDDASHDOT,
1083 RID_SVXITEMS_UL_BOLDDASHDOTDOT,
1084 RID_SVXITEMS_UL_BOLDWAVE
1086 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_UL) - 1 == LINESTYLE_BOLDWAVE, "must match");
1087 assert(nPos <= sal_uInt16(LINESTYLE_BOLDWAVE) && "enum overflow!");
1088 return EditResId(RID_SVXITEMS_UL[nPos]);
1091 // class SvxOverlineItem ------------------------------------------------
1093 SvxOverlineItem::SvxOverlineItem( const FontLineStyle eSt, const sal_uInt16 nId )
1094 : SvxTextLineItem( eSt, nId )
1099 SfxPoolItem* SvxOverlineItem::Clone( SfxItemPool * ) const
1101 return new SvxOverlineItem( *this );
1105 OUString SvxOverlineItem::GetValueTextByPos( sal_uInt16 nPos ) const
1107 static const char* RID_SVXITEMS_OL[] =
1109 RID_SVXITEMS_OL_NONE,
1110 RID_SVXITEMS_OL_SINGLE,
1111 RID_SVXITEMS_OL_DOUBLE,
1112 RID_SVXITEMS_OL_DOTTED,
1113 RID_SVXITEMS_OL_DONTKNOW,
1114 RID_SVXITEMS_OL_DASH,
1115 RID_SVXITEMS_OL_LONGDASH,
1116 RID_SVXITEMS_OL_DASHDOT,
1117 RID_SVXITEMS_OL_DASHDOTDOT,
1118 RID_SVXITEMS_OL_SMALLWAVE,
1119 RID_SVXITEMS_OL_WAVE,
1120 RID_SVXITEMS_OL_DOUBLEWAVE,
1121 RID_SVXITEMS_OL_BOLD,
1122 RID_SVXITEMS_OL_BOLDDOTTED,
1123 RID_SVXITEMS_OL_BOLDDASH,
1124 RID_SVXITEMS_OL_BOLDLONGDASH,
1125 RID_SVXITEMS_OL_BOLDDASHDOT,
1126 RID_SVXITEMS_OL_BOLDDASHDOTDOT,
1127 RID_SVXITEMS_OL_BOLDWAVE
1129 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_OL) - 1 == LINESTYLE_BOLDWAVE, "must match");
1130 assert(nPos <= sal_uInt16(LINESTYLE_BOLDWAVE) && "enum overflow!");
1131 return EditResId(RID_SVXITEMS_OL[nPos]);
1134 // class SvxCrossedOutItem -----------------------------------------------
1136 SvxCrossedOutItem::SvxCrossedOutItem( const FontStrikeout eSt, const sal_uInt16 nId )
1137 : SfxEnumItem( nId, eSt )
1142 bool SvxCrossedOutItem::HasBoolValue() const
1144 return true;
1148 bool SvxCrossedOutItem::GetBoolValue() const
1150 return GetValue() != STRIKEOUT_NONE;
1154 void SvxCrossedOutItem::SetBoolValue( bool bVal )
1156 SetValue( bVal ? STRIKEOUT_SINGLE : STRIKEOUT_NONE );
1160 sal_uInt16 SvxCrossedOutItem::GetValueCount() const
1162 return STRIKEOUT_DOUBLE + 1; // STRIKEOUT_NONE belongs also here
1166 SfxPoolItem* SvxCrossedOutItem::Clone( SfxItemPool * ) const
1168 return new SvxCrossedOutItem( *this );
1172 bool SvxCrossedOutItem::GetPresentation
1174 SfxItemPresentation /*ePres*/,
1175 MapUnit /*eCoreUnit*/,
1176 MapUnit /*ePresUnit*/,
1177 OUString& rText, const IntlWrapper& /*rIntl*/
1178 ) const
1180 rText = GetValueTextByPos( GetValue() );
1181 return true;
1184 OUString SvxCrossedOutItem::GetValueTextByPos( sal_uInt16 nPos )
1186 static const char* RID_SVXITEMS_STRIKEOUT[] =
1188 RID_SVXITEMS_STRIKEOUT_NONE,
1189 RID_SVXITEMS_STRIKEOUT_SINGLE,
1190 RID_SVXITEMS_STRIKEOUT_DOUBLE,
1191 RID_SVXITEMS_STRIKEOUT_DONTKNOW,
1192 RID_SVXITEMS_STRIKEOUT_BOLD,
1193 RID_SVXITEMS_STRIKEOUT_SLASH,
1194 RID_SVXITEMS_STRIKEOUT_X
1196 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_STRIKEOUT) - 1 == STRIKEOUT_X, "must match");
1197 assert(nPos <= sal_uInt16(STRIKEOUT_X) && "enum overflow!");
1198 return EditResId(RID_SVXITEMS_STRIKEOUT[nPos]);
1201 bool SvxCrossedOutItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1203 nMemberId &= ~CONVERT_TWIPS;
1204 switch(nMemberId)
1206 case MID_CROSSED_OUT:
1207 rVal <<= GetBoolValue();
1208 break;
1209 case MID_CROSS_OUT:
1210 rVal <<= static_cast<sal_Int16>(GetValue());
1211 break;
1213 return true;
1216 bool SvxCrossedOutItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1218 nMemberId &= ~CONVERT_TWIPS;
1219 switch(nMemberId)
1221 case MID_CROSSED_OUT:
1222 SetBoolValue(Any2Bool(rVal));
1223 break;
1224 case MID_CROSS_OUT:
1226 sal_Int32 nValue = 0;
1227 if(!(rVal >>= nValue))
1228 return false;
1229 SetValue(static_cast<FontStrikeout>(nValue));
1231 break;
1233 return true;
1235 // class SvxShadowedItem -------------------------------------------------
1237 SvxShadowedItem::SvxShadowedItem( const bool bShadowed, const sal_uInt16 nId ) :
1238 SfxBoolItem( nId, bShadowed )
1243 SfxPoolItem* SvxShadowedItem::Clone( SfxItemPool * ) const
1245 return new SvxShadowedItem( *this );
1249 bool SvxShadowedItem::GetPresentation
1251 SfxItemPresentation /*ePres*/,
1252 MapUnit /*eCoreUnit*/,
1253 MapUnit /*ePresUnit*/,
1254 OUString& rText, const IntlWrapper& /*rIntl*/
1255 ) const
1257 const char* pId = RID_SVXITEMS_SHADOWED_FALSE;
1259 if ( GetValue() )
1260 pId = RID_SVXITEMS_SHADOWED_TRUE;
1261 rText = EditResId(pId);
1262 return true;
1265 // class SvxAutoKernItem -------------------------------------------------
1267 SvxAutoKernItem::SvxAutoKernItem( const bool bAutoKern, const sal_uInt16 nId ) :
1268 SfxBoolItem( nId, bAutoKern )
1273 SfxPoolItem* SvxAutoKernItem::Clone( SfxItemPool * ) const
1275 return new SvxAutoKernItem( *this );
1279 bool SvxAutoKernItem::GetPresentation
1281 SfxItemPresentation /*ePres*/,
1282 MapUnit /*eCoreUnit*/,
1283 MapUnit /*ePresUnit*/,
1284 OUString& rText, const IntlWrapper& /*rIntl*/
1285 ) const
1287 const char* pId = RID_SVXITEMS_AUTOKERN_FALSE;
1289 if ( GetValue() )
1290 pId = RID_SVXITEMS_AUTOKERN_TRUE;
1291 rText = EditResId(pId);
1292 return true;
1295 // class SvxWordLineModeItem ---------------------------------------------
1297 SvxWordLineModeItem::SvxWordLineModeItem( const bool bWordLineMode,
1298 const sal_uInt16 nId ) :
1299 SfxBoolItem( nId, bWordLineMode )
1304 SfxPoolItem* SvxWordLineModeItem::Clone( SfxItemPool * ) const
1306 return new SvxWordLineModeItem( *this );
1310 bool SvxWordLineModeItem::GetPresentation
1312 SfxItemPresentation /*ePres*/,
1313 MapUnit /*eCoreUnit*/,
1314 MapUnit /*ePresUnit*/,
1315 OUString& rText, const IntlWrapper& /*rIntl*/
1316 ) const
1318 const char* pId = RID_SVXITEMS_WORDLINE_FALSE;
1320 if ( GetValue() )
1321 pId = RID_SVXITEMS_WORDLINE_TRUE;
1322 rText = EditResId(pId);
1323 return true;
1326 // class SvxContourItem --------------------------------------------------
1328 SvxContourItem::SvxContourItem( const bool bContoured, const sal_uInt16 nId ) :
1329 SfxBoolItem( nId, bContoured )
1334 SfxPoolItem* SvxContourItem::Clone( SfxItemPool * ) const
1336 return new SvxContourItem( *this );
1340 bool SvxContourItem::GetPresentation
1342 SfxItemPresentation /*ePres*/,
1343 MapUnit /*eCoreUnit*/,
1344 MapUnit /*ePresUnit*/,
1345 OUString& rText, const IntlWrapper& /*rIntl*/
1346 ) const
1348 const char* pId = RID_SVXITEMS_CONTOUR_FALSE;
1350 if ( GetValue() )
1351 pId = RID_SVXITEMS_CONTOUR_TRUE;
1352 rText = EditResId(pId);
1353 return true;
1356 // class SvxBackgroundColorItem -----------------------------------------
1358 SvxBackgroundColorItem::SvxBackgroundColorItem( const sal_uInt16 nId ) :
1359 SvxColorItem( nId )
1364 SvxBackgroundColorItem::SvxBackgroundColorItem( const Color& rCol,
1365 const sal_uInt16 nId ) :
1366 SvxColorItem( rCol, nId )
1370 SfxPoolItem* SvxBackgroundColorItem::Clone( SfxItemPool * ) const
1372 return new SvxBackgroundColorItem(*this);
1375 bool SvxBackgroundColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1377 nMemberId &= ~CONVERT_TWIPS;
1378 Color aColor = SvxColorItem::GetValue();
1380 switch( nMemberId )
1382 case MID_GRAPHIC_TRANSPARENT:
1384 rVal <<= aColor.GetTransparency() == 0xff;
1385 break;
1387 default:
1389 rVal <<= aColor;
1390 break;
1393 return true;
1396 bool SvxBackgroundColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1398 nMemberId &= ~CONVERT_TWIPS;
1399 sal_Int32 nColor = 0;
1400 Color aColor = SvxColorItem::GetValue();
1402 switch( nMemberId )
1404 case MID_GRAPHIC_TRANSPARENT:
1406 aColor.SetTransparency( Any2Bool( rVal ) ? 0xff : 0 );
1407 SvxColorItem::SetValue( aColor );
1408 break;
1410 default:
1412 if(!(rVal >>= nColor))
1413 return false;
1414 SvxColorItem::SetValue( Color(nColor) );
1415 break;
1418 return true;
1421 // class SvxColorItem ----------------------------------------------------
1422 SvxColorItem::SvxColorItem( const sal_uInt16 nId ) :
1423 SfxPoolItem( nId ),
1424 mColor( COL_BLACK )
1428 SvxColorItem::SvxColorItem( const Color& rCol, const sal_uInt16 nId ) :
1429 SfxPoolItem( nId ),
1430 mColor( rCol )
1434 SvxColorItem::~SvxColorItem()
1438 bool SvxColorItem::operator==( const SfxPoolItem& rAttr ) const
1440 assert(SfxPoolItem::operator==(rAttr));
1442 return mColor == static_cast<const SvxColorItem&>( rAttr ).mColor;
1445 bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
1447 rVal <<= mColor;
1448 return true;
1451 bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
1453 return (rVal >>= mColor);
1456 SfxPoolItem* SvxColorItem::Clone( SfxItemPool * ) const
1458 return new SvxColorItem( *this );
1461 bool SvxColorItem::GetPresentation
1463 SfxItemPresentation /*ePres*/,
1464 MapUnit /*eCoreUnit*/,
1465 MapUnit /*ePresUnit*/,
1466 OUString& rText, const IntlWrapper& /*rIntl*/
1467 ) const
1469 rText = ::GetColorString( mColor );
1470 return true;
1473 void SvxColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1475 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxColorItem"));
1476 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1477 OUString aStr;
1478 IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
1479 GetPresentation( SfxItemPresentation::Complete, MapUnit::Map100thMM, MapUnit::Map100thMM, aStr, aIntlWrapper);
1480 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8).getStr()));
1481 xmlTextWriterEndElement(pWriter);
1486 void SvxColorItem::SetValue( const Color& rNewCol )
1488 mColor = rNewCol;
1491 // class SvxKerningItem --------------------------------------------------
1493 SvxKerningItem::SvxKerningItem( const short nKern, const sal_uInt16 nId ) :
1494 SfxInt16Item( nId, nKern )
1499 SfxPoolItem* SvxKerningItem::Clone( SfxItemPool * ) const
1501 return new SvxKerningItem( *this );
1505 void SvxKerningItem::ScaleMetrics( long nMult, long nDiv )
1507 SetValue( static_cast<sal_Int16>(Scale( GetValue(), nMult, nDiv )) );
1511 bool SvxKerningItem::HasMetrics() const
1513 return true;
1517 bool SvxKerningItem::GetPresentation
1519 SfxItemPresentation ePres,
1520 MapUnit eCoreUnit,
1521 MapUnit /*ePresUnit*/,
1522 OUString& rText, const IntlWrapper& rIntl
1523 ) const
1525 switch ( ePres )
1527 case SfxItemPresentation::Nameless:
1528 rText = GetMetricText( static_cast<long>(GetValue()), eCoreUnit, MapUnit::MapPoint, &rIntl ) +
1529 " " + EditResId(GetMetricId(MapUnit::MapPoint));
1530 return true;
1531 case SfxItemPresentation::Complete:
1533 rText = EditResId(RID_SVXITEMS_KERNING_COMPLETE);
1534 const char* pId = nullptr;
1536 if ( GetValue() > 0 )
1537 pId = RID_SVXITEMS_KERNING_EXPANDED;
1538 else if ( GetValue() < 0 )
1539 pId = RID_SVXITEMS_KERNING_CONDENSED;
1541 if (pId)
1542 rText += EditResId(pId);
1543 rText += GetMetricText( static_cast<long>(GetValue()), eCoreUnit, MapUnit::MapPoint, &rIntl ) +
1544 " " + EditResId(GetMetricId(MapUnit::MapPoint));
1545 return true;
1547 default: ; //prevent warning
1549 return false;
1552 bool SvxKerningItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1554 sal_Int16 nVal = GetValue();
1555 if(nMemberId & CONVERT_TWIPS)
1556 nVal = static_cast<sal_Int16>(convertTwipToMm100(nVal));
1557 rVal <<= nVal;
1558 return true;
1561 bool SvxKerningItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId)
1563 sal_Int16 nVal = sal_Int16();
1564 if(!(rVal >>= nVal))
1565 return false;
1566 if(nMemberId & CONVERT_TWIPS)
1567 nVal = static_cast<sal_Int16>(convertMm100ToTwip(nVal));
1568 SetValue(nVal);
1569 return true;
1572 // class SvxCaseMapItem --------------------------------------------------
1574 SvxCaseMapItem::SvxCaseMapItem( const SvxCaseMap eMap, const sal_uInt16 nId ) :
1575 SfxEnumItem( nId, eMap )
1580 sal_uInt16 SvxCaseMapItem::GetValueCount() const
1582 return sal_uInt16(SvxCaseMap::End); // SvxCaseMap::SmallCaps + 1
1586 SfxPoolItem* SvxCaseMapItem::Clone( SfxItemPool * ) const
1588 return new SvxCaseMapItem( *this );
1592 bool SvxCaseMapItem::GetPresentation
1594 SfxItemPresentation /*ePres*/,
1595 MapUnit /*eCoreUnit*/,
1596 MapUnit /*ePresUnit*/,
1597 OUString& rText, const IntlWrapper& /*rIntl*/
1598 ) const
1600 rText = GetValueTextByPos( static_cast<sal_uInt16>(GetValue()) );
1601 return true;
1604 OUString SvxCaseMapItem::GetValueTextByPos( sal_uInt16 nPos )
1606 static const char* RID_SVXITEMS_CASEMAP[] =
1608 RID_SVXITEMS_CASEMAP_NONE,
1609 RID_SVXITEMS_CASEMAP_UPPERCASE,
1610 RID_SVXITEMS_CASEMAP_LOWERCASE,
1611 RID_SVXITEMS_CASEMAP_TITLE,
1612 RID_SVXITEMS_CASEMAP_SMALLCAPS
1615 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_CASEMAP) == size_t(SvxCaseMap::End), "must match");
1616 assert(nPos < sal_uInt16(SvxCaseMap::End) && "enum overflow!");
1617 return EditResId(RID_SVXITEMS_CASEMAP[nPos]);
1620 bool SvxCaseMapItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
1622 sal_Int16 nRet = style::CaseMap::NONE;
1623 switch( GetValue() )
1625 case SvxCaseMap::Uppercase : nRet = style::CaseMap::UPPERCASE; break;
1626 case SvxCaseMap::Lowercase : nRet = style::CaseMap::LOWERCASE; break;
1627 case SvxCaseMap::Capitalize : nRet = style::CaseMap::TITLE ; break;
1628 case SvxCaseMap::SmallCaps: nRet = style::CaseMap::SMALLCAPS; break;
1629 default: break;
1631 rVal <<= nRet;
1632 return true;
1635 bool SvxCaseMapItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
1637 sal_uInt16 nVal = sal_uInt16();
1638 if(!(rVal >>= nVal))
1639 return false;
1641 SvxCaseMap eVal;
1642 switch( nVal )
1644 case style::CaseMap::NONE : eVal = SvxCaseMap::NotMapped; break;
1645 case style::CaseMap::UPPERCASE: eVal = SvxCaseMap::Uppercase; break;
1646 case style::CaseMap::LOWERCASE: eVal = SvxCaseMap::Lowercase; break;
1647 case style::CaseMap::TITLE : eVal = SvxCaseMap::Capitalize; break;
1648 case style::CaseMap::SMALLCAPS: eVal = SvxCaseMap::SmallCaps; break;
1649 default: return false;
1651 SetValue(eVal);
1652 return true;
1655 // class SvxEscapementItem -----------------------------------------------
1657 SvxEscapementItem::SvxEscapementItem( const sal_uInt16 nId ) :
1658 SfxEnumItemInterface( nId ),
1660 nEsc ( 0 ),
1661 nProp ( 100 )
1666 SvxEscapementItem::SvxEscapementItem( const SvxEscapement eEscape,
1667 const sal_uInt16 nId ) :
1668 SfxEnumItemInterface( nId ),
1669 nProp( 100 )
1671 SetEscapement( eEscape );
1672 if( nEsc )
1673 nProp = 58;
1677 SvxEscapementItem::SvxEscapementItem( const short _nEsc,
1678 const sal_uInt8 _nProp,
1679 const sal_uInt16 nId ) :
1680 SfxEnumItemInterface( nId ),
1681 nEsc ( _nEsc ),
1682 nProp ( _nProp )
1687 bool SvxEscapementItem::operator==( const SfxPoolItem& rAttr ) const
1689 assert(SfxPoolItem::operator==(rAttr));
1691 return( nEsc == static_cast<const SvxEscapementItem&>(rAttr).nEsc &&
1692 nProp == static_cast<const SvxEscapementItem&>(rAttr).nProp );
1696 SfxPoolItem* SvxEscapementItem::Clone( SfxItemPool * ) const
1698 return new SvxEscapementItem( *this );
1702 sal_uInt16 SvxEscapementItem::GetValueCount() const
1704 return sal_uInt16(SvxEscapement::End); // SvxEscapement::Subscript + 1
1708 bool SvxEscapementItem::GetPresentation
1710 SfxItemPresentation /*ePres*/,
1711 MapUnit /*eCoreUnit*/,
1712 MapUnit /*ePresUnit*/,
1713 OUString& rText, const IntlWrapper& /*rIntl*/
1714 ) const
1716 rText = GetValueTextByPos( GetEnumValue() );
1718 if ( nEsc != 0 )
1720 if( DFLT_ESC_AUTO_SUPER == nEsc || DFLT_ESC_AUTO_SUB == nEsc )
1721 rText += EditResId(RID_SVXITEMS_ESCAPEMENT_AUTO);
1722 else
1723 rText += OUString::number( nEsc ) + "%";
1725 return true;
1728 OUString SvxEscapementItem::GetValueTextByPos( sal_uInt16 nPos )
1730 static const char* RID_SVXITEMS_ESCAPEMENT[] =
1732 RID_SVXITEMS_ESCAPEMENT_OFF,
1733 RID_SVXITEMS_ESCAPEMENT_SUPER,
1734 RID_SVXITEMS_ESCAPEMENT_SUB
1737 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_ESCAPEMENT) == size_t(SvxEscapement::End), "must match");
1738 assert(nPos < sal_uInt16(SvxEscapement::End) && "enum overflow!");
1739 return EditResId(RID_SVXITEMS_ESCAPEMENT[nPos]);
1742 sal_uInt16 SvxEscapementItem::GetEnumValue() const
1744 if ( nEsc < 0 )
1745 return sal_uInt16(SvxEscapement::Subscript);
1746 else if ( nEsc > 0 )
1747 return sal_uInt16(SvxEscapement::Superscript);
1748 return sal_uInt16(SvxEscapement::Off);
1752 void SvxEscapementItem::SetEnumValue( sal_uInt16 nVal )
1754 SetEscapement( static_cast<SvxEscapement>(nVal) );
1757 bool SvxEscapementItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1759 nMemberId &= ~CONVERT_TWIPS;
1760 switch(nMemberId)
1762 case MID_ESC:
1763 rVal <<= static_cast<sal_Int16>(nEsc);
1764 break;
1765 case MID_ESC_HEIGHT:
1766 rVal <<= static_cast<sal_Int8>(nProp);
1767 break;
1768 case MID_AUTO_ESC:
1769 rVal <<= (DFLT_ESC_AUTO_SUB == nEsc || DFLT_ESC_AUTO_SUPER == nEsc);
1770 break;
1772 return true;
1775 bool SvxEscapementItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1777 nMemberId &= ~CONVERT_TWIPS;
1778 switch(nMemberId)
1780 case MID_ESC:
1782 sal_Int16 nVal = sal_Int16();
1783 // tdf#120412 up to 14400% (eg. 1584 pt with 11 pt letters)
1784 if( (rVal >>= nVal) && (std::abs(nVal) <= 14400))
1785 nEsc = nVal;
1786 else
1787 return false;
1789 break;
1790 case MID_ESC_HEIGHT:
1792 sal_Int8 nVal = sal_Int8();
1793 if( (rVal >>= nVal) && (nVal <= 100))
1794 nProp = nVal;
1795 else
1796 return false;
1798 break;
1799 case MID_AUTO_ESC:
1801 bool bVal = Any2Bool(rVal);
1802 if(bVal)
1804 if(nEsc < 0)
1805 nEsc = DFLT_ESC_AUTO_SUB;
1806 else
1807 nEsc = DFLT_ESC_AUTO_SUPER;
1809 else
1810 if(DFLT_ESC_AUTO_SUPER == nEsc )
1811 --nEsc;
1812 else if(DFLT_ESC_AUTO_SUB == nEsc)
1813 ++nEsc;
1815 break;
1817 return true;
1820 // class SvxLanguageItem -------------------------------------------------
1822 SvxLanguageItem::SvxLanguageItem( const LanguageType eLang, const sal_uInt16 nId )
1823 : SvxLanguageItem_Base( nId , eLang )
1828 sal_uInt16 SvxLanguageItem::GetValueCount() const
1830 // #i50205# got rid of class International
1831 SAL_WARN( "editeng.items", "SvxLanguageItem::GetValueCount: supposed to return a count of what?");
1832 // Could be SvtLanguageTable::GetEntryCount() (all locales with resource string)?
1833 // Could be LocaleDataWrapper::getInstalledLanguageTypes() (all locales with locale data)?
1834 return 0;
1838 SfxPoolItem* SvxLanguageItem::Clone( SfxItemPool * ) const
1840 return new SvxLanguageItem( *this );
1844 bool SvxLanguageItem::GetPresentation
1846 SfxItemPresentation /*ePres*/,
1847 MapUnit /*eCoreUnit*/,
1848 MapUnit /*ePresUnit*/,
1849 OUString& rText, const IntlWrapper& /*rIntl*/
1850 ) const
1852 rText = SvtLanguageTable::GetLanguageString( GetValue() );
1853 return true;
1856 bool SvxLanguageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1858 nMemberId &= ~CONVERT_TWIPS;
1859 switch(nMemberId)
1861 case MID_LANG_INT: // for basic conversions!
1862 rVal <<= static_cast<sal_Int16>(static_cast<sal_uInt16>(GetValue()));
1863 break;
1864 case MID_LANG_LOCALE:
1865 lang::Locale aRet( LanguageTag::convertToLocale( GetValue(), false));
1866 rVal <<= aRet;
1867 break;
1869 return true;
1872 bool SvxLanguageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1874 nMemberId &= ~CONVERT_TWIPS;
1875 switch(nMemberId)
1877 case MID_LANG_INT: // for basic conversions!
1879 sal_Int32 nValue = 0;
1880 if(!(rVal >>= nValue))
1881 return false;
1883 SetValue(LanguageType(nValue));
1885 break;
1886 case MID_LANG_LOCALE:
1888 lang::Locale aLocale;
1889 if(!(rVal >>= aLocale))
1890 return false;
1892 SetValue( LanguageTag::convertToLanguageType( aLocale, false));
1894 break;
1896 return true;
1899 // class SvxNoHyphenItem -------------------------------------------------
1901 SvxNoHyphenItem::SvxNoHyphenItem( const sal_uInt16 nId ) :
1902 SfxBoolItem( nId , true )
1907 SfxPoolItem* SvxNoHyphenItem::Clone( SfxItemPool* ) const
1909 return new SvxNoHyphenItem( *this );
1913 bool SvxNoHyphenItem::GetPresentation
1915 SfxItemPresentation /*ePres*/,
1916 MapUnit /*eCoreUnit*/,
1917 MapUnit /*ePresUnit*/,
1918 OUString& rText, const IntlWrapper& /*rIntl*/
1919 ) const
1921 rText.clear();
1922 return false;
1926 * Dummy item for ToolBox controls:
1931 // class SvxBlinkItem -------------------------------------------------
1934 SvxBlinkItem::SvxBlinkItem( const bool bBlink, const sal_uInt16 nId ) :
1935 SfxBoolItem( nId, bBlink )
1940 SfxPoolItem* SvxBlinkItem::Clone( SfxItemPool * ) const
1942 return new SvxBlinkItem( *this );
1946 bool SvxBlinkItem::GetPresentation
1948 SfxItemPresentation /*ePres*/,
1949 MapUnit /*eCoreUnit*/,
1950 MapUnit /*ePresUnit*/,
1951 OUString& rText, const IntlWrapper& /*rIntl*/
1952 ) const
1954 const char* pId = RID_SVXITEMS_BLINK_FALSE;
1956 if ( GetValue() )
1957 pId = RID_SVXITEMS_BLINK_TRUE;
1958 rText = EditResId(pId);
1959 return true;
1962 // class SvxEmphaisMarkItem ---------------------------------------------------
1964 SvxEmphasisMarkItem::SvxEmphasisMarkItem( const FontEmphasisMark nValue,
1965 const sal_uInt16 nId )
1966 : SfxUInt16Item( nId, static_cast<sal_uInt16>(nValue) )
1971 SfxPoolItem* SvxEmphasisMarkItem::Clone( SfxItemPool * ) const
1973 return new SvxEmphasisMarkItem( *this );
1977 bool SvxEmphasisMarkItem::GetPresentation
1979 SfxItemPresentation /*ePres*/,
1980 MapUnit /*eCoreUnit*/,
1981 MapUnit /*ePresUnit*/,
1982 OUString& rText,
1983 const IntlWrapper& /*rIntl*/
1984 ) const
1986 static const char* RID_SVXITEMS_EMPHASIS[] =
1988 RID_SVXITEMS_EMPHASIS_NONE_STYLE,
1989 RID_SVXITEMS_EMPHASIS_DOT_STYLE,
1990 RID_SVXITEMS_EMPHASIS_CIRCLE_STYLE,
1991 RID_SVXITEMS_EMPHASIS_DISC_STYLE,
1992 RID_SVXITEMS_EMPHASIS_ACCENT_STYLE
1995 FontEmphasisMark nVal = GetEmphasisMark();
1996 rText = EditResId(RID_SVXITEMS_EMPHASIS[
1997 static_cast<sal_uInt16>(static_cast<FontEmphasisMark>( nVal & FontEmphasisMark::Style ))]);
1998 const char* pId = ( FontEmphasisMark::PosAbove & nVal )
1999 ? RID_SVXITEMS_EMPHASIS_ABOVE_POS
2000 : ( FontEmphasisMark::PosBelow & nVal )
2001 ? RID_SVXITEMS_EMPHASIS_BELOW_POS
2002 : nullptr;
2003 if( pId )
2004 rText += EditResId( pId );
2005 return true;
2008 bool SvxEmphasisMarkItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
2010 nMemberId &= ~CONVERT_TWIPS;
2011 switch( nMemberId )
2013 case MID_EMPHASIS:
2015 FontEmphasisMark nValue = GetEmphasisMark();
2016 sal_Int16 nRet = 0;
2017 switch(nValue & FontEmphasisMark::Style)
2019 case FontEmphasisMark::NONE : nRet = FontEmphasis::NONE; break;
2020 case FontEmphasisMark::Dot : nRet = FontEmphasis::DOT_ABOVE; break;
2021 case FontEmphasisMark::Circle : nRet = FontEmphasis::CIRCLE_ABOVE; break;
2022 case FontEmphasisMark::Disc : nRet = FontEmphasis::DISK_ABOVE; break;
2023 case FontEmphasisMark::Accent : nRet = FontEmphasis::ACCENT_ABOVE; break;
2024 default: break;
2026 if(nRet && nValue & FontEmphasisMark::PosBelow)
2027 nRet += 10;
2028 rVal <<= nRet;
2030 break;
2032 return true;
2035 bool SvxEmphasisMarkItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
2037 nMemberId &= ~CONVERT_TWIPS;
2038 switch( nMemberId )
2040 case MID_EMPHASIS:
2042 sal_Int32 nValue = -1;
2043 rVal >>= nValue;
2044 FontEmphasisMark nMark;
2045 switch(nValue)
2047 case FontEmphasis::NONE : nMark = FontEmphasisMark::NONE; break;
2048 case FontEmphasis::DOT_ABOVE : nMark = FontEmphasisMark::Dot|FontEmphasisMark::PosAbove; break;
2049 case FontEmphasis::CIRCLE_ABOVE: nMark = FontEmphasisMark::Circle|FontEmphasisMark::PosAbove; break;
2050 case FontEmphasis::DISK_ABOVE : nMark = FontEmphasisMark::Disc|FontEmphasisMark::PosAbove; break;
2051 case FontEmphasis::ACCENT_ABOVE: nMark = FontEmphasisMark::Accent|FontEmphasisMark::PosAbove; break;
2052 case FontEmphasis::DOT_BELOW : nMark = FontEmphasisMark::Dot|FontEmphasisMark::PosBelow; break;
2053 case FontEmphasis::CIRCLE_BELOW: nMark = FontEmphasisMark::Circle|FontEmphasisMark::PosBelow; break;
2054 case FontEmphasis::DISK_BELOW : nMark = FontEmphasisMark::Disc|FontEmphasisMark::PosBelow; break;
2055 case FontEmphasis::ACCENT_BELOW: nMark = FontEmphasisMark::Accent|FontEmphasisMark::PosBelow; break;
2056 default: return false;
2058 SetValue( static_cast<sal_Int16>(nMark) );
2060 break;
2062 return true;
2065 /*************************************************************************
2066 |* class SvxTwoLinesItem
2067 *************************************************************************/
2069 SvxTwoLinesItem::SvxTwoLinesItem( bool bFlag, sal_Unicode nStartBracket,
2070 sal_Unicode nEndBracket, sal_uInt16 nW )
2071 : SfxPoolItem( nW ),
2072 cStartBracket( nStartBracket ), cEndBracket( nEndBracket ), bOn( bFlag )
2076 SvxTwoLinesItem::~SvxTwoLinesItem()
2080 bool SvxTwoLinesItem::operator==( const SfxPoolItem& rAttr ) const
2082 assert(SfxPoolItem::operator==(rAttr));
2083 return bOn == static_cast<const SvxTwoLinesItem&>(rAttr).bOn &&
2084 cStartBracket == static_cast<const SvxTwoLinesItem&>(rAttr).cStartBracket &&
2085 cEndBracket == static_cast<const SvxTwoLinesItem&>(rAttr).cEndBracket;
2088 SfxPoolItem* SvxTwoLinesItem::Clone( SfxItemPool* ) const
2090 return new SvxTwoLinesItem( *this );
2093 bool SvxTwoLinesItem::QueryValue( css::uno::Any& rVal,
2094 sal_uInt8 nMemberId ) const
2096 nMemberId &= ~CONVERT_TWIPS;
2097 bool bRet = true;
2098 switch( nMemberId )
2100 case MID_TWOLINES:
2101 rVal <<= bOn;
2102 break;
2103 case MID_START_BRACKET:
2105 OUString s;
2106 if( cStartBracket )
2107 s = OUString( cStartBracket );
2108 rVal <<= s;
2110 break;
2111 case MID_END_BRACKET:
2113 OUString s;
2114 if( cEndBracket )
2115 s = OUString( cEndBracket );
2116 rVal <<= s;
2118 break;
2119 default:
2120 bRet = false;
2121 break;
2123 return bRet;
2126 bool SvxTwoLinesItem::PutValue( const css::uno::Any& rVal,
2127 sal_uInt8 nMemberId )
2129 nMemberId &= ~CONVERT_TWIPS;
2130 bool bRet = false;
2131 OUString s;
2132 switch( nMemberId )
2134 case MID_TWOLINES:
2135 bOn = Any2Bool( rVal );
2136 bRet = true;
2137 break;
2138 case MID_START_BRACKET:
2139 if( rVal >>= s )
2141 cStartBracket = s.isEmpty() ? 0 : s[ 0 ];
2142 bRet = true;
2144 break;
2145 case MID_END_BRACKET:
2146 if( rVal >>= s )
2148 cEndBracket = s.isEmpty() ? 0 : s[ 0 ];
2149 bRet = true;
2151 break;
2153 return bRet;
2156 bool SvxTwoLinesItem::GetPresentation( SfxItemPresentation /*ePres*/,
2157 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2158 OUString &rText, const IntlWrapper& /*rIntl*/ ) const
2160 if( !GetValue() )
2161 rText = EditResId( RID_SVXITEMS_TWOLINES_OFF );
2162 else
2164 rText = EditResId( RID_SVXITEMS_TWOLINES );
2165 if( GetStartBracket() )
2166 rText = OUStringChar(GetStartBracket()) + rText;
2167 if( GetEndBracket() )
2168 rText += OUStringChar(GetEndBracket());
2170 return true;
2174 /*************************************************************************
2175 |* class SvxTextRotateItem
2176 *************************************************************************/
2178 SvxTextRotateItem::SvxTextRotateItem(sal_uInt16 nValue, const sal_uInt16 nW)
2179 : SfxUInt16Item(nW, nValue)
2183 SfxPoolItem* SvxTextRotateItem::Clone(SfxItemPool*) const
2185 return new SvxTextRotateItem(*this);
2188 bool SvxTextRotateItem::GetPresentation(
2189 SfxItemPresentation /*ePres*/,
2190 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2191 OUString &rText, const IntlWrapper&) const
2193 if (!GetValue())
2194 rText = EditResId(RID_SVXITEMS_TEXTROTATE_OFF);
2195 else
2197 rText = EditResId(RID_SVXITEMS_TEXTROTATE);
2198 rText = rText.replaceFirst("$(ARG1)",
2199 OUString::number(GetValue() / 10));
2201 return true;
2204 bool SvxTextRotateItem::QueryValue(css::uno::Any& rVal,
2205 sal_uInt8 nMemberId) const
2207 nMemberId &= ~CONVERT_TWIPS;
2208 bool bRet = true;
2209 switch (nMemberId)
2211 case MID_ROTATE:
2212 rVal <<= static_cast<sal_Int16>(GetValue());
2213 break;
2214 default:
2215 bRet = false;
2216 break;
2218 return bRet;
2221 bool SvxTextRotateItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId)
2223 nMemberId &= ~CONVERT_TWIPS;
2224 bool bRet = true;
2225 switch (nMemberId)
2227 case MID_ROTATE:
2229 sal_Int16 nVal = 0;
2230 if ((rVal >>= nVal) && (0 == nVal || 900 == nVal || 2700 == nVal))
2231 SetValue(static_cast<sal_uInt16>(nVal));
2232 else
2233 bRet = false;
2234 break;
2236 default:
2237 bRet = false;
2239 return bRet;
2242 void SvxTextRotateItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2244 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTextRotateItem"));
2245 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
2246 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
2247 xmlTextWriterEndElement(pWriter);
2251 /*************************************************************************
2252 |* class SvxCharRotateItem
2253 *************************************************************************/
2255 SvxCharRotateItem::SvxCharRotateItem( sal_uInt16 nValue,
2256 bool bFitIntoLine,
2257 const sal_uInt16 nW )
2258 : SvxTextRotateItem(nValue, nW), bFitToLine( bFitIntoLine )
2262 SfxPoolItem* SvxCharRotateItem::Clone( SfxItemPool* ) const
2264 return new SvxCharRotateItem( *this );
2267 bool SvxCharRotateItem::GetPresentation(
2268 SfxItemPresentation /*ePres*/,
2269 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2270 OUString &rText, const IntlWrapper&) const
2272 if( !GetValue() )
2273 rText = EditResId( RID_SVXITEMS_CHARROTATE_OFF );
2274 else
2276 rText = EditResId( RID_SVXITEMS_CHARROTATE );
2277 rText = rText.replaceFirst( "$(ARG1)",
2278 OUString::number( GetValue() / 10 ));
2279 if( IsFitToLine() )
2280 rText += EditResId( RID_SVXITEMS_CHARROTATE_FITLINE );
2282 return true;
2285 bool SvxCharRotateItem::QueryValue( css::uno::Any& rVal,
2286 sal_uInt8 nMemberId ) const
2288 bool bRet = true;
2289 switch(nMemberId & ~CONVERT_TWIPS)
2291 case MID_ROTATE:
2292 SvxTextRotateItem::QueryValue(rVal, nMemberId);
2293 break;
2294 case MID_FITTOLINE:
2295 rVal <<= IsFitToLine();
2296 break;
2297 default:
2298 bRet = false;
2299 break;
2301 return bRet;
2304 bool SvxCharRotateItem::PutValue( const css::uno::Any& rVal,
2305 sal_uInt8 nMemberId )
2307 bool bRet = true;
2308 switch(nMemberId & ~CONVERT_TWIPS)
2310 case MID_ROTATE:
2312 bRet = SvxTextRotateItem::PutValue(rVal, nMemberId);
2313 break;
2316 case MID_FITTOLINE:
2317 SetFitToLine( Any2Bool( rVal ) );
2318 break;
2319 default:
2320 bRet = false;
2322 return bRet;
2325 bool SvxCharRotateItem::operator==( const SfxPoolItem& rItem ) const
2327 assert(SfxPoolItem::operator==(rItem));
2328 return SvxTextRotateItem::operator==( rItem ) &&
2329 IsFitToLine() == static_cast<const SvxCharRotateItem&>(rItem).IsFitToLine();
2332 void SvxCharRotateItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2334 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxCharRotateItem"));
2335 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
2336 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
2337 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("fitToLine"), BAD_CAST(OString::boolean(IsFitToLine()).getStr()));
2338 xmlTextWriterEndElement(pWriter);
2341 /*************************************************************************
2342 |* class SvxCharScaleItem
2343 *************************************************************************/
2345 SvxCharScaleWidthItem::SvxCharScaleWidthItem( sal_uInt16 nValue,
2346 const sal_uInt16 nW )
2347 : SfxUInt16Item( nW, nValue )
2351 SfxPoolItem* SvxCharScaleWidthItem::Clone( SfxItemPool* ) const
2353 return new SvxCharScaleWidthItem( *this );
2357 bool SvxCharScaleWidthItem::GetPresentation(
2358 SfxItemPresentation /*ePres*/,
2359 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2360 OUString &rText, const IntlWrapper&) const
2362 if( !GetValue() )
2363 rText = EditResId( RID_SVXITEMS_CHARSCALE_OFF );
2364 else
2366 rText = EditResId( RID_SVXITEMS_CHARSCALE );
2367 rText = rText.replaceFirst( "$(ARG1)",
2368 OUString::number( GetValue() ));
2370 return true;
2373 bool SvxCharScaleWidthItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
2375 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
2376 // where we still want this to be a sal_Int16
2377 sal_Int16 nValue = sal_Int16();
2378 if (rVal >>= nValue)
2380 SetValue( static_cast<sal_uInt16>(nValue) );
2381 return true;
2384 SAL_WARN("editeng.items", "SvxCharScaleWidthItem::PutValue - Wrong type!" );
2385 return false;
2388 bool SvxCharScaleWidthItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
2390 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
2391 // where we still want this to be a sal_Int16
2392 rVal <<= static_cast<sal_Int16>(GetValue());
2393 return true;
2396 /*************************************************************************
2397 |* class SvxCharReliefItem
2398 *************************************************************************/
2400 SvxCharReliefItem::SvxCharReliefItem( FontRelief eValue,
2401 const sal_uInt16 nId )
2402 : SfxEnumItem( nId, eValue )
2406 SfxPoolItem* SvxCharReliefItem::Clone( SfxItemPool * ) const
2408 return new SvxCharReliefItem( *this );
2411 static const char* RID_SVXITEMS_RELIEF[] =
2413 RID_SVXITEMS_RELIEF_NONE,
2414 RID_SVXITEMS_RELIEF_EMBOSSED,
2415 RID_SVXITEMS_RELIEF_ENGRAVED
2418 OUString SvxCharReliefItem::GetValueTextByPos(sal_uInt16 nPos)
2420 assert(nPos < SAL_N_ELEMENTS(RID_SVXITEMS_RELIEF) && "enum overflow");
2421 return EditResId(RID_SVXITEMS_RELIEF[nPos]);
2424 sal_uInt16 SvxCharReliefItem::GetValueCount() const
2426 return SAL_N_ELEMENTS(RID_SVXITEMS_RELIEF) - 1;
2429 bool SvxCharReliefItem::GetPresentation
2431 SfxItemPresentation /*ePres*/,
2432 MapUnit /*eCoreUnit*/,
2433 MapUnit /*ePresUnit*/,
2434 OUString& rText, const IntlWrapper& /*rIntl*/
2435 ) const
2437 rText = GetValueTextByPos( static_cast<sal_uInt16>(GetValue()) );
2438 return true;
2441 bool SvxCharReliefItem::PutValue( const css::uno::Any& rVal,
2442 sal_uInt8 nMemberId )
2444 nMemberId &= ~CONVERT_TWIPS;
2445 bool bRet = true;
2446 switch( nMemberId )
2448 case MID_RELIEF:
2450 sal_Int16 nVal = -1;
2451 rVal >>= nVal;
2452 if(nVal >= 0 && nVal <= sal_Int16(FontRelief::Engraved))
2453 SetValue( static_cast<FontRelief>(nVal) );
2454 else
2455 bRet = false;
2457 break;
2458 default:
2459 bRet = false;
2460 break;
2462 return bRet;
2465 bool SvxCharReliefItem::QueryValue( css::uno::Any& rVal,
2466 sal_uInt8 nMemberId ) const
2468 nMemberId &= ~CONVERT_TWIPS;
2469 bool bRet = true;
2470 switch( nMemberId )
2472 case MID_RELIEF:
2473 rVal <<= static_cast<sal_Int16>(GetValue());
2474 break;
2475 default:
2476 bRet = false;
2477 break;
2479 return bRet;
2482 /*************************************************************************
2483 |* class SvxScriptSetItem
2484 *************************************************************************/
2486 SvxScriptSetItem::SvxScriptSetItem( sal_uInt16 nSlotId, SfxItemPool& rPool )
2487 : SfxSetItem( nSlotId, std::make_unique<SfxItemSet>( rPool,
2488 svl::Items<SID_ATTR_CHAR_FONT, SID_ATTR_CHAR_FONT>{} ))
2490 sal_uInt16 nLatin, nAsian, nComplex;
2491 GetWhichIds( nLatin, nAsian, nComplex );
2492 GetItemSet().MergeRange( nLatin, nLatin );
2493 GetItemSet().MergeRange( nAsian, nAsian );
2494 GetItemSet().MergeRange( nComplex, nComplex );
2497 SfxPoolItem* SvxScriptSetItem::Clone( SfxItemPool * ) const
2499 SvxScriptSetItem* p = new SvxScriptSetItem( Which(), *GetItemSet().GetPool() );
2500 p->GetItemSet().Put( GetItemSet(), false );
2501 return p;
2504 const SfxPoolItem* SvxScriptSetItem::GetItemOfScriptSet(
2505 const SfxItemSet& rSet, sal_uInt16 nId )
2507 const SfxPoolItem* pI;
2508 SfxItemState eSt = rSet.GetItemState( nId, false, &pI );
2509 if( SfxItemState::SET != eSt )
2510 pI = SfxItemState::DEFAULT == eSt ? &rSet.Get( nId ) : nullptr;
2511 return pI;
2514 const SfxPoolItem* SvxScriptSetItem::GetItemOfScript( sal_uInt16 nSlotId, const SfxItemSet& rSet, SvtScriptType nScript )
2516 sal_uInt16 nLatin, nAsian, nComplex;
2517 GetWhichIds( nSlotId, rSet, nLatin, nAsian, nComplex );
2519 const SfxPoolItem *pRet, *pAsn, *pCmplx;
2520 if (nScript == SvtScriptType::ASIAN)
2522 pRet = GetItemOfScriptSet( rSet, nAsian );
2523 } else if (nScript == SvtScriptType::COMPLEX)
2525 pRet = GetItemOfScriptSet( rSet, nComplex );
2526 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::ASIAN))
2528 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2529 nullptr == (pAsn = GetItemOfScriptSet( rSet, nAsian )) ||
2530 *pRet != *pAsn )
2531 pRet = nullptr;
2532 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::COMPLEX))
2534 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2535 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2536 *pRet != *pCmplx )
2537 pRet = nullptr;
2538 } else if (nScript == (SvtScriptType::ASIAN|SvtScriptType::COMPLEX))
2540 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nAsian )) ||
2541 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2542 *pRet != *pCmplx )
2543 pRet = nullptr;
2544 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::ASIAN|SvtScriptType::COMPLEX))
2546 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2547 nullptr == (pAsn = GetItemOfScriptSet( rSet, nAsian )) ||
2548 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2549 *pRet != *pAsn || *pRet != *pCmplx )
2550 pRet = nullptr;
2551 } else {
2552 //no one valid -> match to latin
2553 pRet = GetItemOfScriptSet( rSet, nLatin );
2555 return pRet;
2558 const SfxPoolItem* SvxScriptSetItem::GetItemOfScript( SvtScriptType nScript ) const
2560 return GetItemOfScript( Which(), GetItemSet(), nScript );
2563 void SvxScriptSetItem::PutItemForScriptType( SvtScriptType nScriptType,
2564 const SfxPoolItem& rItem )
2566 sal_uInt16 nLatin, nAsian, nComplex;
2567 GetWhichIds( nLatin, nAsian, nComplex );
2569 std::unique_ptr<SfxPoolItem> pCpy(rItem.Clone());
2570 if( SvtScriptType::LATIN & nScriptType )
2572 pCpy->SetWhich( nLatin );
2573 GetItemSet().Put( *pCpy );
2575 if( SvtScriptType::ASIAN & nScriptType )
2577 pCpy->SetWhich( nAsian );
2578 GetItemSet().Put( *pCpy );
2580 if( SvtScriptType::COMPLEX & nScriptType )
2582 pCpy->SetWhich( nComplex );
2583 GetItemSet().Put( *pCpy );
2587 void SvxScriptSetItem::GetWhichIds( sal_uInt16 nSlotId, const SfxItemSet& rSet, sal_uInt16& rLatin, sal_uInt16& rAsian, sal_uInt16& rComplex )
2589 const SfxItemPool& rPool = *rSet.GetPool();
2590 GetSlotIds( nSlotId, rLatin, rAsian, rComplex );
2591 rLatin = rPool.GetWhich( rLatin );
2592 rAsian = rPool.GetWhich( rAsian );
2593 rComplex = rPool.GetWhich( rComplex );
2596 void SvxScriptSetItem::GetWhichIds( sal_uInt16& rLatin, sal_uInt16& rAsian,
2597 sal_uInt16& rComplex ) const
2599 GetWhichIds( Which(), GetItemSet(), rLatin, rAsian, rComplex );
2602 void SvxScriptSetItem::GetSlotIds( sal_uInt16 nSlotId, sal_uInt16& rLatin,
2603 sal_uInt16& rAsian, sal_uInt16& rComplex )
2605 switch( nSlotId )
2607 default:
2608 SAL_WARN( "editeng.items", "wrong SlotId for class SvxScriptSetItem" );
2609 [[fallthrough]]; // default to font - Id Range !!
2611 case SID_ATTR_CHAR_FONT:
2612 rLatin = SID_ATTR_CHAR_FONT;
2613 rAsian = SID_ATTR_CHAR_CJK_FONT;
2614 rComplex = SID_ATTR_CHAR_CTL_FONT;
2615 break;
2616 case SID_ATTR_CHAR_FONTHEIGHT:
2617 rLatin = SID_ATTR_CHAR_FONTHEIGHT;
2618 rAsian = SID_ATTR_CHAR_CJK_FONTHEIGHT;
2619 rComplex = SID_ATTR_CHAR_CTL_FONTHEIGHT;
2620 break;
2621 case SID_ATTR_CHAR_WEIGHT:
2622 rLatin = SID_ATTR_CHAR_WEIGHT;
2623 rAsian = SID_ATTR_CHAR_CJK_WEIGHT;
2624 rComplex = SID_ATTR_CHAR_CTL_WEIGHT;
2625 break;
2626 case SID_ATTR_CHAR_POSTURE:
2627 rLatin = SID_ATTR_CHAR_POSTURE;
2628 rAsian = SID_ATTR_CHAR_CJK_POSTURE;
2629 rComplex = SID_ATTR_CHAR_CTL_POSTURE;
2630 break;
2631 case SID_ATTR_CHAR_LANGUAGE:
2632 rLatin = SID_ATTR_CHAR_LANGUAGE;
2633 rAsian = SID_ATTR_CHAR_CJK_LANGUAGE;
2634 rComplex = SID_ATTR_CHAR_CTL_LANGUAGE;
2635 break;
2636 case SID_ATTR_CHAR_SHADOWED:
2637 rLatin = SID_ATTR_CHAR_SHADOWED;
2638 rAsian = SID_ATTR_CHAR_SHADOWED;
2639 rComplex = SID_ATTR_CHAR_SHADOWED;
2640 break;
2641 case SID_ATTR_CHAR_STRIKEOUT:
2642 rLatin = SID_ATTR_CHAR_STRIKEOUT;
2643 rAsian = SID_ATTR_CHAR_STRIKEOUT;
2644 rComplex = SID_ATTR_CHAR_STRIKEOUT;
2645 break;
2649 void GetDefaultFonts( SvxFontItem& rLatin, SvxFontItem& rAsian, SvxFontItem& rComplex )
2651 const sal_uInt16 nItemCnt = 3;
2653 static struct
2655 DefaultFontType nFontType;
2656 LanguageType nLanguage;
2658 const aOutTypeArr[ nItemCnt ] =
2660 { DefaultFontType::LATIN_TEXT, LANGUAGE_ENGLISH_US },
2661 { DefaultFontType::CJK_TEXT, LANGUAGE_ENGLISH_US },
2662 { DefaultFontType::CTL_TEXT, LANGUAGE_ARABIC_SAUDI_ARABIA }
2665 SvxFontItem* aItemArr[ nItemCnt ] = { &rLatin, &rAsian, &rComplex };
2667 for ( sal_uInt16 n = 0; n < nItemCnt; ++n )
2669 vcl::Font aFont( OutputDevice::GetDefaultFont( aOutTypeArr[ n ].nFontType,
2670 aOutTypeArr[ n ].nLanguage,
2671 GetDefaultFontFlags::OnlyOne ) );
2672 SvxFontItem* pItem = aItemArr[ n ];
2673 pItem->SetFamily( aFont.GetFamilyType() );
2674 pItem->SetFamilyName( aFont.GetFamilyName() );
2675 pItem->SetStyleName( OUString() );
2676 pItem->SetPitch( aFont.GetPitch());
2677 pItem->SetCharSet(aFont.GetCharSet());
2682 bool SvxRsidItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const
2684 rVal <<= GetValue();
2685 return true;
2688 bool SvxRsidItem::PutValue( const uno::Any& rVal, sal_uInt8 )
2690 sal_uInt32 nRsid = 0;
2691 if( !( rVal >>= nRsid ) )
2692 return false;
2694 SetValue( nRsid );
2695 return true;
2698 SfxPoolItem* SvxRsidItem::Clone( SfxItemPool * ) const
2700 return new SvxRsidItem( *this );
2703 bool SvxRsidItem::GetPresentation
2705 SfxItemPresentation /*ePres*/,
2706 MapUnit /*eCoreUnit*/,
2707 MapUnit /*ePresUnit*/,
2708 OUString& rText, const IntlWrapper& /*rIntl*/
2709 ) const
2711 rText.clear();
2712 return false;
2715 void SvxRsidItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2717 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxRsidItem"));
2718 xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("whichId"), "%d", Which());
2719 xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("value"), "%" SAL_PRIuUINT32, GetValue());
2720 xmlTextWriterEndElement(pWriter);
2723 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */