bump product version to 6.3.0.0.beta1
[LibreOffice.git] / editeng / source / items / textitem.cxx
blobe4ce386c68c9deeb4813534529bd2fd3b2988954
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 = rText + OUString(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 assert(SfxPoolItem::operator==(rItem));
1044 return SfxEnumItem::operator==( static_cast<const SfxEnumItem<FontLineStyle>&>(rItem) ) &&
1045 GetColor() == static_cast<const SvxTextLineItem&>(rItem).GetColor();
1048 // class SvxUnderlineItem ------------------------------------------------
1051 SvxUnderlineItem::SvxUnderlineItem( const FontLineStyle eSt, const sal_uInt16 nId )
1052 : SvxTextLineItem( eSt, nId )
1057 SfxPoolItem* SvxUnderlineItem::Clone( SfxItemPool * ) const
1059 return new SvxUnderlineItem( *this );
1063 OUString SvxUnderlineItem::GetValueTextByPos( sal_uInt16 nPos ) const
1065 static const char* RID_SVXITEMS_UL[] =
1067 RID_SVXITEMS_UL_NONE,
1068 RID_SVXITEMS_UL_SINGLE,
1069 RID_SVXITEMS_UL_DOUBLE,
1070 RID_SVXITEMS_UL_DOTTED,
1071 RID_SVXITEMS_UL_DONTKNOW,
1072 RID_SVXITEMS_UL_DASH,
1073 RID_SVXITEMS_UL_LONGDASH,
1074 RID_SVXITEMS_UL_DASHDOT,
1075 RID_SVXITEMS_UL_DASHDOTDOT,
1076 RID_SVXITEMS_UL_SMALLWAVE,
1077 RID_SVXITEMS_UL_WAVE,
1078 RID_SVXITEMS_UL_DOUBLEWAVE,
1079 RID_SVXITEMS_UL_BOLD,
1080 RID_SVXITEMS_UL_BOLDDOTTED,
1081 RID_SVXITEMS_UL_BOLDDASH,
1082 RID_SVXITEMS_UL_BOLDLONGDASH,
1083 RID_SVXITEMS_UL_BOLDDASHDOT,
1084 RID_SVXITEMS_UL_BOLDDASHDOTDOT,
1085 RID_SVXITEMS_UL_BOLDWAVE
1087 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_UL) - 1 == LINESTYLE_BOLDWAVE, "must match");
1088 assert(nPos <= sal_uInt16(LINESTYLE_BOLDWAVE) && "enum overflow!");
1089 return EditResId(RID_SVXITEMS_UL[nPos]);
1092 // class SvxOverlineItem ------------------------------------------------
1094 SvxOverlineItem::SvxOverlineItem( const FontLineStyle eSt, const sal_uInt16 nId )
1095 : SvxTextLineItem( eSt, nId )
1100 SfxPoolItem* SvxOverlineItem::Clone( SfxItemPool * ) const
1102 return new SvxOverlineItem( *this );
1106 OUString SvxOverlineItem::GetValueTextByPos( sal_uInt16 nPos ) const
1108 static const char* RID_SVXITEMS_OL[] =
1110 RID_SVXITEMS_OL_NONE,
1111 RID_SVXITEMS_OL_SINGLE,
1112 RID_SVXITEMS_OL_DOUBLE,
1113 RID_SVXITEMS_OL_DOTTED,
1114 RID_SVXITEMS_OL_DONTKNOW,
1115 RID_SVXITEMS_OL_DASH,
1116 RID_SVXITEMS_OL_LONGDASH,
1117 RID_SVXITEMS_OL_DASHDOT,
1118 RID_SVXITEMS_OL_DASHDOTDOT,
1119 RID_SVXITEMS_OL_SMALLWAVE,
1120 RID_SVXITEMS_OL_WAVE,
1121 RID_SVXITEMS_OL_DOUBLEWAVE,
1122 RID_SVXITEMS_OL_BOLD,
1123 RID_SVXITEMS_OL_BOLDDOTTED,
1124 RID_SVXITEMS_OL_BOLDDASH,
1125 RID_SVXITEMS_OL_BOLDLONGDASH,
1126 RID_SVXITEMS_OL_BOLDDASHDOT,
1127 RID_SVXITEMS_OL_BOLDDASHDOTDOT,
1128 RID_SVXITEMS_OL_BOLDWAVE
1130 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_OL) - 1 == LINESTYLE_BOLDWAVE, "must match");
1131 assert(nPos <= sal_uInt16(LINESTYLE_BOLDWAVE) && "enum overflow!");
1132 return EditResId(RID_SVXITEMS_OL[nPos]);
1135 // class SvxCrossedOutItem -----------------------------------------------
1137 SvxCrossedOutItem::SvxCrossedOutItem( const FontStrikeout eSt, const sal_uInt16 nId )
1138 : SfxEnumItem( nId, eSt )
1143 bool SvxCrossedOutItem::HasBoolValue() const
1145 return true;
1149 bool SvxCrossedOutItem::GetBoolValue() const
1151 return GetValue() != STRIKEOUT_NONE;
1155 void SvxCrossedOutItem::SetBoolValue( bool bVal )
1157 SetValue( bVal ? STRIKEOUT_SINGLE : STRIKEOUT_NONE );
1161 sal_uInt16 SvxCrossedOutItem::GetValueCount() const
1163 return STRIKEOUT_DOUBLE + 1; // STRIKEOUT_NONE belongs also here
1167 SfxPoolItem* SvxCrossedOutItem::Clone( SfxItemPool * ) const
1169 return new SvxCrossedOutItem( *this );
1173 bool SvxCrossedOutItem::GetPresentation
1175 SfxItemPresentation /*ePres*/,
1176 MapUnit /*eCoreUnit*/,
1177 MapUnit /*ePresUnit*/,
1178 OUString& rText, const IntlWrapper& /*rIntl*/
1179 ) const
1181 rText = GetValueTextByPos( GetValue() );
1182 return true;
1185 OUString SvxCrossedOutItem::GetValueTextByPos( sal_uInt16 nPos )
1187 static const char* RID_SVXITEMS_STRIKEOUT[] =
1189 RID_SVXITEMS_STRIKEOUT_NONE,
1190 RID_SVXITEMS_STRIKEOUT_SINGLE,
1191 RID_SVXITEMS_STRIKEOUT_DOUBLE,
1192 RID_SVXITEMS_STRIKEOUT_DONTKNOW,
1193 RID_SVXITEMS_STRIKEOUT_BOLD,
1194 RID_SVXITEMS_STRIKEOUT_SLASH,
1195 RID_SVXITEMS_STRIKEOUT_X
1197 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_STRIKEOUT) - 1 == STRIKEOUT_X, "must match");
1198 assert(nPos <= sal_uInt16(STRIKEOUT_X) && "enum overflow!");
1199 return EditResId(RID_SVXITEMS_STRIKEOUT[nPos]);
1202 bool SvxCrossedOutItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1204 nMemberId &= ~CONVERT_TWIPS;
1205 switch(nMemberId)
1207 case MID_CROSSED_OUT:
1208 rVal <<= GetBoolValue();
1209 break;
1210 case MID_CROSS_OUT:
1211 rVal <<= static_cast<sal_Int16>(GetValue());
1212 break;
1214 return true;
1217 bool SvxCrossedOutItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1219 nMemberId &= ~CONVERT_TWIPS;
1220 switch(nMemberId)
1222 case MID_CROSSED_OUT:
1223 SetBoolValue(Any2Bool(rVal));
1224 break;
1225 case MID_CROSS_OUT:
1227 sal_Int32 nValue = 0;
1228 if(!(rVal >>= nValue))
1229 return false;
1230 SetValue(static_cast<FontStrikeout>(nValue));
1232 break;
1234 return true;
1236 // class SvxShadowedItem -------------------------------------------------
1238 SvxShadowedItem::SvxShadowedItem( const bool bShadowed, const sal_uInt16 nId ) :
1239 SfxBoolItem( nId, bShadowed )
1244 SfxPoolItem* SvxShadowedItem::Clone( SfxItemPool * ) const
1246 return new SvxShadowedItem( *this );
1250 bool SvxShadowedItem::GetPresentation
1252 SfxItemPresentation /*ePres*/,
1253 MapUnit /*eCoreUnit*/,
1254 MapUnit /*ePresUnit*/,
1255 OUString& rText, const IntlWrapper& /*rIntl*/
1256 ) const
1258 const char* pId = RID_SVXITEMS_SHADOWED_FALSE;
1260 if ( GetValue() )
1261 pId = RID_SVXITEMS_SHADOWED_TRUE;
1262 rText = EditResId(pId);
1263 return true;
1266 // class SvxAutoKernItem -------------------------------------------------
1268 SvxAutoKernItem::SvxAutoKernItem( const bool bAutoKern, const sal_uInt16 nId ) :
1269 SfxBoolItem( nId, bAutoKern )
1274 SfxPoolItem* SvxAutoKernItem::Clone( SfxItemPool * ) const
1276 return new SvxAutoKernItem( *this );
1280 bool SvxAutoKernItem::GetPresentation
1282 SfxItemPresentation /*ePres*/,
1283 MapUnit /*eCoreUnit*/,
1284 MapUnit /*ePresUnit*/,
1285 OUString& rText, const IntlWrapper& /*rIntl*/
1286 ) const
1288 const char* pId = RID_SVXITEMS_AUTOKERN_FALSE;
1290 if ( GetValue() )
1291 pId = RID_SVXITEMS_AUTOKERN_TRUE;
1292 rText = EditResId(pId);
1293 return true;
1296 // class SvxWordLineModeItem ---------------------------------------------
1298 SvxWordLineModeItem::SvxWordLineModeItem( const bool bWordLineMode,
1299 const sal_uInt16 nId ) :
1300 SfxBoolItem( nId, bWordLineMode )
1305 SfxPoolItem* SvxWordLineModeItem::Clone( SfxItemPool * ) const
1307 return new SvxWordLineModeItem( *this );
1311 bool SvxWordLineModeItem::GetPresentation
1313 SfxItemPresentation /*ePres*/,
1314 MapUnit /*eCoreUnit*/,
1315 MapUnit /*ePresUnit*/,
1316 OUString& rText, const IntlWrapper& /*rIntl*/
1317 ) const
1319 const char* pId = RID_SVXITEMS_WORDLINE_FALSE;
1321 if ( GetValue() )
1322 pId = RID_SVXITEMS_WORDLINE_TRUE;
1323 rText = EditResId(pId);
1324 return true;
1327 // class SvxContourItem --------------------------------------------------
1329 SvxContourItem::SvxContourItem( const bool bContoured, const sal_uInt16 nId ) :
1330 SfxBoolItem( nId, bContoured )
1335 SfxPoolItem* SvxContourItem::Clone( SfxItemPool * ) const
1337 return new SvxContourItem( *this );
1341 bool SvxContourItem::GetPresentation
1343 SfxItemPresentation /*ePres*/,
1344 MapUnit /*eCoreUnit*/,
1345 MapUnit /*ePresUnit*/,
1346 OUString& rText, const IntlWrapper& /*rIntl*/
1347 ) const
1349 const char* pId = RID_SVXITEMS_CONTOUR_FALSE;
1351 if ( GetValue() )
1352 pId = RID_SVXITEMS_CONTOUR_TRUE;
1353 rText = EditResId(pId);
1354 return true;
1357 // class SvxBackgroundColorItem -----------------------------------------
1359 SvxBackgroundColorItem::SvxBackgroundColorItem( const sal_uInt16 nId ) :
1360 SvxColorItem( nId )
1365 SvxBackgroundColorItem::SvxBackgroundColorItem( const Color& rCol,
1366 const sal_uInt16 nId ) :
1367 SvxColorItem( rCol, nId )
1371 SfxPoolItem* SvxBackgroundColorItem::Clone( SfxItemPool * ) const
1373 return new SvxBackgroundColorItem(*this);
1376 bool SvxBackgroundColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1378 nMemberId &= ~CONVERT_TWIPS;
1379 Color aColor = SvxColorItem::GetValue();
1381 switch( nMemberId )
1383 case MID_GRAPHIC_TRANSPARENT:
1385 rVal <<= aColor.GetTransparency() == 0xff;
1386 break;
1388 default:
1390 rVal <<= aColor;
1391 break;
1394 return true;
1397 bool SvxBackgroundColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1399 nMemberId &= ~CONVERT_TWIPS;
1400 sal_Int32 nColor = 0;
1401 Color aColor = SvxColorItem::GetValue();
1403 switch( nMemberId )
1405 case MID_GRAPHIC_TRANSPARENT:
1407 aColor.SetTransparency( Any2Bool( rVal ) ? 0xff : 0 );
1408 SvxColorItem::SetValue( aColor );
1409 break;
1411 default:
1413 if(!(rVal >>= nColor))
1414 return false;
1415 SvxColorItem::SetValue( Color(nColor) );
1416 break;
1419 return true;
1422 // class SvxColorItem ----------------------------------------------------
1423 SvxColorItem::SvxColorItem( const sal_uInt16 nId ) :
1424 SfxPoolItem( nId ),
1425 mColor( COL_BLACK )
1429 SvxColorItem::SvxColorItem( const Color& rCol, const sal_uInt16 nId ) :
1430 SfxPoolItem( nId ),
1431 mColor( rCol )
1435 SvxColorItem::~SvxColorItem()
1439 bool SvxColorItem::operator==( const SfxPoolItem& rAttr ) const
1441 assert(SfxPoolItem::operator==(rAttr));
1443 return mColor == static_cast<const SvxColorItem&>( rAttr ).mColor;
1446 bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
1448 rVal <<= mColor;
1449 return true;
1452 bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
1454 return (rVal >>= mColor);
1457 SfxPoolItem* SvxColorItem::Clone( SfxItemPool * ) const
1459 return new SvxColorItem( *this );
1462 bool SvxColorItem::GetPresentation
1464 SfxItemPresentation /*ePres*/,
1465 MapUnit /*eCoreUnit*/,
1466 MapUnit /*ePresUnit*/,
1467 OUString& rText, const IntlWrapper& /*rIntl*/
1468 ) const
1470 rText = ::GetColorString( mColor );
1471 return true;
1474 void SvxColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1476 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxColorItem"));
1477 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1478 OUString aStr;
1479 IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
1480 GetPresentation( SfxItemPresentation::Complete, MapUnit::Map100thMM, MapUnit::Map100thMM, aStr, aIntlWrapper);
1481 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8).getStr()));
1482 xmlTextWriterEndElement(pWriter);
1487 void SvxColorItem::SetValue( const Color& rNewCol )
1489 mColor = rNewCol;
1492 // class SvxKerningItem --------------------------------------------------
1494 SvxKerningItem::SvxKerningItem( const short nKern, const sal_uInt16 nId ) :
1495 SfxInt16Item( nId, nKern )
1500 SfxPoolItem* SvxKerningItem::Clone( SfxItemPool * ) const
1502 return new SvxKerningItem( *this );
1506 void SvxKerningItem::ScaleMetrics( long nMult, long nDiv )
1508 SetValue( static_cast<sal_Int16>(Scale( GetValue(), nMult, nDiv )) );
1512 bool SvxKerningItem::HasMetrics() const
1514 return true;
1518 bool SvxKerningItem::GetPresentation
1520 SfxItemPresentation ePres,
1521 MapUnit eCoreUnit,
1522 MapUnit /*ePresUnit*/,
1523 OUString& rText, const IntlWrapper& rIntl
1524 ) const
1526 switch ( ePres )
1528 case SfxItemPresentation::Nameless:
1529 rText = GetMetricText( static_cast<long>(GetValue()), eCoreUnit, MapUnit::MapPoint, &rIntl ) +
1530 " " + EditResId(GetMetricId(MapUnit::MapPoint));
1531 return true;
1532 case SfxItemPresentation::Complete:
1534 rText = EditResId(RID_SVXITEMS_KERNING_COMPLETE);
1535 const char* pId = nullptr;
1537 if ( GetValue() > 0 )
1538 pId = RID_SVXITEMS_KERNING_EXPANDED;
1539 else if ( GetValue() < 0 )
1540 pId = RID_SVXITEMS_KERNING_CONDENSED;
1542 if (pId)
1543 rText += EditResId(pId);
1544 rText = rText +
1545 GetMetricText( static_cast<long>(GetValue()), eCoreUnit, MapUnit::MapPoint, &rIntl ) +
1546 " " + EditResId(GetMetricId(MapUnit::MapPoint));
1547 return true;
1549 default: ; //prevent warning
1551 return false;
1554 bool SvxKerningItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1556 sal_Int16 nVal = GetValue();
1557 if(nMemberId & CONVERT_TWIPS)
1558 nVal = static_cast<sal_Int16>(convertTwipToMm100(nVal));
1559 rVal <<= nVal;
1560 return true;
1563 bool SvxKerningItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId)
1565 sal_Int16 nVal = sal_Int16();
1566 if(!(rVal >>= nVal))
1567 return false;
1568 if(nMemberId & CONVERT_TWIPS)
1569 nVal = static_cast<sal_Int16>(convertMm100ToTwip(nVal));
1570 SetValue(nVal);
1571 return true;
1574 // class SvxCaseMapItem --------------------------------------------------
1576 SvxCaseMapItem::SvxCaseMapItem( const SvxCaseMap eMap, const sal_uInt16 nId ) :
1577 SfxEnumItem( nId, eMap )
1582 sal_uInt16 SvxCaseMapItem::GetValueCount() const
1584 return sal_uInt16(SvxCaseMap::End); // SvxCaseMap::SmallCaps + 1
1588 SfxPoolItem* SvxCaseMapItem::Clone( SfxItemPool * ) const
1590 return new SvxCaseMapItem( *this );
1594 bool SvxCaseMapItem::GetPresentation
1596 SfxItemPresentation /*ePres*/,
1597 MapUnit /*eCoreUnit*/,
1598 MapUnit /*ePresUnit*/,
1599 OUString& rText, const IntlWrapper& /*rIntl*/
1600 ) const
1602 rText = GetValueTextByPos( static_cast<sal_uInt16>(GetValue()) );
1603 return true;
1606 OUString SvxCaseMapItem::GetValueTextByPos( sal_uInt16 nPos )
1608 static const char* RID_SVXITEMS_CASEMAP[] =
1610 RID_SVXITEMS_CASEMAP_NONE,
1611 RID_SVXITEMS_CASEMAP_UPPERCASE,
1612 RID_SVXITEMS_CASEMAP_LOWERCASE,
1613 RID_SVXITEMS_CASEMAP_TITLE,
1614 RID_SVXITEMS_CASEMAP_SMALLCAPS
1617 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_CASEMAP) == size_t(SvxCaseMap::End), "must match");
1618 assert(nPos < sal_uInt16(SvxCaseMap::End) && "enum overflow!");
1619 return EditResId(RID_SVXITEMS_CASEMAP[nPos]);
1622 bool SvxCaseMapItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
1624 sal_Int16 nRet = style::CaseMap::NONE;
1625 switch( GetValue() )
1627 case SvxCaseMap::Uppercase : nRet = style::CaseMap::UPPERCASE; break;
1628 case SvxCaseMap::Lowercase : nRet = style::CaseMap::LOWERCASE; break;
1629 case SvxCaseMap::Capitalize : nRet = style::CaseMap::TITLE ; break;
1630 case SvxCaseMap::SmallCaps: nRet = style::CaseMap::SMALLCAPS; break;
1631 default: break;
1633 rVal <<= nRet;
1634 return true;
1637 bool SvxCaseMapItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
1639 sal_uInt16 nVal = sal_uInt16();
1640 if(!(rVal >>= nVal))
1641 return false;
1643 SvxCaseMap eVal;
1644 switch( nVal )
1646 case style::CaseMap::NONE : eVal = SvxCaseMap::NotMapped; break;
1647 case style::CaseMap::UPPERCASE: eVal = SvxCaseMap::Uppercase; break;
1648 case style::CaseMap::LOWERCASE: eVal = SvxCaseMap::Lowercase; break;
1649 case style::CaseMap::TITLE : eVal = SvxCaseMap::Capitalize; break;
1650 case style::CaseMap::SMALLCAPS: eVal = SvxCaseMap::SmallCaps; break;
1651 default: return false;
1653 SetValue(eVal);
1654 return true;
1657 // class SvxEscapementItem -----------------------------------------------
1659 SvxEscapementItem::SvxEscapementItem( const sal_uInt16 nId ) :
1660 SfxEnumItemInterface( nId ),
1662 nEsc ( 0 ),
1663 nProp ( 100 )
1668 SvxEscapementItem::SvxEscapementItem( const SvxEscapement eEscape,
1669 const sal_uInt16 nId ) :
1670 SfxEnumItemInterface( nId ),
1671 nProp( 100 )
1673 SetEscapement( eEscape );
1674 if( nEsc )
1675 nProp = 58;
1679 SvxEscapementItem::SvxEscapementItem( const short _nEsc,
1680 const sal_uInt8 _nProp,
1681 const sal_uInt16 nId ) :
1682 SfxEnumItemInterface( nId ),
1683 nEsc ( _nEsc ),
1684 nProp ( _nProp )
1689 bool SvxEscapementItem::operator==( const SfxPoolItem& rAttr ) const
1691 assert(SfxPoolItem::operator==(rAttr));
1693 return( nEsc == static_cast<const SvxEscapementItem&>(rAttr).nEsc &&
1694 nProp == static_cast<const SvxEscapementItem&>(rAttr).nProp );
1698 SfxPoolItem* SvxEscapementItem::Clone( SfxItemPool * ) const
1700 return new SvxEscapementItem( *this );
1704 sal_uInt16 SvxEscapementItem::GetValueCount() const
1706 return sal_uInt16(SvxEscapement::End); // SvxEscapement::Subscript + 1
1710 bool SvxEscapementItem::GetPresentation
1712 SfxItemPresentation /*ePres*/,
1713 MapUnit /*eCoreUnit*/,
1714 MapUnit /*ePresUnit*/,
1715 OUString& rText, const IntlWrapper& /*rIntl*/
1716 ) const
1718 rText = GetValueTextByPos( GetEnumValue() );
1720 if ( nEsc != 0 )
1722 if( DFLT_ESC_AUTO_SUPER == nEsc || DFLT_ESC_AUTO_SUB == nEsc )
1723 rText += EditResId(RID_SVXITEMS_ESCAPEMENT_AUTO);
1724 else
1725 rText = rText + OUString::number( nEsc ) + "%";
1727 return true;
1730 OUString SvxEscapementItem::GetValueTextByPos( sal_uInt16 nPos )
1732 static const char* RID_SVXITEMS_ESCAPEMENT[] =
1734 RID_SVXITEMS_ESCAPEMENT_OFF,
1735 RID_SVXITEMS_ESCAPEMENT_SUPER,
1736 RID_SVXITEMS_ESCAPEMENT_SUB
1739 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_ESCAPEMENT) == size_t(SvxEscapement::End), "must match");
1740 assert(nPos < sal_uInt16(SvxEscapement::End) && "enum overflow!");
1741 return EditResId(RID_SVXITEMS_ESCAPEMENT[nPos]);
1744 sal_uInt16 SvxEscapementItem::GetEnumValue() const
1746 if ( nEsc < 0 )
1747 return sal_uInt16(SvxEscapement::Subscript);
1748 else if ( nEsc > 0 )
1749 return sal_uInt16(SvxEscapement::Superscript);
1750 return sal_uInt16(SvxEscapement::Off);
1754 void SvxEscapementItem::SetEnumValue( sal_uInt16 nVal )
1756 SetEscapement( static_cast<SvxEscapement>(nVal) );
1759 bool SvxEscapementItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1761 nMemberId &= ~CONVERT_TWIPS;
1762 switch(nMemberId)
1764 case MID_ESC:
1765 rVal <<= static_cast<sal_Int16>(nEsc);
1766 break;
1767 case MID_ESC_HEIGHT:
1768 rVal <<= static_cast<sal_Int8>(nProp);
1769 break;
1770 case MID_AUTO_ESC:
1771 rVal <<= (DFLT_ESC_AUTO_SUB == nEsc || DFLT_ESC_AUTO_SUPER == nEsc);
1772 break;
1774 return true;
1777 bool SvxEscapementItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1779 nMemberId &= ~CONVERT_TWIPS;
1780 switch(nMemberId)
1782 case MID_ESC:
1784 sal_Int16 nVal = sal_Int16();
1785 // tdf#120412 up to 14400% (eg. 1584 pt with 11 pt letters)
1786 if( (rVal >>= nVal) && (std::abs(nVal) <= 14400))
1787 nEsc = nVal;
1788 else
1789 return false;
1791 break;
1792 case MID_ESC_HEIGHT:
1794 sal_Int8 nVal = sal_Int8();
1795 if( (rVal >>= nVal) && (nVal <= 100))
1796 nProp = nVal;
1797 else
1798 return false;
1800 break;
1801 case MID_AUTO_ESC:
1803 bool bVal = Any2Bool(rVal);
1804 if(bVal)
1806 if(nEsc < 0)
1807 nEsc = DFLT_ESC_AUTO_SUB;
1808 else
1809 nEsc = DFLT_ESC_AUTO_SUPER;
1811 else
1812 if(DFLT_ESC_AUTO_SUPER == nEsc )
1813 --nEsc;
1814 else if(DFLT_ESC_AUTO_SUB == nEsc)
1815 ++nEsc;
1817 break;
1819 return true;
1822 // class SvxLanguageItem -------------------------------------------------
1824 SvxLanguageItem::SvxLanguageItem( const LanguageType eLang, const sal_uInt16 nId )
1825 : SvxLanguageItem_Base( nId , eLang )
1830 sal_uInt16 SvxLanguageItem::GetValueCount() const
1832 // #i50205# got rid of class International
1833 SAL_WARN( "editeng.items", "SvxLanguageItem::GetValueCount: supposed to return a count of what?");
1834 // Could be SvtLanguageTable::GetEntryCount() (all locales with resource string)?
1835 // Could be LocaleDataWrapper::getInstalledLanguageTypes() (all locales with locale data)?
1836 return 0;
1840 SfxPoolItem* SvxLanguageItem::Clone( SfxItemPool * ) const
1842 return new SvxLanguageItem( *this );
1846 bool SvxLanguageItem::GetPresentation
1848 SfxItemPresentation /*ePres*/,
1849 MapUnit /*eCoreUnit*/,
1850 MapUnit /*ePresUnit*/,
1851 OUString& rText, const IntlWrapper& /*rIntl*/
1852 ) const
1854 rText = SvtLanguageTable::GetLanguageString( GetValue() );
1855 return true;
1858 bool SvxLanguageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1860 nMemberId &= ~CONVERT_TWIPS;
1861 switch(nMemberId)
1863 case MID_LANG_INT: // for basic conversions!
1864 rVal <<= static_cast<sal_Int16>(static_cast<sal_uInt16>(GetValue()));
1865 break;
1866 case MID_LANG_LOCALE:
1867 lang::Locale aRet( LanguageTag::convertToLocale( GetValue(), false));
1868 rVal <<= aRet;
1869 break;
1871 return true;
1874 bool SvxLanguageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1876 nMemberId &= ~CONVERT_TWIPS;
1877 switch(nMemberId)
1879 case MID_LANG_INT: // for basic conversions!
1881 sal_Int32 nValue = 0;
1882 if(!(rVal >>= nValue))
1883 return false;
1885 SetValue(LanguageType(nValue));
1887 break;
1888 case MID_LANG_LOCALE:
1890 lang::Locale aLocale;
1891 if(!(rVal >>= aLocale))
1892 return false;
1894 SetValue( LanguageTag::convertToLanguageType( aLocale, false));
1896 break;
1898 return true;
1901 // class SvxNoHyphenItem -------------------------------------------------
1903 SvxNoHyphenItem::SvxNoHyphenItem( const sal_uInt16 nId ) :
1904 SfxBoolItem( nId , true )
1909 SfxPoolItem* SvxNoHyphenItem::Clone( SfxItemPool* ) const
1911 return new SvxNoHyphenItem( *this );
1915 bool SvxNoHyphenItem::GetPresentation
1917 SfxItemPresentation /*ePres*/,
1918 MapUnit /*eCoreUnit*/,
1919 MapUnit /*ePresUnit*/,
1920 OUString& rText, const IntlWrapper& /*rIntl*/
1921 ) const
1923 rText.clear();
1924 return false;
1928 * Dummy item for ToolBox controls:
1933 // class SvxBlinkItem -------------------------------------------------
1936 SvxBlinkItem::SvxBlinkItem( const bool bBlink, const sal_uInt16 nId ) :
1937 SfxBoolItem( nId, bBlink )
1942 SfxPoolItem* SvxBlinkItem::Clone( SfxItemPool * ) const
1944 return new SvxBlinkItem( *this );
1948 bool SvxBlinkItem::GetPresentation
1950 SfxItemPresentation /*ePres*/,
1951 MapUnit /*eCoreUnit*/,
1952 MapUnit /*ePresUnit*/,
1953 OUString& rText, const IntlWrapper& /*rIntl*/
1954 ) const
1956 const char* pId = RID_SVXITEMS_BLINK_FALSE;
1958 if ( GetValue() )
1959 pId = RID_SVXITEMS_BLINK_TRUE;
1960 rText = EditResId(pId);
1961 return true;
1964 // class SvxEmphaisMarkItem ---------------------------------------------------
1966 SvxEmphasisMarkItem::SvxEmphasisMarkItem( const FontEmphasisMark nValue,
1967 const sal_uInt16 nId )
1968 : SfxUInt16Item( nId, static_cast<sal_uInt16>(nValue) )
1973 SfxPoolItem* SvxEmphasisMarkItem::Clone( SfxItemPool * ) const
1975 return new SvxEmphasisMarkItem( *this );
1979 bool SvxEmphasisMarkItem::GetPresentation
1981 SfxItemPresentation /*ePres*/,
1982 MapUnit /*eCoreUnit*/,
1983 MapUnit /*ePresUnit*/,
1984 OUString& rText,
1985 const IntlWrapper& /*rIntl*/
1986 ) const
1988 static const char* RID_SVXITEMS_EMPHASIS[] =
1990 RID_SVXITEMS_EMPHASIS_NONE_STYLE,
1991 RID_SVXITEMS_EMPHASIS_DOT_STYLE,
1992 RID_SVXITEMS_EMPHASIS_CIRCLE_STYLE,
1993 RID_SVXITEMS_EMPHASIS_DISC_STYLE,
1994 RID_SVXITEMS_EMPHASIS_ACCENT_STYLE
1997 FontEmphasisMark nVal = GetEmphasisMark();
1998 rText = EditResId(RID_SVXITEMS_EMPHASIS[
1999 static_cast<sal_uInt16>(static_cast<FontEmphasisMark>( nVal & FontEmphasisMark::Style ))]);
2000 const char* pId = ( FontEmphasisMark::PosAbove & nVal )
2001 ? RID_SVXITEMS_EMPHASIS_ABOVE_POS
2002 : ( FontEmphasisMark::PosBelow & nVal )
2003 ? RID_SVXITEMS_EMPHASIS_BELOW_POS
2004 : nullptr;
2005 if( pId )
2006 rText += EditResId( pId );
2007 return true;
2010 bool SvxEmphasisMarkItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
2012 nMemberId &= ~CONVERT_TWIPS;
2013 switch( nMemberId )
2015 case MID_EMPHASIS:
2017 FontEmphasisMark nValue = GetEmphasisMark();
2018 sal_Int16 nRet = 0;
2019 switch(nValue & FontEmphasisMark::Style)
2021 case FontEmphasisMark::NONE : nRet = FontEmphasis::NONE; break;
2022 case FontEmphasisMark::Dot : nRet = FontEmphasis::DOT_ABOVE; break;
2023 case FontEmphasisMark::Circle : nRet = FontEmphasis::CIRCLE_ABOVE; break;
2024 case FontEmphasisMark::Disc : nRet = FontEmphasis::DISK_ABOVE; break;
2025 case FontEmphasisMark::Accent : nRet = FontEmphasis::ACCENT_ABOVE; break;
2026 default: break;
2028 if(nRet && nValue & FontEmphasisMark::PosBelow)
2029 nRet += 10;
2030 rVal <<= nRet;
2032 break;
2034 return true;
2037 bool SvxEmphasisMarkItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
2039 nMemberId &= ~CONVERT_TWIPS;
2040 switch( nMemberId )
2042 case MID_EMPHASIS:
2044 sal_Int32 nValue = -1;
2045 rVal >>= nValue;
2046 FontEmphasisMark nMark;
2047 switch(nValue)
2049 case FontEmphasis::NONE : nMark = FontEmphasisMark::NONE; break;
2050 case FontEmphasis::DOT_ABOVE : nMark = FontEmphasisMark::Dot|FontEmphasisMark::PosAbove; break;
2051 case FontEmphasis::CIRCLE_ABOVE: nMark = FontEmphasisMark::Circle|FontEmphasisMark::PosAbove; break;
2052 case FontEmphasis::DISK_ABOVE : nMark = FontEmphasisMark::Disc|FontEmphasisMark::PosAbove; break;
2053 case FontEmphasis::ACCENT_ABOVE: nMark = FontEmphasisMark::Accent|FontEmphasisMark::PosAbove; break;
2054 case FontEmphasis::DOT_BELOW : nMark = FontEmphasisMark::Dot|FontEmphasisMark::PosBelow; break;
2055 case FontEmphasis::CIRCLE_BELOW: nMark = FontEmphasisMark::Circle|FontEmphasisMark::PosBelow; break;
2056 case FontEmphasis::DISK_BELOW : nMark = FontEmphasisMark::Disc|FontEmphasisMark::PosBelow; break;
2057 case FontEmphasis::ACCENT_BELOW: nMark = FontEmphasisMark::Accent|FontEmphasisMark::PosBelow; break;
2058 default: return false;
2060 SetValue( static_cast<sal_Int16>(nMark) );
2062 break;
2064 return true;
2067 /*************************************************************************
2068 |* class SvxTwoLinesItem
2069 *************************************************************************/
2071 SvxTwoLinesItem::SvxTwoLinesItem( bool bFlag, sal_Unicode nStartBracket,
2072 sal_Unicode nEndBracket, sal_uInt16 nW )
2073 : SfxPoolItem( nW ),
2074 cStartBracket( nStartBracket ), cEndBracket( nEndBracket ), bOn( bFlag )
2078 SvxTwoLinesItem::~SvxTwoLinesItem()
2082 bool SvxTwoLinesItem::operator==( const SfxPoolItem& rAttr ) const
2084 assert(SfxPoolItem::operator==(rAttr));
2085 return bOn == static_cast<const SvxTwoLinesItem&>(rAttr).bOn &&
2086 cStartBracket == static_cast<const SvxTwoLinesItem&>(rAttr).cStartBracket &&
2087 cEndBracket == static_cast<const SvxTwoLinesItem&>(rAttr).cEndBracket;
2090 SfxPoolItem* SvxTwoLinesItem::Clone( SfxItemPool* ) const
2092 return new SvxTwoLinesItem( *this );
2095 bool SvxTwoLinesItem::QueryValue( css::uno::Any& rVal,
2096 sal_uInt8 nMemberId ) const
2098 nMemberId &= ~CONVERT_TWIPS;
2099 bool bRet = true;
2100 switch( nMemberId )
2102 case MID_TWOLINES:
2103 rVal <<= bOn;
2104 break;
2105 case MID_START_BRACKET:
2107 OUString s;
2108 if( cStartBracket )
2109 s = OUString( cStartBracket );
2110 rVal <<= s;
2112 break;
2113 case MID_END_BRACKET:
2115 OUString s;
2116 if( cEndBracket )
2117 s = OUString( cEndBracket );
2118 rVal <<= s;
2120 break;
2121 default:
2122 bRet = false;
2123 break;
2125 return bRet;
2128 bool SvxTwoLinesItem::PutValue( const css::uno::Any& rVal,
2129 sal_uInt8 nMemberId )
2131 nMemberId &= ~CONVERT_TWIPS;
2132 bool bRet = false;
2133 OUString s;
2134 switch( nMemberId )
2136 case MID_TWOLINES:
2137 bOn = Any2Bool( rVal );
2138 bRet = true;
2139 break;
2140 case MID_START_BRACKET:
2141 if( rVal >>= s )
2143 cStartBracket = s.isEmpty() ? 0 : s[ 0 ];
2144 bRet = true;
2146 break;
2147 case MID_END_BRACKET:
2148 if( rVal >>= s )
2150 cEndBracket = s.isEmpty() ? 0 : s[ 0 ];
2151 bRet = true;
2153 break;
2155 return bRet;
2158 bool SvxTwoLinesItem::GetPresentation( SfxItemPresentation /*ePres*/,
2159 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2160 OUString &rText, const IntlWrapper& /*rIntl*/ ) const
2162 if( !GetValue() )
2163 rText = EditResId( RID_SVXITEMS_TWOLINES_OFF );
2164 else
2166 rText = EditResId( RID_SVXITEMS_TWOLINES );
2167 if( GetStartBracket() )
2168 rText = OUStringLiteral1(GetStartBracket()) + rText;
2169 if( GetEndBracket() )
2170 rText += OUStringLiteral1(GetEndBracket());
2172 return true;
2176 /*************************************************************************
2177 |* class SvxTextRotateItem
2178 *************************************************************************/
2180 SvxTextRotateItem::SvxTextRotateItem(sal_uInt16 nValue, const sal_uInt16 nW)
2181 : SfxUInt16Item(nW, nValue)
2185 SfxPoolItem* SvxTextRotateItem::Clone(SfxItemPool*) const
2187 return new SvxTextRotateItem(*this);
2190 bool SvxTextRotateItem::GetPresentation(
2191 SfxItemPresentation /*ePres*/,
2192 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2193 OUString &rText, const IntlWrapper&) const
2195 if (!GetValue())
2196 rText = EditResId(RID_SVXITEMS_TEXTROTATE_OFF);
2197 else
2199 rText = EditResId(RID_SVXITEMS_TEXTROTATE);
2200 rText = rText.replaceFirst("$(ARG1)",
2201 OUString::number(GetValue() / 10));
2203 return true;
2206 bool SvxTextRotateItem::QueryValue(css::uno::Any& rVal,
2207 sal_uInt8 nMemberId) const
2209 nMemberId &= ~CONVERT_TWIPS;
2210 bool bRet = true;
2211 switch (nMemberId)
2213 case MID_ROTATE:
2214 rVal <<= static_cast<sal_Int16>(GetValue());
2215 break;
2216 default:
2217 bRet = false;
2218 break;
2220 return bRet;
2223 bool SvxTextRotateItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId)
2225 nMemberId &= ~CONVERT_TWIPS;
2226 bool bRet = true;
2227 switch (nMemberId)
2229 case MID_ROTATE:
2231 sal_Int16 nVal = 0;
2232 if ((rVal >>= nVal) && (0 == nVal || 900 == nVal || 2700 == nVal))
2233 SetValue(static_cast<sal_uInt16>(nVal));
2234 else
2235 bRet = false;
2236 break;
2238 default:
2239 bRet = false;
2241 return bRet;
2244 bool SvxTextRotateItem::operator==(const SfxPoolItem& rItem) const
2246 assert(SfxPoolItem::operator==(rItem));
2247 return SfxUInt16Item::operator==(rItem);
2250 void SvxTextRotateItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2252 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTextRotateItem"));
2253 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
2254 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
2255 xmlTextWriterEndElement(pWriter);
2259 /*************************************************************************
2260 |* class SvxCharRotateItem
2261 *************************************************************************/
2263 SvxCharRotateItem::SvxCharRotateItem( sal_uInt16 nValue,
2264 bool bFitIntoLine,
2265 const sal_uInt16 nW )
2266 : SvxTextRotateItem(nValue, nW), bFitToLine( bFitIntoLine )
2270 SfxPoolItem* SvxCharRotateItem::Clone( SfxItemPool* ) const
2272 return new SvxCharRotateItem( *this );
2275 bool SvxCharRotateItem::GetPresentation(
2276 SfxItemPresentation /*ePres*/,
2277 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2278 OUString &rText, const IntlWrapper&) const
2280 if( !GetValue() )
2281 rText = EditResId( RID_SVXITEMS_CHARROTATE_OFF );
2282 else
2284 rText = EditResId( RID_SVXITEMS_CHARROTATE );
2285 rText = rText.replaceFirst( "$(ARG1)",
2286 OUString::number( GetValue() / 10 ));
2287 if( IsFitToLine() )
2288 rText += EditResId( RID_SVXITEMS_CHARROTATE_FITLINE );
2290 return true;
2293 bool SvxCharRotateItem::QueryValue( css::uno::Any& rVal,
2294 sal_uInt8 nMemberId ) const
2296 bool bRet = true;
2297 switch(nMemberId & ~CONVERT_TWIPS)
2299 case MID_ROTATE:
2300 SvxTextRotateItem::QueryValue(rVal, nMemberId);
2301 break;
2302 case MID_FITTOLINE:
2303 rVal <<= IsFitToLine();
2304 break;
2305 default:
2306 bRet = false;
2307 break;
2309 return bRet;
2312 bool SvxCharRotateItem::PutValue( const css::uno::Any& rVal,
2313 sal_uInt8 nMemberId )
2315 bool bRet = true;
2316 switch(nMemberId & ~CONVERT_TWIPS)
2318 case MID_ROTATE:
2320 bRet = SvxTextRotateItem::PutValue(rVal, nMemberId);
2321 break;
2324 case MID_FITTOLINE:
2325 SetFitToLine( Any2Bool( rVal ) );
2326 break;
2327 default:
2328 bRet = false;
2330 return bRet;
2333 bool SvxCharRotateItem::operator==( const SfxPoolItem& rItem ) const
2335 assert(SfxPoolItem::operator==(rItem));
2336 return SvxTextRotateItem::operator==( rItem ) &&
2337 IsFitToLine() == static_cast<const SvxCharRotateItem&>(rItem).IsFitToLine();
2340 void SvxCharRotateItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2342 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxCharRotateItem"));
2343 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
2344 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
2345 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("fitToLine"), BAD_CAST(OString::boolean(IsFitToLine()).getStr()));
2346 xmlTextWriterEndElement(pWriter);
2349 /*************************************************************************
2350 |* class SvxCharScaleItem
2351 *************************************************************************/
2353 SvxCharScaleWidthItem::SvxCharScaleWidthItem( sal_uInt16 nValue,
2354 const sal_uInt16 nW )
2355 : SfxUInt16Item( nW, nValue )
2359 SfxPoolItem* SvxCharScaleWidthItem::Clone( SfxItemPool* ) const
2361 return new SvxCharScaleWidthItem( *this );
2365 bool SvxCharScaleWidthItem::GetPresentation(
2366 SfxItemPresentation /*ePres*/,
2367 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2368 OUString &rText, const IntlWrapper&) const
2370 if( !GetValue() )
2371 rText = EditResId( RID_SVXITEMS_CHARSCALE_OFF );
2372 else
2374 rText = EditResId( RID_SVXITEMS_CHARSCALE );
2375 rText = rText.replaceFirst( "$(ARG1)",
2376 OUString::number( GetValue() ));
2378 return true;
2381 bool SvxCharScaleWidthItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
2383 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
2384 // where we still want this to be a sal_Int16
2385 sal_Int16 nValue = sal_Int16();
2386 if (rVal >>= nValue)
2388 SetValue( static_cast<sal_uInt16>(nValue) );
2389 return true;
2392 SAL_WARN("editeng.items", "SvxCharScaleWidthItem::PutValue - Wrong type!" );
2393 return false;
2396 bool SvxCharScaleWidthItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
2398 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
2399 // where we still want this to be a sal_Int16
2400 rVal <<= static_cast<sal_Int16>(GetValue());
2401 return true;
2404 /*************************************************************************
2405 |* class SvxCharReliefItem
2406 *************************************************************************/
2408 SvxCharReliefItem::SvxCharReliefItem( FontRelief eValue,
2409 const sal_uInt16 nId )
2410 : SfxEnumItem( nId, eValue )
2414 SfxPoolItem* SvxCharReliefItem::Clone( SfxItemPool * ) const
2416 return new SvxCharReliefItem( *this );
2419 static const char* RID_SVXITEMS_RELIEF[] =
2421 RID_SVXITEMS_RELIEF_NONE,
2422 RID_SVXITEMS_RELIEF_EMBOSSED,
2423 RID_SVXITEMS_RELIEF_ENGRAVED
2426 OUString SvxCharReliefItem::GetValueTextByPos(sal_uInt16 nPos)
2428 assert(nPos < SAL_N_ELEMENTS(RID_SVXITEMS_RELIEF) && "enum overflow");
2429 return EditResId(RID_SVXITEMS_RELIEF[nPos]);
2432 sal_uInt16 SvxCharReliefItem::GetValueCount() const
2434 return SAL_N_ELEMENTS(RID_SVXITEMS_RELIEF) - 1;
2437 bool SvxCharReliefItem::GetPresentation
2439 SfxItemPresentation /*ePres*/,
2440 MapUnit /*eCoreUnit*/,
2441 MapUnit /*ePresUnit*/,
2442 OUString& rText, const IntlWrapper& /*rIntl*/
2443 ) const
2445 rText = GetValueTextByPos( static_cast<sal_uInt16>(GetValue()) );
2446 return true;
2449 bool SvxCharReliefItem::PutValue( const css::uno::Any& rVal,
2450 sal_uInt8 nMemberId )
2452 nMemberId &= ~CONVERT_TWIPS;
2453 bool bRet = true;
2454 switch( nMemberId )
2456 case MID_RELIEF:
2458 sal_Int16 nVal = -1;
2459 rVal >>= nVal;
2460 if(nVal >= 0 && nVal <= sal_Int16(FontRelief::Engraved))
2461 SetValue( static_cast<FontRelief>(nVal) );
2462 else
2463 bRet = false;
2465 break;
2466 default:
2467 bRet = false;
2468 break;
2470 return bRet;
2473 bool SvxCharReliefItem::QueryValue( css::uno::Any& rVal,
2474 sal_uInt8 nMemberId ) const
2476 nMemberId &= ~CONVERT_TWIPS;
2477 bool bRet = true;
2478 switch( nMemberId )
2480 case MID_RELIEF:
2481 rVal <<= static_cast<sal_Int16>(GetValue());
2482 break;
2483 default:
2484 bRet = false;
2485 break;
2487 return bRet;
2490 /*************************************************************************
2491 |* class SvxScriptSetItem
2492 *************************************************************************/
2494 SvxScriptSetItem::SvxScriptSetItem( sal_uInt16 nSlotId, SfxItemPool& rPool )
2495 : SfxSetItem( nSlotId, std::make_unique<SfxItemSet>( rPool,
2496 svl::Items<SID_ATTR_CHAR_FONT, SID_ATTR_CHAR_FONT>{} ))
2498 sal_uInt16 nLatin, nAsian, nComplex;
2499 GetWhichIds( nLatin, nAsian, nComplex );
2500 GetItemSet().MergeRange( nLatin, nLatin );
2501 GetItemSet().MergeRange( nAsian, nAsian );
2502 GetItemSet().MergeRange( nComplex, nComplex );
2505 SfxPoolItem* SvxScriptSetItem::Clone( SfxItemPool * ) const
2507 SvxScriptSetItem* p = new SvxScriptSetItem( Which(), *GetItemSet().GetPool() );
2508 p->GetItemSet().Put( GetItemSet(), false );
2509 return p;
2512 const SfxPoolItem* SvxScriptSetItem::GetItemOfScriptSet(
2513 const SfxItemSet& rSet, sal_uInt16 nId )
2515 const SfxPoolItem* pI;
2516 SfxItemState eSt = rSet.GetItemState( nId, false, &pI );
2517 if( SfxItemState::SET != eSt )
2518 pI = SfxItemState::DEFAULT == eSt ? &rSet.Get( nId ) : nullptr;
2519 return pI;
2522 const SfxPoolItem* SvxScriptSetItem::GetItemOfScript( sal_uInt16 nSlotId, const SfxItemSet& rSet, SvtScriptType nScript )
2524 sal_uInt16 nLatin, nAsian, nComplex;
2525 GetWhichIds( nSlotId, rSet, nLatin, nAsian, nComplex );
2527 const SfxPoolItem *pRet, *pAsn, *pCmplx;
2528 if (nScript == SvtScriptType::ASIAN)
2530 pRet = GetItemOfScriptSet( rSet, nAsian );
2531 } else if (nScript == SvtScriptType::COMPLEX)
2533 pRet = GetItemOfScriptSet( rSet, nComplex );
2534 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::ASIAN))
2536 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2537 nullptr == (pAsn = GetItemOfScriptSet( rSet, nAsian )) ||
2538 *pRet != *pAsn )
2539 pRet = nullptr;
2540 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::COMPLEX))
2542 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2543 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2544 *pRet != *pCmplx )
2545 pRet = nullptr;
2546 } else if (nScript == (SvtScriptType::ASIAN|SvtScriptType::COMPLEX))
2548 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nAsian )) ||
2549 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2550 *pRet != *pCmplx )
2551 pRet = nullptr;
2552 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::ASIAN|SvtScriptType::COMPLEX))
2554 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2555 nullptr == (pAsn = GetItemOfScriptSet( rSet, nAsian )) ||
2556 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2557 *pRet != *pAsn || *pRet != *pCmplx )
2558 pRet = nullptr;
2559 } else {
2560 //no one valid -> match to latin
2561 pRet = GetItemOfScriptSet( rSet, nLatin );
2563 return pRet;
2566 const SfxPoolItem* SvxScriptSetItem::GetItemOfScript( SvtScriptType nScript ) const
2568 return GetItemOfScript( Which(), GetItemSet(), nScript );
2571 void SvxScriptSetItem::PutItemForScriptType( SvtScriptType nScriptType,
2572 const SfxPoolItem& rItem )
2574 sal_uInt16 nLatin, nAsian, nComplex;
2575 GetWhichIds( nLatin, nAsian, nComplex );
2577 std::unique_ptr<SfxPoolItem> pCpy(rItem.Clone());
2578 if( SvtScriptType::LATIN & nScriptType )
2580 pCpy->SetWhich( nLatin );
2581 GetItemSet().Put( *pCpy );
2583 if( SvtScriptType::ASIAN & nScriptType )
2585 pCpy->SetWhich( nAsian );
2586 GetItemSet().Put( *pCpy );
2588 if( SvtScriptType::COMPLEX & nScriptType )
2590 pCpy->SetWhich( nComplex );
2591 GetItemSet().Put( *pCpy );
2595 void SvxScriptSetItem::GetWhichIds( sal_uInt16 nSlotId, const SfxItemSet& rSet, sal_uInt16& rLatin, sal_uInt16& rAsian, sal_uInt16& rComplex )
2597 const SfxItemPool& rPool = *rSet.GetPool();
2598 GetSlotIds( nSlotId, rLatin, rAsian, rComplex );
2599 rLatin = rPool.GetWhich( rLatin );
2600 rAsian = rPool.GetWhich( rAsian );
2601 rComplex = rPool.GetWhich( rComplex );
2604 void SvxScriptSetItem::GetWhichIds( sal_uInt16& rLatin, sal_uInt16& rAsian,
2605 sal_uInt16& rComplex ) const
2607 GetWhichIds( Which(), GetItemSet(), rLatin, rAsian, rComplex );
2610 void SvxScriptSetItem::GetSlotIds( sal_uInt16 nSlotId, sal_uInt16& rLatin,
2611 sal_uInt16& rAsian, sal_uInt16& rComplex )
2613 switch( nSlotId )
2615 default:
2616 SAL_WARN( "editeng.items", "wrong SlotId for class SvxScriptSetItem" );
2617 [[fallthrough]]; // default to font - Id Range !!
2619 case SID_ATTR_CHAR_FONT:
2620 rLatin = SID_ATTR_CHAR_FONT;
2621 rAsian = SID_ATTR_CHAR_CJK_FONT;
2622 rComplex = SID_ATTR_CHAR_CTL_FONT;
2623 break;
2624 case SID_ATTR_CHAR_FONTHEIGHT:
2625 rLatin = SID_ATTR_CHAR_FONTHEIGHT;
2626 rAsian = SID_ATTR_CHAR_CJK_FONTHEIGHT;
2627 rComplex = SID_ATTR_CHAR_CTL_FONTHEIGHT;
2628 break;
2629 case SID_ATTR_CHAR_WEIGHT:
2630 rLatin = SID_ATTR_CHAR_WEIGHT;
2631 rAsian = SID_ATTR_CHAR_CJK_WEIGHT;
2632 rComplex = SID_ATTR_CHAR_CTL_WEIGHT;
2633 break;
2634 case SID_ATTR_CHAR_POSTURE:
2635 rLatin = SID_ATTR_CHAR_POSTURE;
2636 rAsian = SID_ATTR_CHAR_CJK_POSTURE;
2637 rComplex = SID_ATTR_CHAR_CTL_POSTURE;
2638 break;
2639 case SID_ATTR_CHAR_LANGUAGE:
2640 rLatin = SID_ATTR_CHAR_LANGUAGE;
2641 rAsian = SID_ATTR_CHAR_CJK_LANGUAGE;
2642 rComplex = SID_ATTR_CHAR_CTL_LANGUAGE;
2643 break;
2644 case SID_ATTR_CHAR_SHADOWED:
2645 rLatin = SID_ATTR_CHAR_SHADOWED;
2646 rAsian = SID_ATTR_CHAR_SHADOWED;
2647 rComplex = SID_ATTR_CHAR_SHADOWED;
2648 break;
2649 case SID_ATTR_CHAR_STRIKEOUT:
2650 rLatin = SID_ATTR_CHAR_STRIKEOUT;
2651 rAsian = SID_ATTR_CHAR_STRIKEOUT;
2652 rComplex = SID_ATTR_CHAR_STRIKEOUT;
2653 break;
2657 void GetDefaultFonts( SvxFontItem& rLatin, SvxFontItem& rAsian, SvxFontItem& rComplex )
2659 const sal_uInt16 nItemCnt = 3;
2661 static struct
2663 DefaultFontType nFontType;
2664 LanguageType nLanguage;
2666 const aOutTypeArr[ nItemCnt ] =
2668 { DefaultFontType::LATIN_TEXT, LANGUAGE_ENGLISH_US },
2669 { DefaultFontType::CJK_TEXT, LANGUAGE_ENGLISH_US },
2670 { DefaultFontType::CTL_TEXT, LANGUAGE_ARABIC_SAUDI_ARABIA }
2673 SvxFontItem* aItemArr[ nItemCnt ] = { &rLatin, &rAsian, &rComplex };
2675 for ( sal_uInt16 n = 0; n < nItemCnt; ++n )
2677 vcl::Font aFont( OutputDevice::GetDefaultFont( aOutTypeArr[ n ].nFontType,
2678 aOutTypeArr[ n ].nLanguage,
2679 GetDefaultFontFlags::OnlyOne ) );
2680 SvxFontItem* pItem = aItemArr[ n ];
2681 pItem->SetFamily( aFont.GetFamilyType() );
2682 pItem->SetFamilyName( aFont.GetFamilyName() );
2683 pItem->SetStyleName( OUString() );
2684 pItem->SetPitch( aFont.GetPitch());
2685 pItem->SetCharSet(aFont.GetCharSet());
2690 bool SvxRsidItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const
2692 rVal <<= GetValue();
2693 return true;
2696 bool SvxRsidItem::PutValue( const uno::Any& rVal, sal_uInt8 )
2698 sal_uInt32 nRsid = 0;
2699 if( !( rVal >>= nRsid ) )
2700 return false;
2702 SetValue( nRsid );
2703 return true;
2706 SfxPoolItem* SvxRsidItem::Clone( SfxItemPool * ) const
2708 return new SvxRsidItem( *this );
2711 bool SvxRsidItem::GetPresentation
2713 SfxItemPresentation /*ePres*/,
2714 MapUnit /*eCoreUnit*/,
2715 MapUnit /*ePresUnit*/,
2716 OUString& rText, const IntlWrapper& /*rIntl*/
2717 ) const
2719 rText.clear();
2720 return false;
2723 void SvxRsidItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2725 xmlTextWriterStartElement(pWriter, BAD_CAST("SvxRsidItem"));
2726 xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("whichId"), "%d", Which());
2727 xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("value"), "%" SAL_PRIuUINT32, GetValue());
2728 xmlTextWriterEndElement(pWriter);
2731 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */