1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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 <math.h>
24 #include <sal/log.hxx>
25 #include <o3tl/safeint.hxx>
26 #include <osl/diagnose.h>
27 #include <unotools/fontdefs.hxx>
28 #include <unotools/intlwrapper.hxx>
29 #include <unotools/syslocale.hxx>
30 #include <vcl/outdev.hxx>
31 #include <vcl/unohelp.hxx>
32 #include <svtools/unitconv.hxx>
33
34 #include <editeng/editids.hrc>
35 #include <editeng/editrids.hrc>
36 #include <tools/bigint.hxx>
37 #include <tools/mapunit.hxx>
38 #include <tools/UnitConversion.hxx>
39
40 #include <rtl/math.hxx>
41 #include <rtl/ustring.hxx>
42 #include <i18nlangtag/languagetag.hxx>
43 #include <svl/itemset.hxx>
44
45 #include <svtools/langtab.hxx>
46 #include <svl/itempool.hxx>
47 #include <svtools/ctrltool.hxx>
48 #include <com/sun/star/awt/FontSlant.hpp>
49 #include <com/sun/star/lang/Locale.hpp>
50 #include <com/sun/star/text/FontEmphasis.hpp>
51 #include <editeng/rsiditem.hxx>
52 #include <editeng/memberids.h>
53 #include <editeng/flstitem.hxx>
54 #include <editeng/fontitem.hxx>
55 #include <editeng/postitem.hxx>
56 #include <editeng/wghtitem.hxx>
57 #include <editeng/fhgtitem.hxx>
58 #include <editeng/udlnitem.hxx>
59 #include <editeng/crossedoutitem.hxx>
60 #include <editeng/shdditem.hxx>
61 #include <editeng/autokernitem.hxx>
62 #include <editeng/wrlmitem.hxx>
63 #include <editeng/contouritem.hxx>
64 #include <editeng/colritem.hxx>
65 #include <editeng/kernitem.hxx>
66 #include <editeng/cmapitem.hxx>
67 #include <editeng/escapementitem.hxx>
68 #include <editeng/langitem.hxx>
69 #include <editeng/nhypitem.hxx>
70 #include <editeng/blinkitem.hxx>
71 #include <editeng/emphasismarkitem.hxx>
72 #include <editeng/twolinesitem.hxx>
73 #include <editeng/scripttypeitem.hxx>
74 #include <editeng/charrotateitem.hxx>
75 #include <editeng/charscaleitem.hxx>
76 #include <editeng/charreliefitem.hxx>
77 #include <editeng/itemtype.hxx>
78 #include <editeng/eerdll.hxx>
79 #include <libxml/xmlwriter.h>
80
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::text;
83
CreateDefault()84 SfxPoolItem* SvxFontItem::CreateDefault() {return new SvxFontItem(0);}
CreateDefault()85 SfxPoolItem* SvxPostureItem::CreateDefault() { return new SvxPostureItem(ITALIC_NONE, 0);}
CreateDefault()86 SfxPoolItem* SvxWeightItem::CreateDefault() {return new SvxWeightItem(WEIGHT_NORMAL, 0);}
CreateDefault()87 SfxPoolItem* SvxFontHeightItem::CreateDefault() {return new SvxFontHeightItem(240, 100, 0);}
CreateDefault()88 SfxPoolItem* SvxUnderlineItem::CreateDefault() {return new SvxUnderlineItem(LINESTYLE_NONE, 0);}
CreateDefault()89 SfxPoolItem* SvxOverlineItem::CreateDefault() {return new SvxOverlineItem(LINESTYLE_NONE, 0);}
CreateDefault()90 SfxPoolItem* SvxCrossedOutItem::CreateDefault() {return new SvxCrossedOutItem(STRIKEOUT_NONE, 0);}
CreateDefault()91 SfxPoolItem* SvxShadowedItem::CreateDefault() {return new SvxShadowedItem(false, 0);}
CreateDefault()92 SfxPoolItem* SvxAutoKernItem::CreateDefault() {return new SvxAutoKernItem(false, 0);}
CreateDefault()93 SfxPoolItem* SvxWordLineModeItem::CreateDefault() {return new SvxWordLineModeItem(false, 0);}
CreateDefault()94 SfxPoolItem* SvxContourItem::CreateDefault() {return new SvxContourItem(false, 0);}
CreateDefault()95 SfxPoolItem* SvxColorItem::CreateDefault() {return new SvxColorItem(0);}
CreateDefault()96 SfxPoolItem* SvxKerningItem::CreateDefault() {return new SvxKerningItem(0, 0);}
CreateDefault()97 SfxPoolItem* SvxCaseMapItem::CreateDefault() {return new SvxCaseMapItem(SvxCaseMap::NotMapped, 0);}
CreateDefault()98 SfxPoolItem* SvxEscapementItem::CreateDefault() {return new SvxEscapementItem(0);}
CreateDefault()99 SfxPoolItem* SvxLanguageItem::CreateDefault() {return new SvxLanguageItem(LANGUAGE_GERMAN, 0);}
CreateDefault()100 SfxPoolItem* SvxEmphasisMarkItem::CreateDefault() {return new SvxEmphasisMarkItem(FontEmphasisMark::NONE, 0);}
CreateDefault()101 SfxPoolItem* SvxCharRotateItem::CreateDefault() {return new SvxCharRotateItem(0_deg10, false, 0);}
CreateDefault()102 SfxPoolItem* SvxCharScaleWidthItem::CreateDefault() {return new SvxCharScaleWidthItem(100, 0);}
CreateDefault()103 SfxPoolItem* SvxCharReliefItem::CreateDefault() {return new SvxCharReliefItem(FontRelief::NONE, 0);}
104
105
106 // class SvxFontListItem -------------------------------------------------
107
SvxFontListItem(const FontList * pFontLst,const sal_uInt16 nId)108 SvxFontListItem::SvxFontListItem( const FontList* pFontLst,
109 const sal_uInt16 nId ) :
110 SfxPoolItem( nId ),
111 pFontList( pFontLst )
112 {
113 if ( pFontList )
114 {
115 sal_Int32 nCount = pFontList->GetFontNameCount();
116 aFontNameSeq.realloc( nCount );
117
118 for ( sal_Int32 i = 0; i < nCount; i++ )
119 aFontNameSeq[i] = pFontList->GetFontName(i).GetFamilyName();
120 }
121 }
122
Clone(SfxItemPool *) const123 SvxFontListItem* SvxFontListItem::Clone( SfxItemPool* ) const
124 {
125 return new SvxFontListItem( *this );
126 }
127
operator ==(const SfxPoolItem & rAttr) const128 bool SvxFontListItem::operator==( const SfxPoolItem& rAttr ) const
129 {
130 assert(SfxPoolItem::operator==(rAttr));
131
132 return( pFontList == static_cast<const SvxFontListItem&>(rAttr).pFontList );
133 }
134
QueryValue(css::uno::Any & rVal,sal_uInt8) const135 bool SvxFontListItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
136 {
137 rVal <<= aFontNameSeq;
138 return true;
139 }
140
141
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const142 bool SvxFontListItem::GetPresentation
143 (
144 SfxItemPresentation /*ePres*/,
145 MapUnit /*eCoreUnit*/,
146 MapUnit /*ePresUnit*/,
147 OUString& rText, const IntlWrapper& /*rIntl*/
148 ) const
149 {
150 rText.clear();
151 return false;
152 }
153
154 // class SvxFontItem -----------------------------------------------------
155
SvxFontItem(const sal_uInt16 nId)156 SvxFontItem::SvxFontItem( const sal_uInt16 nId ) :
157 SfxPoolItem( nId )
158 {
159 eFamily = FAMILY_SWISS;
160 ePitch = PITCH_VARIABLE;
161 eTextEncoding = RTL_TEXTENCODING_DONTKNOW;
162 }
163
164
SvxFontItem(const FontFamily eFam,const OUString & aName,const OUString & aStName,const FontPitch eFontPitch,const rtl_TextEncoding eFontTextEncoding,const sal_uInt16 nId)165 SvxFontItem::SvxFontItem( const FontFamily eFam, const OUString& aName,
166 const OUString& aStName, const FontPitch eFontPitch,
167 const rtl_TextEncoding eFontTextEncoding, const sal_uInt16 nId ) :
168
169 SfxPoolItem( nId ),
170
171 aFamilyName(aName),
172 aStyleName(aStName)
173 {
174 eFamily = eFam;
175 ePitch = eFontPitch;
176 eTextEncoding = eFontTextEncoding;
177 }
178
179
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const180 bool SvxFontItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
181 {
182 nMemberId &= ~CONVERT_TWIPS;
183 switch(nMemberId)
184 {
185 case 0:
186 {
187 css::awt::FontDescriptor aFontDescriptor;
188 aFontDescriptor.Name = aFamilyName;
189 aFontDescriptor.StyleName = aStyleName;
190 aFontDescriptor.Family = static_cast<sal_Int16>(eFamily);
191 aFontDescriptor.CharSet = static_cast<sal_Int16>(eTextEncoding);
192 aFontDescriptor.Pitch = static_cast<sal_Int16>(ePitch);
193 rVal <<= aFontDescriptor;
194 }
195 break;
196 case MID_FONT_FAMILY_NAME:
197 rVal <<= aFamilyName;
198 break;
199 case MID_FONT_STYLE_NAME:
200 rVal <<= aStyleName;
201 break;
202 case MID_FONT_FAMILY : rVal <<= static_cast<sal_Int16>(eFamily); break;
203 case MID_FONT_CHAR_SET : rVal <<= static_cast<sal_Int16>(eTextEncoding); break;
204 case MID_FONT_PITCH : rVal <<= static_cast<sal_Int16>(ePitch); break;
205 }
206 return true;
207 }
208
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)209 bool SvxFontItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId)
210 {
211 nMemberId &= ~CONVERT_TWIPS;
212 switch(nMemberId)
213 {
214 case 0:
215 {
216 css::awt::FontDescriptor aFontDescriptor;
217 if ( !( rVal >>= aFontDescriptor ))
218 return false;
219
220 aFamilyName = aFontDescriptor.Name;
221 aStyleName = aFontDescriptor.StyleName;
222 eFamily = static_cast<FontFamily>(aFontDescriptor.Family);
223 eTextEncoding = static_cast<rtl_TextEncoding>(aFontDescriptor.CharSet);
224 ePitch = static_cast<FontPitch>(aFontDescriptor.Pitch);
225 }
226 break;
227 case MID_FONT_FAMILY_NAME :
228 {
229 OUString aStr;
230 if(!(rVal >>= aStr))
231 return false;
232 aFamilyName = aStr;
233 }
234 break;
235 case MID_FONT_STYLE_NAME:
236 {
237 OUString aStr;
238 if(!(rVal >>= aStr))
239 return false;
240 aStyleName = aStr;
241 }
242 break;
243 case MID_FONT_FAMILY :
244 {
245 sal_Int16 nFamily = sal_Int16();
246 if(!(rVal >>= nFamily))
247 return false;
248 eFamily = static_cast<FontFamily>(nFamily);
249 }
250 break;
251 case MID_FONT_CHAR_SET :
252 {
253 sal_Int16 nSet = sal_Int16();
254 if(!(rVal >>= nSet))
255 return false;
256 eTextEncoding = static_cast<rtl_TextEncoding>(nSet);
257 }
258 break;
259 case MID_FONT_PITCH :
260 {
261 sal_Int16 nPitch = sal_Int16();
262 if(!(rVal >>= nPitch))
263 return false;
264 ePitch = static_cast<FontPitch>(nPitch);
265 }
266 break;
267 }
268 return true;
269 }
270
271
operator ==(const SfxPoolItem & rAttr) const272 bool SvxFontItem::operator==( const SfxPoolItem& rAttr ) const
273 {
274 assert(SfxPoolItem::operator==(rAttr));
275
276 const SvxFontItem& rItem = static_cast<const SvxFontItem&>(rAttr);
277
278 bool bRet = ( eFamily == rItem.eFamily &&
279 aFamilyName == rItem.aFamilyName &&
280 aStyleName == rItem.aStyleName );
281
282 if ( bRet )
283 {
284 if ( ePitch != rItem.ePitch || eTextEncoding != rItem.eTextEncoding )
285 {
286 bRet = false;
287 SAL_INFO( "editeng.items", "FontItem::operator==(): only pitch or rtl_TextEncoding different ");
288 }
289 }
290 return bRet;
291 }
292
Clone(SfxItemPool *) const293 SvxFontItem* SvxFontItem::Clone( SfxItemPool * ) const
294 {
295 return new SvxFontItem( *this );
296 }
297
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const298 bool SvxFontItem::GetPresentation
299 (
300 SfxItemPresentation /*ePres*/,
301 MapUnit /*eCoreUnit*/,
302 MapUnit /*ePresUnit*/,
303 OUString& rText, const IntlWrapper& /*rIntl*/
304 ) const
305 {
306 rText = aFamilyName;
307 return true;
308 }
309
310
dumpAsXml(xmlTextWriterPtr pWriter) const311 void SvxFontItem::dumpAsXml(xmlTextWriterPtr pWriter) const
312 {
313 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFontItem"));
314 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
315 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("familyName"), BAD_CAST(aFamilyName.toUtf8().getStr()));
316 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("styleName"), BAD_CAST(aStyleName.toUtf8().getStr()));
317 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("family"), BAD_CAST(OString::number(eFamily).getStr()));
318 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("pitch"), BAD_CAST(OString::number(ePitch).getStr()));
319 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("textEncoding"), BAD_CAST(OString::number(eTextEncoding).getStr()));
320 (void)xmlTextWriterEndElement(pWriter);
321 }
322
323 // class SvxPostureItem --------------------------------------------------
324
SvxPostureItem(const FontItalic ePosture,const sal_uInt16 nId)325 SvxPostureItem::SvxPostureItem( const FontItalic ePosture, const sal_uInt16 nId ) :
326 SfxEnumItem( nId, ePosture )
327 {
328 }
329
Clone(SfxItemPool *) const330 SvxPostureItem* SvxPostureItem::Clone( SfxItemPool * ) const
331 {
332 return new SvxPostureItem( *this );
333 }
334
GetValueCount() const335 sal_uInt16 SvxPostureItem::GetValueCount() const
336 {
337 return ITALIC_NORMAL + 1; // ITALIC_NONE also belongs here
338 }
339
340
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const341 bool SvxPostureItem::GetPresentation
342 (
343 SfxItemPresentation /*ePres*/,
344 MapUnit /*eCoreUnit*/,
345 MapUnit /*ePresUnit*/,
346 OUString& rText, const IntlWrapper& /*rIntl*/
347 ) const
348 {
349 rText = GetValueTextByPos( GetValue() );
350 return true;
351 }
352
353
GetValueTextByPos(sal_uInt16 nPos)354 OUString SvxPostureItem::GetValueTextByPos( sal_uInt16 nPos )
355 {
356 DBG_ASSERT( nPos <= sal_uInt16(ITALIC_NORMAL), "enum overflow!" );
357
358 FontItalic eItalic = static_cast<FontItalic>(nPos);
359 const char* pId = nullptr;
360
361 switch ( eItalic )
362 {
363 case ITALIC_NONE: pId = RID_SVXITEMS_ITALIC_NONE; break;
364 case ITALIC_OBLIQUE: pId = RID_SVXITEMS_ITALIC_OBLIQUE; break;
365 case ITALIC_NORMAL: pId = RID_SVXITEMS_ITALIC_NORMAL; break;
366 default: ;//prevent warning
367 }
368
369 return pId ? EditResId(pId) : OUString();
370 }
371
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const372 bool SvxPostureItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
373 {
374 nMemberId &= ~CONVERT_TWIPS;
375 switch( nMemberId )
376 {
377 case MID_ITALIC:
378 rVal <<= GetBoolValue();
379 break;
380 case MID_POSTURE:
381 rVal <<= vcl::unohelper::ConvertFontSlant(GetValue());
382 break;
383 }
384 return true;
385 }
386
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)387 bool SvxPostureItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
388 {
389 nMemberId &= ~CONVERT_TWIPS;
390 switch( nMemberId )
391 {
392 case MID_ITALIC:
393 SetBoolValue(Any2Bool(rVal));
394 break;
395 case MID_POSTURE:
396 {
397 awt::FontSlant eSlant;
398 if(!(rVal >>= eSlant))
399 {
400 sal_Int32 nValue = 0;
401 if(!(rVal >>= nValue))
402 return false;
403
404 eSlant = static_cast<awt::FontSlant>(nValue);
405 }
406 SetValue(vcl::unohelper::ConvertFontSlant(eSlant));
407 }
408 }
409 return true;
410 }
411
HasBoolValue() const412 bool SvxPostureItem::HasBoolValue() const
413 {
414 return true;
415 }
416
GetBoolValue() const417 bool SvxPostureItem::GetBoolValue() const
418 {
419 return ( GetValue() >= ITALIC_OBLIQUE );
420 }
421
SetBoolValue(bool bVal)422 void SvxPostureItem::SetBoolValue( bool bVal )
423 {
424 SetValue( bVal ? ITALIC_NORMAL : ITALIC_NONE );
425 }
426
dumpAsXml(xmlTextWriterPtr pWriter) const427 void SvxPostureItem::dumpAsXml(xmlTextWriterPtr pWriter) const
428 {
429 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxPostureItem"));
430 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("whichId"), "%d", Which());
431 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("value"), "%d", GetValue());
432 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(GetValueTextByPos(GetValue()).toUtf8().getStr()));
433 (void)xmlTextWriterEndElement(pWriter);
434 }
435
436 // class SvxWeightItem ---------------------------------------------------
437
SvxWeightItem(const FontWeight eWght,const sal_uInt16 nId)438 SvxWeightItem::SvxWeightItem( const FontWeight eWght, const sal_uInt16 nId ) :
439 SfxEnumItem( nId, eWght )
440 {
441 }
442
443
HasBoolValue() const444 bool SvxWeightItem::HasBoolValue() const
445 {
446 return true;
447 }
448
449
GetBoolValue() const450 bool SvxWeightItem::GetBoolValue() const
451 {
452 return GetValue() >= WEIGHT_BOLD;
453 }
454
455
SetBoolValue(bool bVal)456 void SvxWeightItem::SetBoolValue( bool bVal )
457 {
458 SetValue( bVal ? WEIGHT_BOLD : WEIGHT_NORMAL );
459 }
460
461
GetValueCount() const462 sal_uInt16 SvxWeightItem::GetValueCount() const
463 {
464 return WEIGHT_BLACK; // WEIGHT_DONTKNOW does not belong
465 }
466
Clone(SfxItemPool *) const467 SvxWeightItem* SvxWeightItem::Clone( SfxItemPool * ) const
468 {
469 return new SvxWeightItem( *this );
470 }
471
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const472 bool SvxWeightItem::GetPresentation
473 (
474 SfxItemPresentation /*ePres*/,
475 MapUnit /*eCoreUnit*/,
476 MapUnit /*ePresUnit*/,
477 OUString& rText, const IntlWrapper& /*rIntl*/
478 ) const
479 {
480 rText = GetValueTextByPos( GetValue() );
481 return true;
482 }
483
GetValueTextByPos(sal_uInt16 nPos)484 OUString SvxWeightItem::GetValueTextByPos( sal_uInt16 nPos )
485 {
486 static const char* RID_SVXITEMS_WEIGHTS[] =
487 {
488 RID_SVXITEMS_WEIGHT_DONTKNOW,
489 RID_SVXITEMS_WEIGHT_THIN,
490 RID_SVXITEMS_WEIGHT_ULTRALIGHT,
491 RID_SVXITEMS_WEIGHT_LIGHT,
492 RID_SVXITEMS_WEIGHT_SEMILIGHT,
493 RID_SVXITEMS_WEIGHT_NORMAL,
494 RID_SVXITEMS_WEIGHT_MEDIUM,
495 RID_SVXITEMS_WEIGHT_SEMIBOLD,
496 RID_SVXITEMS_WEIGHT_BOLD,
497 RID_SVXITEMS_WEIGHT_ULTRABOLD,
498 RID_SVXITEMS_WEIGHT_BLACK
499 };
500
501 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_WEIGHTS) - 1 == WEIGHT_BLACK, "must match");
502 assert(nPos <= sal_uInt16(WEIGHT_BLACK) && "enum overflow!" );
503 return EditResId(RID_SVXITEMS_WEIGHTS[nPos]);
504 }
505
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const506 bool SvxWeightItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
507 {
508 nMemberId &= ~CONVERT_TWIPS;
509 switch( nMemberId )
510 {
511 case MID_BOLD :
512 rVal <<= GetBoolValue();
513 break;
514 case MID_WEIGHT:
515 {
516 rVal <<= vcl::unohelper::ConvertFontWeight( GetValue() );
517 }
518 break;
519 }
520 return true;
521 }
522
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)523 bool SvxWeightItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
524 {
525 nMemberId &= ~CONVERT_TWIPS;
526 switch( nMemberId )
527 {
528 case MID_BOLD :
529 SetBoolValue(Any2Bool(rVal));
530 break;
531 case MID_WEIGHT:
532 {
533 double fValue = 0;
534 if(!(rVal >>= fValue))
535 {
536 sal_Int32 nValue = 0;
537 if(!(rVal >>= nValue))
538 return false;
539 fValue = static_cast<float>(nValue);
540 }
541 SetValue( vcl::unohelper::ConvertFontWeight(static_cast<float>(fValue)) );
542 }
543 break;
544 }
545 return true;
546 }
547
dumpAsXml(xmlTextWriterPtr pWriter) const548 void SvxWeightItem::dumpAsXml(xmlTextWriterPtr pWriter) const
549 {
550 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxWeightItem"));
551 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("whichId"), "%d", Which());
552 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("value"), "%d", GetValue());
553 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(GetValueTextByPos(GetValue()).toUtf8().getStr()));
554 (void)xmlTextWriterEndElement(pWriter);
555 }
556
557 // class SvxFontHeightItem -----------------------------------------------
558
SvxFontHeightItem(const sal_uInt32 nSz,const sal_uInt16 nPrp,const sal_uInt16 nId)559 SvxFontHeightItem::SvxFontHeightItem( const sal_uInt32 nSz,
560 const sal_uInt16 nPrp,
561 const sal_uInt16 nId ) :
562 SfxPoolItem( nId )
563 {
564 SetHeight( nSz,nPrp ); // calculate in percentage
565 }
566
Clone(SfxItemPool *) const567 SvxFontHeightItem* SvxFontHeightItem::Clone( SfxItemPool * ) const
568 {
569 return new SvxFontHeightItem( *this );
570 }
571
operator ==(const SfxPoolItem & rItem) const572 bool SvxFontHeightItem::operator==( const SfxPoolItem& rItem ) const
573 {
574 assert(SfxPoolItem::operator==(rItem));
575 return GetHeight() == static_cast<const SvxFontHeightItem&>(rItem).GetHeight() &&
576 GetProp() == static_cast<const SvxFontHeightItem&>(rItem).GetProp() &&
577 GetPropUnit() == static_cast<const SvxFontHeightItem&>(rItem).GetPropUnit();
578 }
579
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const580 bool SvxFontHeightItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
581 {
582 // In StarOne is the uno::Any always 1/100mm. Through the MemberId it is
583 // controlled if the value in the Item should be 1/100mm or Twips.
584
585 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
586 nMemberId &= ~CONVERT_TWIPS;
587 switch( nMemberId )
588 {
589 case 0:
590 {
591 css::frame::status::FontHeight aFontHeight;
592
593 // Point (i.e. Twips) is asked for, thus re-calculate if
594 // CONVERT_TWIPS is not set.
595 if( bConvert )
596 {
597 aFontHeight.Height = static_cast<float>( nHeight / 20.0 );
598 }
599 else
600 {
601 double fPoints = convertMm100ToTwip(nHeight) / 20.0;
602 float fRoundPoints =
603 static_cast<float>(::rtl::math::round(fPoints, 1));
604 aFontHeight.Height = fRoundPoints;
605 }
606
607 aFontHeight.Prop = static_cast<sal_Int16>(MapUnit::MapRelative == ePropUnit ? nProp : 100);
608
609 float fRet = static_cast<float>(static_cast<short>(nProp));
610 switch( ePropUnit )
611 {
612 case MapUnit::MapRelative:
613 fRet = 0.;
614 break;
615 case MapUnit::Map100thMM:
616 fRet = convertMm100ToTwip(fRet);
617 fRet /= 20.;
618 break;
619 case MapUnit::MapPoint:
620
621 break;
622 case MapUnit::MapTwip:
623 fRet /= 20.;
624 break;
625 default: ;//prevent warning
626 }
627 aFontHeight.Diff = fRet;
628 rVal <<= aFontHeight;
629 }
630 break;
631 case MID_FONTHEIGHT:
632 {
633 // Point (i.e. Twips) is asked for, thus re-calculate if
634 // CONVERT_TWIPS is not set.
635 if( bConvert )
636 {
637 rVal <<= static_cast<float>( nHeight / 20.0 );
638 }
639 else
640 {
641 double fPoints = convertMm100ToTwip(nHeight) / 20.0;
642 float fRoundPoints =
643 static_cast<float>(::rtl::math::round(fPoints, 1));
644 rVal <<= fRoundPoints;
645 }
646 }
647 break;
648 case MID_FONTHEIGHT_PROP:
649 rVal <<= static_cast<sal_Int16>(MapUnit::MapRelative == ePropUnit ? nProp : 100);
650 break;
651 case MID_FONTHEIGHT_DIFF:
652 {
653 float fRet = static_cast<float>(static_cast<short>(nProp));
654 switch( ePropUnit )
655 {
656 case MapUnit::MapRelative:
657 fRet = 0.;
658 break;
659 case MapUnit::Map100thMM:
660 fRet = convertMm100ToTwip(fRet);
661 fRet /= 20.;
662 break;
663 case MapUnit::MapPoint:
664
665 break;
666 case MapUnit::MapTwip:
667 fRet /= 20.;
668 break;
669 default: ;//prevent warning
670 }
671 rVal <<= fRet;
672 }
673 break;
674 }
675 return true;
676 }
677
678 // Try to reconstruct the original height input value from the modified height
679 // and the prop data; this seems somewhat futile given the various ways how the
680 // modified height is calculated (with and without conversion between twips and
681 // 100th mm; with an additional eCoreMetric input in one of the SetHeight
682 // overloads), and indeed known to occasionally produce nRet values that would
683 // be negative, so just guard against negative results here and throw the hands
684 // up in despair:
lcl_GetRealHeight_Impl(sal_uInt32 nHeight,sal_uInt16 nProp,MapUnit eProp,bool bCoreInTwip)685 static sal_uInt32 lcl_GetRealHeight_Impl(sal_uInt32 nHeight, sal_uInt16 nProp, MapUnit eProp, bool bCoreInTwip)
686 {
687 sal_uInt32 nRet = nHeight;
688 short nDiff = 0;
689 switch( eProp )
690 {
691 case MapUnit::MapRelative:
692 if (nProp)
693 {
694 nRet *= 100;
695 nRet /= nProp;
696 }
697 break;
698 case MapUnit::MapPoint:
699 {
700 short nTemp = static_cast<short>(nProp);
701 nDiff = nTemp * 20;
702 if(!bCoreInTwip)
703 nDiff = static_cast<short>(convertTwipToMm100(static_cast<tools::Long>(nDiff)));
704 break;
705 }
706 case MapUnit::Map100thMM:
707 //then the core is surely also in 1/100 mm
708 nDiff = static_cast<short>(nProp);
709 break;
710 case MapUnit::MapTwip:
711 // Here surely TWIP
712 nDiff = static_cast<short>(nProp);
713 break;
714 default:
715 break;
716 }
717 nRet = (nDiff < 0 || nRet >= o3tl::make_unsigned(nDiff))
718 ? nRet - nDiff : 0;
719 //TODO: overflow in case nDiff < 0 and nRet - nDiff > SAL_MAX_UINT32
720
721 return nRet;
722 }
723
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)724 bool SvxFontHeightItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
725 {
726 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
727 nMemberId &= ~CONVERT_TWIPS;
728 switch( nMemberId )
729 {
730 case 0:
731 {
732 css::frame::status::FontHeight aFontHeight;
733 if ( rVal >>= aFontHeight )
734 {
735 // Height
736 ePropUnit = MapUnit::MapRelative;
737 nProp = 100;
738 double fPoint = aFontHeight.Height;
739 if( fPoint < 0. || fPoint > 10000. )
740 return false;
741
742 nHeight = static_cast<tools::Long>( fPoint * 20.0 + 0.5 ); // Twips
743 if (!bConvert)
744 nHeight = convertTwipToMm100(nHeight); // Convert, if the item contains 1/100mm
745
746 nProp = aFontHeight.Prop;
747 }
748 else
749 return false;
750 }
751 break;
752 case MID_FONTHEIGHT:
753 {
754 ePropUnit = MapUnit::MapRelative;
755 nProp = 100;
756 double fPoint = 0;
757 if(!(rVal >>= fPoint))
758 {
759 sal_Int32 nValue = 0;
760 if(!(rVal >>= nValue))
761 return false;
762 fPoint = static_cast<float>(nValue);
763 }
764 if(fPoint < 0. || fPoint > 10000.)
765 return false;
766
767 nHeight = static_cast<tools::Long>( fPoint * 20.0 + 0.5 ); // Twips
768 if (!bConvert)
769 nHeight = convertTwipToMm100(nHeight); // Convert, if the item contains 1/100mm
770 }
771 break;
772 case MID_FONTHEIGHT_PROP:
773 {
774 sal_Int16 nNew = sal_Int16();
775 if(!(rVal >>= nNew))
776 return true;
777
778 nHeight = lcl_GetRealHeight_Impl(nHeight, nProp, ePropUnit, bConvert);
779
780 nHeight *= nNew;
781 nHeight /= 100;
782 nProp = nNew;
783 ePropUnit = MapUnit::MapRelative;
784 }
785 break;
786 case MID_FONTHEIGHT_DIFF:
787 {
788 nHeight = lcl_GetRealHeight_Impl(nHeight, nProp, ePropUnit, bConvert);
789 float fValue = 0;
790 if(!(rVal >>= fValue))
791 {
792 sal_Int32 nValue = 0;
793 if(!(rVal >>= nValue))
794 return false;
795 fValue = static_cast<float>(nValue);
796 }
797 sal_Int16 nCoreDiffValue = static_cast<sal_Int16>(fValue * 20.);
798 nHeight += bConvert ? nCoreDiffValue : convertTwipToMm100(nCoreDiffValue);
799 nProp = static_cast<sal_uInt16>(static_cast<sal_Int16>(fValue));
800 ePropUnit = MapUnit::MapPoint;
801 }
802 break;
803 }
804 return true;
805 }
806
807
GetPresentation(SfxItemPresentation,MapUnit eCoreUnit,MapUnit,OUString & rText,const IntlWrapper & rIntl) const808 bool SvxFontHeightItem::GetPresentation
809 (
810 SfxItemPresentation /*ePres*/,
811 MapUnit eCoreUnit,
812 MapUnit /*ePresUnit*/,
813 OUString& rText, const IntlWrapper& rIntl
814 ) const
815 {
816 if( MapUnit::MapRelative != ePropUnit )
817 {
818 rText = OUString::number( static_cast<short>(nProp) ) +
819 " " + EditResId( GetMetricId( ePropUnit ) );
820 if( 0 <= static_cast<short>(nProp) )
821 rText = "+" + rText;
822 }
823 else if( 100 == nProp )
824 {
825 rText = GetMetricText( static_cast<tools::Long>(nHeight),
826 eCoreUnit, MapUnit::MapPoint, &rIntl ) +
827 " " + EditResId(GetMetricId(MapUnit::MapPoint));
828 }
829 else
830 rText = OUString::number( nProp ) + "%";
831 return true;
832 }
833
834
ScaleMetrics(tools::Long nMult,tools::Long nDiv)835 void SvxFontHeightItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
836 {
837 nHeight = static_cast<sal_uInt32>(BigInt::Scale( nHeight, nMult, nDiv ));
838 }
839
840
HasMetrics() const841 bool SvxFontHeightItem::HasMetrics() const
842 {
843 return true;
844 }
845
SetHeight(sal_uInt32 nNewHeight,const sal_uInt16 nNewProp,MapUnit eUnit)846 void SvxFontHeightItem::SetHeight( sal_uInt32 nNewHeight, const sal_uInt16 nNewProp,
847 MapUnit eUnit )
848 {
849 DBG_ASSERT( GetRefCount() == 0, "SetValue() with pooled item" );
850
851 if( MapUnit::MapRelative != eUnit )
852 nHeight = nNewHeight + ::ItemToControl( short(nNewProp), eUnit,
853 FieldUnit::TWIP );
854 else if( 100 != nNewProp )
855 nHeight = sal_uInt32(( nNewHeight * nNewProp ) / 100 );
856 else
857 nHeight = nNewHeight;
858
859 nProp = nNewProp;
860 ePropUnit = eUnit;
861 }
862
SetHeight(sal_uInt32 nNewHeight,sal_uInt16 nNewProp,MapUnit eMetric,MapUnit eCoreMetric)863 void SvxFontHeightItem::SetHeight( sal_uInt32 nNewHeight, sal_uInt16 nNewProp,
864 MapUnit eMetric, MapUnit eCoreMetric )
865 {
866 DBG_ASSERT( GetRefCount() == 0, "SetValue() with pooled item" );
867
868 if( MapUnit::MapRelative != eMetric )
869 nHeight = nNewHeight +
870 ::ControlToItem( ::ItemToControl(static_cast<short>(nNewProp), eMetric,
871 FieldUnit::TWIP ), FieldUnit::TWIP,
872 eCoreMetric );
873 else if( 100 != nNewProp )
874 nHeight = sal_uInt32(( nNewHeight * nNewProp ) / 100 );
875 else
876 nHeight = nNewHeight;
877
878 nProp = nNewProp;
879 ePropUnit = eMetric;
880 }
881
dumpAsXml(xmlTextWriterPtr pWriter) const882 void SvxFontHeightItem::dumpAsXml(xmlTextWriterPtr pWriter) const
883 {
884 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFontHeightItem"));
885 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
886 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("height"), BAD_CAST(OString::number(nHeight).getStr()));
887 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("prop"), BAD_CAST(OString::number(nProp).getStr()));
888 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("propUnit"), BAD_CAST(OString::number(static_cast<int>(ePropUnit)).getStr()));
889 (void)xmlTextWriterEndElement(pWriter);
890 }
891
892 // class SvxTextLineItem ------------------------------------------------
893
SvxTextLineItem(const FontLineStyle eSt,const sal_uInt16 nId)894 SvxTextLineItem::SvxTextLineItem( const FontLineStyle eSt, const sal_uInt16 nId )
895 : SfxEnumItem( nId, eSt ), mColor( COL_TRANSPARENT )
896 {
897 }
898
899
HasBoolValue() const900 bool SvxTextLineItem::HasBoolValue() const
901 {
902 return true;
903 }
904
905
GetBoolValue() const906 bool SvxTextLineItem::GetBoolValue() const
907 {
908 return GetValue() != LINESTYLE_NONE;
909 }
910
911
SetBoolValue(bool bVal)912 void SvxTextLineItem::SetBoolValue( bool bVal )
913 {
914 SetValue( bVal ? LINESTYLE_SINGLE : LINESTYLE_NONE );
915 }
916
Clone(SfxItemPool *) const917 SvxTextLineItem* SvxTextLineItem::Clone( SfxItemPool * ) const
918 {
919 return new SvxTextLineItem( *this );
920 }
921
GetValueCount() const922 sal_uInt16 SvxTextLineItem::GetValueCount() const
923 {
924 return LINESTYLE_DOTTED + 1; // LINESTYLE_NONE also belongs here
925 }
926
927
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const928 bool SvxTextLineItem::GetPresentation
929 (
930 SfxItemPresentation /*ePres*/,
931 MapUnit /*eCoreUnit*/,
932 MapUnit /*ePresUnit*/,
933 OUString& rText, const IntlWrapper& /*rIntl*/
934 ) const
935 {
936 rText = GetValueTextByPos( GetValue() );
937 if( !mColor.IsTransparent() )
938 rText += cpDelim + ::GetColorString( mColor );
939 return true;
940 }
941
942
GetValueTextByPos(sal_uInt16) const943 OUString SvxTextLineItem::GetValueTextByPos( sal_uInt16 /*nPos*/ ) const
944 {
945 OSL_FAIL("SvxTextLineItem::GetValueTextByPos: Pure virtual method");
946 return OUString();
947 }
948
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const949 bool SvxTextLineItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
950 {
951 nMemberId &= ~CONVERT_TWIPS;
952 switch(nMemberId)
953 {
954 case MID_TEXTLINED:
955 rVal <<= GetBoolValue();
956 break;
957 case MID_TL_STYLE:
958 rVal <<= static_cast<sal_Int16>(GetValue());
959 break;
960 case MID_TL_COLOR:
961 rVal <<= mColor;
962 break;
963 case MID_TL_HASCOLOR:
964 rVal <<= mColor.GetAlpha() == 255;
965 break;
966 }
967 return true;
968
969 }
970
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)971 bool SvxTextLineItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
972 {
973 nMemberId &= ~CONVERT_TWIPS;
974 bool bRet = true;
975 switch(nMemberId)
976 {
977 case MID_TEXTLINED:
978 SetBoolValue(Any2Bool(rVal));
979 break;
980 case MID_TL_STYLE:
981 {
982 sal_Int32 nValue = 0;
983 if(!(rVal >>= nValue))
984 bRet = false;
985 else
986 SetValue(static_cast<FontLineStyle>(nValue));
987 }
988 break;
989 case MID_TL_COLOR:
990 {
991 Color nCol;
992 if( !( rVal >>= nCol ) )
993 bRet = false;
994 else
995 {
996 // Keep transparence, because it contains the information
997 // whether the font color or the stored color should be used
998 sal_uInt8 nAlpha = mColor.GetAlpha();
999 mColor = nCol;
1000 mColor.SetAlpha( nAlpha );
1001 }
1002 }
1003 break;
1004 case MID_TL_HASCOLOR:
1005 mColor.SetAlpha( Any2Bool( rVal ) ? 255 : 0 );
1006 break;
1007 }
1008 return bRet;
1009 }
1010
operator ==(const SfxPoolItem & rItem) const1011 bool SvxTextLineItem::operator==( const SfxPoolItem& rItem ) const
1012 {
1013 return SfxEnumItem::operator==( rItem ) &&
1014 GetColor() == static_cast<const SvxTextLineItem&>(rItem).GetColor();
1015 }
1016
1017 // class SvxUnderlineItem ------------------------------------------------
1018
1019
SvxUnderlineItem(const FontLineStyle eSt,const sal_uInt16 nId)1020 SvxUnderlineItem::SvxUnderlineItem( const FontLineStyle eSt, const sal_uInt16 nId )
1021 : SvxTextLineItem( eSt, nId )
1022 {
1023 }
1024
Clone(SfxItemPool *) const1025 SvxUnderlineItem* SvxUnderlineItem::Clone( SfxItemPool * ) const
1026 {
1027 return new SvxUnderlineItem( *this );
1028 }
1029
GetValueTextByPos(sal_uInt16 nPos) const1030 OUString SvxUnderlineItem::GetValueTextByPos( sal_uInt16 nPos ) const
1031 {
1032 static const char* RID_SVXITEMS_UL[] =
1033 {
1034 RID_SVXITEMS_UL_NONE,
1035 RID_SVXITEMS_UL_SINGLE,
1036 RID_SVXITEMS_UL_DOUBLE,
1037 RID_SVXITEMS_UL_DOTTED,
1038 RID_SVXITEMS_UL_DONTKNOW,
1039 RID_SVXITEMS_UL_DASH,
1040 RID_SVXITEMS_UL_LONGDASH,
1041 RID_SVXITEMS_UL_DASHDOT,
1042 RID_SVXITEMS_UL_DASHDOTDOT,
1043 RID_SVXITEMS_UL_SMALLWAVE,
1044 RID_SVXITEMS_UL_WAVE,
1045 RID_SVXITEMS_UL_DOUBLEWAVE,
1046 RID_SVXITEMS_UL_BOLD,
1047 RID_SVXITEMS_UL_BOLDDOTTED,
1048 RID_SVXITEMS_UL_BOLDDASH,
1049 RID_SVXITEMS_UL_BOLDLONGDASH,
1050 RID_SVXITEMS_UL_BOLDDASHDOT,
1051 RID_SVXITEMS_UL_BOLDDASHDOTDOT,
1052 RID_SVXITEMS_UL_BOLDWAVE
1053 };
1054 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_UL) - 1 == LINESTYLE_BOLDWAVE, "must match");
1055 assert(nPos <= sal_uInt16(LINESTYLE_BOLDWAVE) && "enum overflow!");
1056 return EditResId(RID_SVXITEMS_UL[nPos]);
1057 }
1058
1059 // class SvxOverlineItem ------------------------------------------------
1060
SvxOverlineItem(const FontLineStyle eSt,const sal_uInt16 nId)1061 SvxOverlineItem::SvxOverlineItem( const FontLineStyle eSt, const sal_uInt16 nId )
1062 : SvxTextLineItem( eSt, nId )
1063 {
1064 }
1065
Clone(SfxItemPool *) const1066 SvxOverlineItem* SvxOverlineItem::Clone( SfxItemPool * ) const
1067 {
1068 return new SvxOverlineItem( *this );
1069 }
1070
GetValueTextByPos(sal_uInt16 nPos) const1071 OUString SvxOverlineItem::GetValueTextByPos( sal_uInt16 nPos ) const
1072 {
1073 static const char* RID_SVXITEMS_OL[] =
1074 {
1075 RID_SVXITEMS_OL_NONE,
1076 RID_SVXITEMS_OL_SINGLE,
1077 RID_SVXITEMS_OL_DOUBLE,
1078 RID_SVXITEMS_OL_DOTTED,
1079 RID_SVXITEMS_OL_DONTKNOW,
1080 RID_SVXITEMS_OL_DASH,
1081 RID_SVXITEMS_OL_LONGDASH,
1082 RID_SVXITEMS_OL_DASHDOT,
1083 RID_SVXITEMS_OL_DASHDOTDOT,
1084 RID_SVXITEMS_OL_SMALLWAVE,
1085 RID_SVXITEMS_OL_WAVE,
1086 RID_SVXITEMS_OL_DOUBLEWAVE,
1087 RID_SVXITEMS_OL_BOLD,
1088 RID_SVXITEMS_OL_BOLDDOTTED,
1089 RID_SVXITEMS_OL_BOLDDASH,
1090 RID_SVXITEMS_OL_BOLDLONGDASH,
1091 RID_SVXITEMS_OL_BOLDDASHDOT,
1092 RID_SVXITEMS_OL_BOLDDASHDOTDOT,
1093 RID_SVXITEMS_OL_BOLDWAVE
1094 };
1095 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_OL) - 1 == LINESTYLE_BOLDWAVE, "must match");
1096 assert(nPos <= sal_uInt16(LINESTYLE_BOLDWAVE) && "enum overflow!");
1097 return EditResId(RID_SVXITEMS_OL[nPos]);
1098 }
1099
1100 // class SvxCrossedOutItem -----------------------------------------------
1101
SvxCrossedOutItem(const FontStrikeout eSt,const sal_uInt16 nId)1102 SvxCrossedOutItem::SvxCrossedOutItem( const FontStrikeout eSt, const sal_uInt16 nId )
1103 : SfxEnumItem( nId, eSt )
1104 {
1105 }
1106
1107
HasBoolValue() const1108 bool SvxCrossedOutItem::HasBoolValue() const
1109 {
1110 return true;
1111 }
1112
1113
GetBoolValue() const1114 bool SvxCrossedOutItem::GetBoolValue() const
1115 {
1116 return GetValue() != STRIKEOUT_NONE;
1117 }
1118
1119
SetBoolValue(bool bVal)1120 void SvxCrossedOutItem::SetBoolValue( bool bVal )
1121 {
1122 SetValue( bVal ? STRIKEOUT_SINGLE : STRIKEOUT_NONE );
1123 }
1124
1125
GetValueCount() const1126 sal_uInt16 SvxCrossedOutItem::GetValueCount() const
1127 {
1128 return STRIKEOUT_DOUBLE + 1; // STRIKEOUT_NONE belongs also here
1129 }
1130
Clone(SfxItemPool *) const1131 SvxCrossedOutItem* SvxCrossedOutItem::Clone( SfxItemPool * ) const
1132 {
1133 return new SvxCrossedOutItem( *this );
1134 }
1135
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1136 bool SvxCrossedOutItem::GetPresentation
1137 (
1138 SfxItemPresentation /*ePres*/,
1139 MapUnit /*eCoreUnit*/,
1140 MapUnit /*ePresUnit*/,
1141 OUString& rText, const IntlWrapper& /*rIntl*/
1142 ) const
1143 {
1144 rText = GetValueTextByPos( GetValue() );
1145 return true;
1146 }
1147
GetValueTextByPos(sal_uInt16 nPos)1148 OUString SvxCrossedOutItem::GetValueTextByPos( sal_uInt16 nPos )
1149 {
1150 static const char* RID_SVXITEMS_STRIKEOUT[] =
1151 {
1152 RID_SVXITEMS_STRIKEOUT_NONE,
1153 RID_SVXITEMS_STRIKEOUT_SINGLE,
1154 RID_SVXITEMS_STRIKEOUT_DOUBLE,
1155 RID_SVXITEMS_STRIKEOUT_DONTKNOW,
1156 RID_SVXITEMS_STRIKEOUT_BOLD,
1157 RID_SVXITEMS_STRIKEOUT_SLASH,
1158 RID_SVXITEMS_STRIKEOUT_X
1159 };
1160 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_STRIKEOUT) - 1 == STRIKEOUT_X, "must match");
1161 assert(nPos <= sal_uInt16(STRIKEOUT_X) && "enum overflow!");
1162 return EditResId(RID_SVXITEMS_STRIKEOUT[nPos]);
1163 }
1164
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const1165 bool SvxCrossedOutItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1166 {
1167 nMemberId &= ~CONVERT_TWIPS;
1168 switch(nMemberId)
1169 {
1170 case MID_CROSSED_OUT:
1171 rVal <<= GetBoolValue();
1172 break;
1173 case MID_CROSS_OUT:
1174 rVal <<= static_cast<sal_Int16>(GetValue());
1175 break;
1176 }
1177 return true;
1178 }
1179
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)1180 bool SvxCrossedOutItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1181 {
1182 nMemberId &= ~CONVERT_TWIPS;
1183 switch(nMemberId)
1184 {
1185 case MID_CROSSED_OUT:
1186 SetBoolValue(Any2Bool(rVal));
1187 break;
1188 case MID_CROSS_OUT:
1189 {
1190 sal_Int32 nValue = 0;
1191 if(!(rVal >>= nValue))
1192 return false;
1193 SetValue(static_cast<FontStrikeout>(nValue));
1194 }
1195 break;
1196 }
1197 return true;
1198 }
1199 // class SvxShadowedItem -------------------------------------------------
1200
SvxShadowedItem(const bool bShadowed,const sal_uInt16 nId)1201 SvxShadowedItem::SvxShadowedItem( const bool bShadowed, const sal_uInt16 nId ) :
1202 SfxBoolItem( nId, bShadowed )
1203 {
1204 }
1205
Clone(SfxItemPool *) const1206 SvxShadowedItem* SvxShadowedItem::Clone( SfxItemPool * ) const
1207 {
1208 return new SvxShadowedItem( *this );
1209 }
1210
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1211 bool SvxShadowedItem::GetPresentation
1212 (
1213 SfxItemPresentation /*ePres*/,
1214 MapUnit /*eCoreUnit*/,
1215 MapUnit /*ePresUnit*/,
1216 OUString& rText, const IntlWrapper& /*rIntl*/
1217 ) const
1218 {
1219 const char* pId = RID_SVXITEMS_SHADOWED_FALSE;
1220
1221 if ( GetValue() )
1222 pId = RID_SVXITEMS_SHADOWED_TRUE;
1223 rText = EditResId(pId);
1224 return true;
1225 }
1226
1227 // class SvxAutoKernItem -------------------------------------------------
1228
SvxAutoKernItem(const bool bAutoKern,const sal_uInt16 nId)1229 SvxAutoKernItem::SvxAutoKernItem( const bool bAutoKern, const sal_uInt16 nId ) :
1230 SfxBoolItem( nId, bAutoKern )
1231 {
1232 }
1233
Clone(SfxItemPool *) const1234 SvxAutoKernItem* SvxAutoKernItem::Clone( SfxItemPool * ) const
1235 {
1236 return new SvxAutoKernItem( *this );
1237 }
1238
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1239 bool SvxAutoKernItem::GetPresentation
1240 (
1241 SfxItemPresentation /*ePres*/,
1242 MapUnit /*eCoreUnit*/,
1243 MapUnit /*ePresUnit*/,
1244 OUString& rText, const IntlWrapper& /*rIntl*/
1245 ) const
1246 {
1247 const char* pId = RID_SVXITEMS_AUTOKERN_FALSE;
1248
1249 if ( GetValue() )
1250 pId = RID_SVXITEMS_AUTOKERN_TRUE;
1251 rText = EditResId(pId);
1252 return true;
1253 }
1254
1255 // class SvxWordLineModeItem ---------------------------------------------
1256
SvxWordLineModeItem(const bool bWordLineMode,const sal_uInt16 nId)1257 SvxWordLineModeItem::SvxWordLineModeItem( const bool bWordLineMode,
1258 const sal_uInt16 nId ) :
1259 SfxBoolItem( nId, bWordLineMode )
1260 {
1261 }
1262
Clone(SfxItemPool *) const1263 SvxWordLineModeItem* SvxWordLineModeItem::Clone( SfxItemPool * ) const
1264 {
1265 return new SvxWordLineModeItem( *this );
1266 }
1267
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1268 bool SvxWordLineModeItem::GetPresentation
1269 (
1270 SfxItemPresentation /*ePres*/,
1271 MapUnit /*eCoreUnit*/,
1272 MapUnit /*ePresUnit*/,
1273 OUString& rText, const IntlWrapper& /*rIntl*/
1274 ) const
1275 {
1276 const char* pId = RID_SVXITEMS_WORDLINE_FALSE;
1277
1278 if ( GetValue() )
1279 pId = RID_SVXITEMS_WORDLINE_TRUE;
1280 rText = EditResId(pId);
1281 return true;
1282 }
1283
1284 // class SvxContourItem --------------------------------------------------
1285
SvxContourItem(const bool bContoured,const sal_uInt16 nId)1286 SvxContourItem::SvxContourItem( const bool bContoured, const sal_uInt16 nId ) :
1287 SfxBoolItem( nId, bContoured )
1288 {
1289 }
1290
Clone(SfxItemPool *) const1291 SvxContourItem* SvxContourItem::Clone( SfxItemPool * ) const
1292 {
1293 return new SvxContourItem( *this );
1294 }
1295
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1296 bool SvxContourItem::GetPresentation
1297 (
1298 SfxItemPresentation /*ePres*/,
1299 MapUnit /*eCoreUnit*/,
1300 MapUnit /*ePresUnit*/,
1301 OUString& rText, const IntlWrapper& /*rIntl*/
1302 ) const
1303 {
1304 const char* pId = RID_SVXITEMS_CONTOUR_FALSE;
1305
1306 if ( GetValue() )
1307 pId = RID_SVXITEMS_CONTOUR_TRUE;
1308 rText = EditResId(pId);
1309 return true;
1310 }
1311
1312 // class SvxColorItem ----------------------------------------------------
SvxColorItem(const sal_uInt16 nId)1313 SvxColorItem::SvxColorItem( const sal_uInt16 nId ) :
1314 SfxPoolItem( nId ),
1315 mColor( COL_BLACK )
1316 {
1317 }
1318
SvxColorItem(const Color & rCol,const sal_uInt16 nId)1319 SvxColorItem::SvxColorItem( const Color& rCol, const sal_uInt16 nId ) :
1320 SfxPoolItem( nId ),
1321 mColor( rCol )
1322 {
1323 }
1324
~SvxColorItem()1325 SvxColorItem::~SvxColorItem()
1326 {
1327 }
1328
operator ==(const SfxPoolItem & rAttr) const1329 bool SvxColorItem::operator==( const SfxPoolItem& rAttr ) const
1330 {
1331 assert(SfxPoolItem::operator==(rAttr));
1332
1333 return mColor == static_cast<const SvxColorItem&>( rAttr ).mColor;
1334 }
1335
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const1336 bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1337 {
1338 nMemberId &= ~CONVERT_TWIPS;
1339 switch (nMemberId)
1340 {
1341 case MID_COLOR_ALPHA:
1342 {
1343 auto fTransparency = static_cast<double>(255 - mColor.GetAlpha()) * 100 / 255;
1344 rVal <<= static_cast<sal_Int16>(basegfx::fround(fTransparency));
1345 break;
1346 }
1347 case MID_GRAPHIC_TRANSPARENT:
1348 {
1349 rVal <<= mColor.GetAlpha() == 0;
1350 break;
1351 }
1352 default:
1353 {
1354 rVal <<= mColor;
1355 break;
1356 }
1357 }
1358 return true;
1359 }
1360
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)1361 bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1362 {
1363 nMemberId &= ~CONVERT_TWIPS;
1364 switch(nMemberId)
1365 {
1366 case MID_COLOR_ALPHA:
1367 {
1368 sal_Int16 nTransparency = 0;
1369 bool bRet = rVal >>= nTransparency;
1370 if (bRet)
1371 {
1372 auto fTransparency = static_cast<double>(nTransparency) * 255 / 100;
1373 mColor.SetAlpha(255 - static_cast<sal_uInt8>(basegfx::fround(fTransparency)));
1374 }
1375 return bRet;
1376 }
1377 case MID_GRAPHIC_TRANSPARENT:
1378 {
1379 mColor.SetAlpha( Any2Bool( rVal ) ? 0 : 255 );
1380 return true;
1381 }
1382 default:
1383 {
1384 return rVal >>= mColor;
1385 }
1386 }
1387 }
1388
Clone(SfxItemPool *) const1389 SvxColorItem* SvxColorItem::Clone( SfxItemPool * ) const
1390 {
1391 return new SvxColorItem( *this );
1392 }
1393
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1394 bool SvxColorItem::GetPresentation
1395 (
1396 SfxItemPresentation /*ePres*/,
1397 MapUnit /*eCoreUnit*/,
1398 MapUnit /*ePresUnit*/,
1399 OUString& rText, const IntlWrapper& /*rIntl*/
1400 ) const
1401 {
1402 rText = ::GetColorString( mColor );
1403 return true;
1404 }
1405
dumpAsXml(xmlTextWriterPtr pWriter) const1406 void SvxColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1407 {
1408 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxColorItem"));
1409 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1410
1411 std::stringstream ss;
1412 ss << mColor;
1413 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(ss.str().c_str()));
1414
1415 OUString aStr;
1416 IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
1417 GetPresentation( SfxItemPresentation::Complete, MapUnit::Map100thMM, MapUnit::Map100thMM, aStr, aIntlWrapper);
1418 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8).getStr()));
1419 (void)xmlTextWriterEndElement(pWriter);
1420 }
1421
1422
1423
SetValue(const Color & rNewCol)1424 void SvxColorItem::SetValue( const Color& rNewCol )
1425 {
1426 mColor = rNewCol;
1427 }
1428
1429 // class SvxKerningItem --------------------------------------------------
1430
SvxKerningItem(const short nKern,const sal_uInt16 nId)1431 SvxKerningItem::SvxKerningItem( const short nKern, const sal_uInt16 nId ) :
1432 SfxInt16Item( nId, nKern )
1433 {
1434 }
1435
Clone(SfxItemPool *) const1436 SvxKerningItem* SvxKerningItem::Clone( SfxItemPool * ) const
1437 {
1438 return new SvxKerningItem( *this );
1439 }
1440
ScaleMetrics(tools::Long nMult,tools::Long nDiv)1441 void SvxKerningItem::ScaleMetrics( tools::Long nMult, tools::Long nDiv )
1442 {
1443 SetValue( static_cast<sal_Int16>(BigInt::Scale( GetValue(), nMult, nDiv )) );
1444 }
1445
1446
HasMetrics() const1447 bool SvxKerningItem::HasMetrics() const
1448 {
1449 return true;
1450 }
1451
1452
GetPresentation(SfxItemPresentation ePres,MapUnit eCoreUnit,MapUnit,OUString & rText,const IntlWrapper & rIntl) const1453 bool SvxKerningItem::GetPresentation
1454 (
1455 SfxItemPresentation ePres,
1456 MapUnit eCoreUnit,
1457 MapUnit /*ePresUnit*/,
1458 OUString& rText, const IntlWrapper& rIntl
1459 ) const
1460 {
1461 switch ( ePres )
1462 {
1463 case SfxItemPresentation::Nameless:
1464 rText = GetMetricText( static_cast<tools::Long>(GetValue()), eCoreUnit, MapUnit::MapPoint, &rIntl ) +
1465 " " + EditResId(GetMetricId(MapUnit::MapPoint));
1466 return true;
1467 case SfxItemPresentation::Complete:
1468 {
1469 rText = EditResId(RID_SVXITEMS_KERNING_COMPLETE);
1470 const char* pId = nullptr;
1471
1472 if ( GetValue() > 0 )
1473 pId = RID_SVXITEMS_KERNING_EXPANDED;
1474 else if ( GetValue() < 0 )
1475 pId = RID_SVXITEMS_KERNING_CONDENSED;
1476
1477 if (pId)
1478 rText += EditResId(pId);
1479 rText += GetMetricText( static_cast<tools::Long>(GetValue()), eCoreUnit, MapUnit::MapPoint, &rIntl ) +
1480 " " + EditResId(GetMetricId(MapUnit::MapPoint));
1481 return true;
1482 }
1483 default: ; //prevent warning
1484 }
1485 return false;
1486 }
1487
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const1488 bool SvxKerningItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1489 {
1490 sal_Int16 nVal = GetValue();
1491 if(nMemberId & CONVERT_TWIPS)
1492 nVal = static_cast<sal_Int16>(convertTwipToMm100(nVal));
1493 rVal <<= nVal;
1494 return true;
1495 }
1496
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)1497 bool SvxKerningItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId)
1498 {
1499 sal_Int16 nVal = sal_Int16();
1500 if(!(rVal >>= nVal))
1501 return false;
1502 if(nMemberId & CONVERT_TWIPS)
1503 nVal = static_cast<sal_Int16>(convertMm100ToTwip(nVal));
1504 SetValue(nVal);
1505 return true;
1506 }
1507
1508 // class SvxCaseMapItem --------------------------------------------------
1509
SvxCaseMapItem(const SvxCaseMap eMap,const sal_uInt16 nId)1510 SvxCaseMapItem::SvxCaseMapItem( const SvxCaseMap eMap, const sal_uInt16 nId ) :
1511 SfxEnumItem( nId, eMap )
1512 {
1513 }
1514
GetValueCount() const1515 sal_uInt16 SvxCaseMapItem::GetValueCount() const
1516 {
1517 return sal_uInt16(SvxCaseMap::End); // SvxCaseMap::SmallCaps + 1
1518 }
1519
Clone(SfxItemPool *) const1520 SvxCaseMapItem* SvxCaseMapItem::Clone( SfxItemPool * ) const
1521 {
1522 return new SvxCaseMapItem( *this );
1523 }
1524
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1525 bool SvxCaseMapItem::GetPresentation
1526 (
1527 SfxItemPresentation /*ePres*/,
1528 MapUnit /*eCoreUnit*/,
1529 MapUnit /*ePresUnit*/,
1530 OUString& rText, const IntlWrapper& /*rIntl*/
1531 ) const
1532 {
1533 rText = GetValueTextByPos( static_cast<sal_uInt16>(GetValue()) );
1534 return true;
1535 }
1536
GetValueTextByPos(sal_uInt16 nPos)1537 OUString SvxCaseMapItem::GetValueTextByPos( sal_uInt16 nPos )
1538 {
1539 static const char* RID_SVXITEMS_CASEMAP[] =
1540 {
1541 RID_SVXITEMS_CASEMAP_NONE,
1542 RID_SVXITEMS_CASEMAP_UPPERCASE,
1543 RID_SVXITEMS_CASEMAP_LOWERCASE,
1544 RID_SVXITEMS_CASEMAP_TITLE,
1545 RID_SVXITEMS_CASEMAP_SMALLCAPS
1546 };
1547
1548 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_CASEMAP) == size_t(SvxCaseMap::End), "must match");
1549 assert(nPos < sal_uInt16(SvxCaseMap::End) && "enum overflow!");
1550 return EditResId(RID_SVXITEMS_CASEMAP[nPos]);
1551 }
1552
QueryValue(uno::Any & rVal,sal_uInt8) const1553 bool SvxCaseMapItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
1554 {
1555 sal_Int16 nRet = style::CaseMap::NONE;
1556 switch( GetValue() )
1557 {
1558 case SvxCaseMap::Uppercase : nRet = style::CaseMap::UPPERCASE; break;
1559 case SvxCaseMap::Lowercase : nRet = style::CaseMap::LOWERCASE; break;
1560 case SvxCaseMap::Capitalize : nRet = style::CaseMap::TITLE ; break;
1561 case SvxCaseMap::SmallCaps: nRet = style::CaseMap::SMALLCAPS; break;
1562 default: break;
1563 }
1564 rVal <<= nRet;
1565 return true;
1566 }
1567
PutValue(const uno::Any & rVal,sal_uInt8)1568 bool SvxCaseMapItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
1569 {
1570 sal_uInt16 nVal = sal_uInt16();
1571 if(!(rVal >>= nVal))
1572 return false;
1573
1574 SvxCaseMap eVal;
1575 switch( nVal )
1576 {
1577 case style::CaseMap::NONE : eVal = SvxCaseMap::NotMapped; break;
1578 case style::CaseMap::UPPERCASE: eVal = SvxCaseMap::Uppercase; break;
1579 case style::CaseMap::LOWERCASE: eVal = SvxCaseMap::Lowercase; break;
1580 case style::CaseMap::TITLE : eVal = SvxCaseMap::Capitalize; break;
1581 case style::CaseMap::SMALLCAPS: eVal = SvxCaseMap::SmallCaps; break;
1582 default: return false;
1583 }
1584 SetValue(eVal);
1585 return true;
1586 }
1587
1588 // class SvxEscapementItem -----------------------------------------------
1589
SvxEscapementItem(const sal_uInt16 nId)1590 SvxEscapementItem::SvxEscapementItem( const sal_uInt16 nId ) :
1591 SfxEnumItemInterface( nId ),
1592
1593 nEsc ( 0 ),
1594 nProp ( 100 )
1595 {
1596 }
1597
1598
SvxEscapementItem(const SvxEscapement eEscape,const sal_uInt16 nId)1599 SvxEscapementItem::SvxEscapementItem( const SvxEscapement eEscape,
1600 const sal_uInt16 nId ) :
1601 SfxEnumItemInterface( nId ),
1602 nProp( 100 )
1603 {
1604 SetEscapement( eEscape );
1605 if( nEsc )
1606 nProp = DFLT_ESC_PROP;
1607 }
1608
1609
SvxEscapementItem(const short _nEsc,const sal_uInt8 _nProp,const sal_uInt16 nId)1610 SvxEscapementItem::SvxEscapementItem( const short _nEsc,
1611 const sal_uInt8 _nProp,
1612 const sal_uInt16 nId ) :
1613 SfxEnumItemInterface( nId ),
1614 nEsc ( _nEsc ),
1615 nProp ( _nProp )
1616 {
1617 }
1618
1619
operator ==(const SfxPoolItem & rAttr) const1620 bool SvxEscapementItem::operator==( const SfxPoolItem& rAttr ) const
1621 {
1622 assert(SfxPoolItem::operator==(rAttr));
1623
1624 return( nEsc == static_cast<const SvxEscapementItem&>(rAttr).nEsc &&
1625 nProp == static_cast<const SvxEscapementItem&>(rAttr).nProp );
1626 }
1627
Clone(SfxItemPool *) const1628 SvxEscapementItem* SvxEscapementItem::Clone( SfxItemPool * ) const
1629 {
1630 return new SvxEscapementItem( *this );
1631 }
1632
GetValueCount() const1633 sal_uInt16 SvxEscapementItem::GetValueCount() const
1634 {
1635 return sal_uInt16(SvxEscapement::End); // SvxEscapement::Subscript + 1
1636 }
1637
1638
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1639 bool SvxEscapementItem::GetPresentation
1640 (
1641 SfxItemPresentation /*ePres*/,
1642 MapUnit /*eCoreUnit*/,
1643 MapUnit /*ePresUnit*/,
1644 OUString& rText, const IntlWrapper& /*rIntl*/
1645 ) const
1646 {
1647 rText = GetValueTextByPos( GetEnumValue() );
1648
1649 if ( nEsc != 0 )
1650 {
1651 if( DFLT_ESC_AUTO_SUPER == nEsc || DFLT_ESC_AUTO_SUB == nEsc )
1652 rText += EditResId(RID_SVXITEMS_ESCAPEMENT_AUTO);
1653 else
1654 rText += OUString::number( nEsc ) + "%";
1655 }
1656 return true;
1657 }
1658
GetValueTextByPos(sal_uInt16 nPos)1659 OUString SvxEscapementItem::GetValueTextByPos( sal_uInt16 nPos )
1660 {
1661 static const char* RID_SVXITEMS_ESCAPEMENT[] =
1662 {
1663 RID_SVXITEMS_ESCAPEMENT_OFF,
1664 RID_SVXITEMS_ESCAPEMENT_SUPER,
1665 RID_SVXITEMS_ESCAPEMENT_SUB
1666 };
1667
1668 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_ESCAPEMENT) == size_t(SvxEscapement::End), "must match");
1669 assert(nPos < sal_uInt16(SvxEscapement::End) && "enum overflow!");
1670 return EditResId(RID_SVXITEMS_ESCAPEMENT[nPos]);
1671 }
1672
GetEnumValue() const1673 sal_uInt16 SvxEscapementItem::GetEnumValue() const
1674 {
1675 if ( nEsc < 0 )
1676 return sal_uInt16(SvxEscapement::Subscript);
1677 else if ( nEsc > 0 )
1678 return sal_uInt16(SvxEscapement::Superscript);
1679 return sal_uInt16(SvxEscapement::Off);
1680 }
1681
1682
SetEnumValue(sal_uInt16 nVal)1683 void SvxEscapementItem::SetEnumValue( sal_uInt16 nVal )
1684 {
1685 SetEscapement( static_cast<SvxEscapement>(nVal) );
1686 }
1687
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const1688 bool SvxEscapementItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1689 {
1690 nMemberId &= ~CONVERT_TWIPS;
1691 switch(nMemberId)
1692 {
1693 case MID_ESC:
1694 rVal <<= static_cast<sal_Int16>(nEsc);
1695 break;
1696 case MID_ESC_HEIGHT:
1697 rVal <<= static_cast<sal_Int8>(nProp);
1698 break;
1699 case MID_AUTO_ESC:
1700 rVal <<= (DFLT_ESC_AUTO_SUB == nEsc || DFLT_ESC_AUTO_SUPER == nEsc);
1701 break;
1702 }
1703 return true;
1704 }
1705
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)1706 bool SvxEscapementItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1707 {
1708 nMemberId &= ~CONVERT_TWIPS;
1709 switch(nMemberId)
1710 {
1711 case MID_ESC:
1712 {
1713 sal_Int16 nVal = sal_Int16();
1714 if( (rVal >>= nVal) && (std::abs(nVal) <= MAX_ESC_POS+1))
1715 nEsc = nVal;
1716 else
1717 return false;
1718 }
1719 break;
1720 case MID_ESC_HEIGHT:
1721 {
1722 sal_Int8 nVal = sal_Int8();
1723 if( (rVal >>= nVal) && (nVal <= 100))
1724 nProp = nVal;
1725 else
1726 return false;
1727 }
1728 break;
1729 case MID_AUTO_ESC:
1730 {
1731 bool bVal = Any2Bool(rVal);
1732 if(bVal)
1733 {
1734 if(nEsc < 0)
1735 nEsc = DFLT_ESC_AUTO_SUB;
1736 else
1737 nEsc = DFLT_ESC_AUTO_SUPER;
1738 }
1739 else
1740 if(DFLT_ESC_AUTO_SUPER == nEsc )
1741 --nEsc;
1742 else if(DFLT_ESC_AUTO_SUB == nEsc)
1743 ++nEsc;
1744 }
1745 break;
1746 }
1747 return true;
1748 }
1749
1750 // class SvxLanguageItem -------------------------------------------------
1751
SvxLanguageItem(const LanguageType eLang,const sal_uInt16 nId)1752 SvxLanguageItem::SvxLanguageItem( const LanguageType eLang, const sal_uInt16 nId )
1753 : SvxLanguageItem_Base( nId , eLang )
1754 {
1755 }
1756
1757
GetValueCount() const1758 sal_uInt16 SvxLanguageItem::GetValueCount() const
1759 {
1760 // #i50205# got rid of class International
1761 SAL_WARN( "editeng.items", "SvxLanguageItem::GetValueCount: supposed to return a count of what?");
1762 // Could be SvtLanguageTable::GetEntryCount() (all locales with resource string)?
1763 // Could be LocaleDataWrapper::getInstalledLanguageTypes() (all locales with locale data)?
1764 return 0;
1765 }
1766
Clone(SfxItemPool *) const1767 SvxLanguageItem* SvxLanguageItem::Clone( SfxItemPool * ) const
1768 {
1769 return new SvxLanguageItem( *this );
1770 }
1771
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1772 bool SvxLanguageItem::GetPresentation
1773 (
1774 SfxItemPresentation /*ePres*/,
1775 MapUnit /*eCoreUnit*/,
1776 MapUnit /*ePresUnit*/,
1777 OUString& rText, const IntlWrapper& /*rIntl*/
1778 ) const
1779 {
1780 rText = SvtLanguageTable::GetLanguageString( GetValue() );
1781 return true;
1782 }
1783
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const1784 bool SvxLanguageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1785 {
1786 nMemberId &= ~CONVERT_TWIPS;
1787 switch(nMemberId)
1788 {
1789 case MID_LANG_INT: // for basic conversions!
1790 rVal <<= static_cast<sal_Int16>(static_cast<sal_uInt16>(GetValue()));
1791 break;
1792 case MID_LANG_LOCALE:
1793 lang::Locale aRet( LanguageTag::convertToLocale( GetValue(), false));
1794 rVal <<= aRet;
1795 break;
1796 }
1797 return true;
1798 }
1799
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)1800 bool SvxLanguageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1801 {
1802 nMemberId &= ~CONVERT_TWIPS;
1803 switch(nMemberId)
1804 {
1805 case MID_LANG_INT: // for basic conversions!
1806 {
1807 sal_Int32 nValue = 0;
1808 if(!(rVal >>= nValue))
1809 return false;
1810
1811 SetValue(LanguageType(nValue));
1812 }
1813 break;
1814 case MID_LANG_LOCALE:
1815 {
1816 lang::Locale aLocale;
1817 if(!(rVal >>= aLocale))
1818 return false;
1819
1820 SetValue( LanguageTag::convertToLanguageType( aLocale, false));
1821 }
1822 break;
1823 }
1824 return true;
1825 }
1826
1827 // class SvxNoHyphenItem -------------------------------------------------
1828
SvxNoHyphenItem(const sal_uInt16 nId)1829 SvxNoHyphenItem::SvxNoHyphenItem( const sal_uInt16 nId ) :
1830 SfxBoolItem( nId , true )
1831 {
1832 }
1833
Clone(SfxItemPool *) const1834 SvxNoHyphenItem* SvxNoHyphenItem::Clone( SfxItemPool* ) const
1835 {
1836 return new SvxNoHyphenItem( *this );
1837 }
1838
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1839 bool SvxNoHyphenItem::GetPresentation
1840 (
1841 SfxItemPresentation /*ePres*/,
1842 MapUnit /*eCoreUnit*/,
1843 MapUnit /*ePresUnit*/,
1844 OUString& rText, const IntlWrapper& /*rIntl*/
1845 ) const
1846 {
1847 rText.clear();
1848 return false;
1849 }
1850
1851 /*
1852 * Dummy item for ToolBox controls:
1853 *
1854 */
1855
1856
1857 // class SvxBlinkItem -------------------------------------------------
1858
1859
SvxBlinkItem(const bool bBlink,const sal_uInt16 nId)1860 SvxBlinkItem::SvxBlinkItem( const bool bBlink, const sal_uInt16 nId ) :
1861 SfxBoolItem( nId, bBlink )
1862 {
1863 }
1864
Clone(SfxItemPool *) const1865 SvxBlinkItem* SvxBlinkItem::Clone( SfxItemPool * ) const
1866 {
1867 return new SvxBlinkItem( *this );
1868 }
1869
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1870 bool SvxBlinkItem::GetPresentation
1871 (
1872 SfxItemPresentation /*ePres*/,
1873 MapUnit /*eCoreUnit*/,
1874 MapUnit /*ePresUnit*/,
1875 OUString& rText, const IntlWrapper& /*rIntl*/
1876 ) const
1877 {
1878 const char* pId = RID_SVXITEMS_BLINK_FALSE;
1879
1880 if ( GetValue() )
1881 pId = RID_SVXITEMS_BLINK_TRUE;
1882 rText = EditResId(pId);
1883 return true;
1884 }
1885
1886 // class SvxEmphaisMarkItem ---------------------------------------------------
1887
SvxEmphasisMarkItem(const FontEmphasisMark nValue,const sal_uInt16 nId)1888 SvxEmphasisMarkItem::SvxEmphasisMarkItem( const FontEmphasisMark nValue,
1889 const sal_uInt16 nId )
1890 : SfxUInt16Item( nId, static_cast<sal_uInt16>(nValue) )
1891 {
1892 }
1893
Clone(SfxItemPool *) const1894 SvxEmphasisMarkItem* SvxEmphasisMarkItem::Clone( SfxItemPool * ) const
1895 {
1896 return new SvxEmphasisMarkItem( *this );
1897 }
1898
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const1899 bool SvxEmphasisMarkItem::GetPresentation
1900 (
1901 SfxItemPresentation /*ePres*/,
1902 MapUnit /*eCoreUnit*/,
1903 MapUnit /*ePresUnit*/,
1904 OUString& rText,
1905 const IntlWrapper& /*rIntl*/
1906 ) const
1907 {
1908 static const char* RID_SVXITEMS_EMPHASIS[] =
1909 {
1910 RID_SVXITEMS_EMPHASIS_NONE_STYLE,
1911 RID_SVXITEMS_EMPHASIS_DOT_STYLE,
1912 RID_SVXITEMS_EMPHASIS_CIRCLE_STYLE,
1913 RID_SVXITEMS_EMPHASIS_DISC_STYLE,
1914 RID_SVXITEMS_EMPHASIS_ACCENT_STYLE
1915 };
1916
1917 FontEmphasisMark nVal = GetEmphasisMark();
1918 rText = EditResId(RID_SVXITEMS_EMPHASIS[
1919 static_cast<sal_uInt16>(static_cast<FontEmphasisMark>( nVal & FontEmphasisMark::Style ))]);
1920 const char* pId = ( FontEmphasisMark::PosAbove & nVal )
1921 ? RID_SVXITEMS_EMPHASIS_ABOVE_POS
1922 : ( FontEmphasisMark::PosBelow & nVal )
1923 ? RID_SVXITEMS_EMPHASIS_BELOW_POS
1924 : nullptr;
1925 if( pId )
1926 rText += EditResId( pId );
1927 return true;
1928 }
1929
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const1930 bool SvxEmphasisMarkItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1931 {
1932 nMemberId &= ~CONVERT_TWIPS;
1933 switch( nMemberId )
1934 {
1935 case MID_EMPHASIS:
1936 {
1937 FontEmphasisMark nValue = GetEmphasisMark();
1938 sal_Int16 nRet = 0;
1939 switch(nValue & FontEmphasisMark::Style)
1940 {
1941 case FontEmphasisMark::NONE : nRet = FontEmphasis::NONE; break;
1942 case FontEmphasisMark::Dot : nRet = FontEmphasis::DOT_ABOVE; break;
1943 case FontEmphasisMark::Circle : nRet = FontEmphasis::CIRCLE_ABOVE; break;
1944 case FontEmphasisMark::Disc : nRet = FontEmphasis::DISK_ABOVE; break;
1945 case FontEmphasisMark::Accent : nRet = FontEmphasis::ACCENT_ABOVE; break;
1946 default: break;
1947 }
1948 if(nRet && nValue & FontEmphasisMark::PosBelow)
1949 nRet += 10;
1950 rVal <<= nRet;
1951 }
1952 break;
1953 }
1954 return true;
1955 }
1956
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)1957 bool SvxEmphasisMarkItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1958 {
1959 nMemberId &= ~CONVERT_TWIPS;
1960 switch( nMemberId )
1961 {
1962 case MID_EMPHASIS:
1963 {
1964 sal_Int32 nValue = -1;
1965 rVal >>= nValue;
1966 FontEmphasisMark nMark;
1967 switch(nValue)
1968 {
1969 case FontEmphasis::NONE : nMark = FontEmphasisMark::NONE; break;
1970 case FontEmphasis::DOT_ABOVE : nMark = FontEmphasisMark::Dot|FontEmphasisMark::PosAbove; break;
1971 case FontEmphasis::CIRCLE_ABOVE: nMark = FontEmphasisMark::Circle|FontEmphasisMark::PosAbove; break;
1972 case FontEmphasis::DISK_ABOVE : nMark = FontEmphasisMark::Disc|FontEmphasisMark::PosAbove; break;
1973 case FontEmphasis::ACCENT_ABOVE: nMark = FontEmphasisMark::Accent|FontEmphasisMark::PosAbove; break;
1974 case FontEmphasis::DOT_BELOW : nMark = FontEmphasisMark::Dot|FontEmphasisMark::PosBelow; break;
1975 case FontEmphasis::CIRCLE_BELOW: nMark = FontEmphasisMark::Circle|FontEmphasisMark::PosBelow; break;
1976 case FontEmphasis::DISK_BELOW : nMark = FontEmphasisMark::Disc|FontEmphasisMark::PosBelow; break;
1977 case FontEmphasis::ACCENT_BELOW: nMark = FontEmphasisMark::Accent|FontEmphasisMark::PosBelow; break;
1978 default: return false;
1979 }
1980 SetValue( static_cast<sal_Int16>(nMark) );
1981 }
1982 break;
1983 }
1984 return true;
1985 }
1986
1987 /*************************************************************************
1988 |* class SvxTwoLinesItem
1989 *************************************************************************/
1990
SvxTwoLinesItem(bool bFlag,sal_Unicode nStartBracket,sal_Unicode nEndBracket,sal_uInt16 nW)1991 SvxTwoLinesItem::SvxTwoLinesItem( bool bFlag, sal_Unicode nStartBracket,
1992 sal_Unicode nEndBracket, sal_uInt16 nW )
1993 : SfxPoolItem( nW ),
1994 cStartBracket( nStartBracket ), cEndBracket( nEndBracket ), bOn( bFlag )
1995 {
1996 }
1997
~SvxTwoLinesItem()1998 SvxTwoLinesItem::~SvxTwoLinesItem()
1999 {
2000 }
2001
operator ==(const SfxPoolItem & rAttr) const2002 bool SvxTwoLinesItem::operator==( const SfxPoolItem& rAttr ) const
2003 {
2004 assert(SfxPoolItem::operator==(rAttr));
2005 return bOn == static_cast<const SvxTwoLinesItem&>(rAttr).bOn &&
2006 cStartBracket == static_cast<const SvxTwoLinesItem&>(rAttr).cStartBracket &&
2007 cEndBracket == static_cast<const SvxTwoLinesItem&>(rAttr).cEndBracket;
2008 }
2009
Clone(SfxItemPool *) const2010 SvxTwoLinesItem* SvxTwoLinesItem::Clone( SfxItemPool* ) const
2011 {
2012 return new SvxTwoLinesItem( *this );
2013 }
2014
QueryValue(css::uno::Any & rVal,sal_uInt8 nMemberId) const2015 bool SvxTwoLinesItem::QueryValue( css::uno::Any& rVal,
2016 sal_uInt8 nMemberId ) const
2017 {
2018 nMemberId &= ~CONVERT_TWIPS;
2019 bool bRet = true;
2020 switch( nMemberId )
2021 {
2022 case MID_TWOLINES:
2023 rVal <<= bOn;
2024 break;
2025 case MID_START_BRACKET:
2026 {
2027 OUString s;
2028 if( cStartBracket )
2029 s = OUString( cStartBracket );
2030 rVal <<= s;
2031 }
2032 break;
2033 case MID_END_BRACKET:
2034 {
2035 OUString s;
2036 if( cEndBracket )
2037 s = OUString( cEndBracket );
2038 rVal <<= s;
2039 }
2040 break;
2041 default:
2042 bRet = false;
2043 break;
2044 }
2045 return bRet;
2046 }
2047
PutValue(const css::uno::Any & rVal,sal_uInt8 nMemberId)2048 bool SvxTwoLinesItem::PutValue( const css::uno::Any& rVal,
2049 sal_uInt8 nMemberId )
2050 {
2051 nMemberId &= ~CONVERT_TWIPS;
2052 bool bRet = false;
2053 OUString s;
2054 switch( nMemberId )
2055 {
2056 case MID_TWOLINES:
2057 bOn = Any2Bool( rVal );
2058 bRet = true;
2059 break;
2060 case MID_START_BRACKET:
2061 if( rVal >>= s )
2062 {
2063 cStartBracket = s.isEmpty() ? 0 : s[ 0 ];
2064 bRet = true;
2065 }
2066 break;
2067 case MID_END_BRACKET:
2068 if( rVal >>= s )
2069 {
2070 cEndBracket = s.isEmpty() ? 0 : s[ 0 ];
2071 bRet = true;
2072 }
2073 break;
2074 }
2075 return bRet;
2076 }
2077
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const2078 bool SvxTwoLinesItem::GetPresentation( SfxItemPresentation /*ePres*/,
2079 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2080 OUString &rText, const IntlWrapper& /*rIntl*/ ) const
2081 {
2082 if( !GetValue() )
2083 rText = EditResId( RID_SVXITEMS_TWOLINES_OFF );
2084 else
2085 {
2086 rText = EditResId( RID_SVXITEMS_TWOLINES );
2087 if( GetStartBracket() )
2088 rText = OUStringChar(GetStartBracket()) + rText;
2089 if( GetEndBracket() )
2090 rText += OUStringChar(GetEndBracket());
2091 }
2092 return true;
2093 }
2094
2095
2096 /*************************************************************************
2097 |* class SvxTextRotateItem
2098 *************************************************************************/
2099
SvxTextRotateItem(Degree10 nValue,const sal_uInt16 nW)2100 SvxTextRotateItem::SvxTextRotateItem(Degree10 nValue, const sal_uInt16 nW)
2101 : SfxUInt16Item(nW, nValue.get())
2102 {
2103 }
2104
Clone(SfxItemPool *) const2105 SvxTextRotateItem* SvxTextRotateItem::Clone(SfxItemPool*) const
2106 {
2107 return new SvxTextRotateItem(*this);
2108 }
2109
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const2110 bool SvxTextRotateItem::GetPresentation(
2111 SfxItemPresentation /*ePres*/,
2112 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2113 OUString &rText, const IntlWrapper&) const
2114 {
2115 if (!GetValue())
2116 rText = EditResId(RID_SVXITEMS_TEXTROTATE_OFF);
2117 else
2118 {
2119 rText = EditResId(RID_SVXITEMS_TEXTROTATE);
2120 rText = rText.replaceFirst("$(ARG1)",
2121 OUString::number(GetValue().get() / 10));
2122 }
2123 return true;
2124 }
2125
QueryValue(css::uno::Any & rVal,sal_uInt8 nMemberId) const2126 bool SvxTextRotateItem::QueryValue(css::uno::Any& rVal,
2127 sal_uInt8 nMemberId) const
2128 {
2129 nMemberId &= ~CONVERT_TWIPS;
2130 bool bRet = true;
2131 switch (nMemberId)
2132 {
2133 case MID_ROTATE:
2134 rVal <<= static_cast<sal_Int16>(GetValue());
2135 break;
2136 default:
2137 bRet = false;
2138 break;
2139 }
2140 return bRet;
2141 }
2142
PutValue(const css::uno::Any & rVal,sal_uInt8 nMemberId)2143 bool SvxTextRotateItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId)
2144 {
2145 nMemberId &= ~CONVERT_TWIPS;
2146 bool bRet = true;
2147 switch (nMemberId)
2148 {
2149 case MID_ROTATE:
2150 {
2151 sal_Int16 nVal = 0;
2152 if ((rVal >>= nVal) && (0 == nVal || 900 == nVal || 2700 == nVal))
2153 SetValue(Degree10(nVal));
2154 else
2155 bRet = false;
2156 break;
2157 }
2158 default:
2159 bRet = false;
2160 }
2161 return bRet;
2162 }
2163
dumpAsXml(xmlTextWriterPtr pWriter) const2164 void SvxTextRotateItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2165 {
2166 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTextRotateItem"));
2167 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
2168 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue().get()).getStr()));
2169 (void)xmlTextWriterEndElement(pWriter);
2170 }
2171
2172
2173 /*************************************************************************
2174 |* class SvxCharRotateItem
2175 *************************************************************************/
2176
SvxCharRotateItem(Degree10 nValue,bool bFitIntoLine,const sal_uInt16 nW)2177 SvxCharRotateItem::SvxCharRotateItem( Degree10 nValue,
2178 bool bFitIntoLine,
2179 const sal_uInt16 nW )
2180 : SvxTextRotateItem(nValue, nW), bFitToLine( bFitIntoLine )
2181 {
2182 }
2183
Clone(SfxItemPool *) const2184 SvxCharRotateItem* SvxCharRotateItem::Clone( SfxItemPool* ) const
2185 {
2186 return new SvxCharRotateItem( *this );
2187 }
2188
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const2189 bool SvxCharRotateItem::GetPresentation(
2190 SfxItemPresentation /*ePres*/,
2191 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2192 OUString &rText, const IntlWrapper&) const
2193 {
2194 if( !GetValue() )
2195 rText = EditResId( RID_SVXITEMS_CHARROTATE_OFF );
2196 else
2197 {
2198 rText = EditResId( RID_SVXITEMS_CHARROTATE );
2199 rText = rText.replaceFirst( "$(ARG1)",
2200 OUString::number( GetValue().get() / 10 ));
2201 if( IsFitToLine() )
2202 rText += EditResId( RID_SVXITEMS_CHARROTATE_FITLINE );
2203 }
2204 return true;
2205 }
2206
QueryValue(css::uno::Any & rVal,sal_uInt8 nMemberId) const2207 bool SvxCharRotateItem::QueryValue( css::uno::Any& rVal,
2208 sal_uInt8 nMemberId ) const
2209 {
2210 bool bRet = true;
2211 switch(nMemberId & ~CONVERT_TWIPS)
2212 {
2213 case MID_ROTATE:
2214 SvxTextRotateItem::QueryValue(rVal, nMemberId);
2215 break;
2216 case MID_FITTOLINE:
2217 rVal <<= IsFitToLine();
2218 break;
2219 default:
2220 bRet = false;
2221 break;
2222 }
2223 return bRet;
2224 }
2225
PutValue(const css::uno::Any & rVal,sal_uInt8 nMemberId)2226 bool SvxCharRotateItem::PutValue( const css::uno::Any& rVal,
2227 sal_uInt8 nMemberId )
2228 {
2229 bool bRet = true;
2230 switch(nMemberId & ~CONVERT_TWIPS)
2231 {
2232 case MID_ROTATE:
2233 {
2234 bRet = SvxTextRotateItem::PutValue(rVal, nMemberId);
2235 break;
2236 }
2237
2238 case MID_FITTOLINE:
2239 SetFitToLine( Any2Bool( rVal ) );
2240 break;
2241 default:
2242 bRet = false;
2243 }
2244 return bRet;
2245 }
2246
operator ==(const SfxPoolItem & rItem) const2247 bool SvxCharRotateItem::operator==( const SfxPoolItem& rItem ) const
2248 {
2249 assert(SfxPoolItem::operator==(rItem));
2250 return SvxTextRotateItem::operator==( rItem ) &&
2251 IsFitToLine() == static_cast<const SvxCharRotateItem&>(rItem).IsFitToLine();
2252 }
2253
dumpAsXml(xmlTextWriterPtr pWriter) const2254 void SvxCharRotateItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2255 {
2256 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxCharRotateItem"));
2257 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
2258 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue().get()).getStr()));
2259 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("fitToLine"), BAD_CAST(OString::boolean(IsFitToLine()).getStr()));
2260 (void)xmlTextWriterEndElement(pWriter);
2261 }
2262
2263 /*************************************************************************
2264 |* class SvxCharScaleItem
2265 *************************************************************************/
2266
SvxCharScaleWidthItem(sal_uInt16 nValue,const sal_uInt16 nW)2267 SvxCharScaleWidthItem::SvxCharScaleWidthItem( sal_uInt16 nValue,
2268 const sal_uInt16 nW )
2269 : SfxUInt16Item( nW, nValue )
2270 {
2271 }
2272
Clone(SfxItemPool *) const2273 SvxCharScaleWidthItem* SvxCharScaleWidthItem::Clone( SfxItemPool* ) const
2274 {
2275 return new SvxCharScaleWidthItem( *this );
2276 }
2277
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const2278 bool SvxCharScaleWidthItem::GetPresentation(
2279 SfxItemPresentation /*ePres*/,
2280 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
2281 OUString &rText, const IntlWrapper&) const
2282 {
2283 if( !GetValue() )
2284 rText = EditResId( RID_SVXITEMS_CHARSCALE_OFF );
2285 else
2286 {
2287 rText = EditResId( RID_SVXITEMS_CHARSCALE );
2288 rText = rText.replaceFirst( "$(ARG1)",
2289 OUString::number( GetValue() ));
2290 }
2291 return true;
2292 }
2293
PutValue(const uno::Any & rVal,sal_uInt8)2294 bool SvxCharScaleWidthItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
2295 {
2296 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
2297 // where we still want this to be a sal_Int16
2298 sal_Int16 nValue = sal_Int16();
2299 if (rVal >>= nValue)
2300 {
2301 SetValue( static_cast<sal_uInt16>(nValue) );
2302 return true;
2303 }
2304
2305 SAL_WARN("editeng.items", "SvxCharScaleWidthItem::PutValue - Wrong type!" );
2306 return false;
2307 }
2308
QueryValue(uno::Any & rVal,sal_uInt8) const2309 bool SvxCharScaleWidthItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
2310 {
2311 // SfxUInt16Item::QueryValue returns sal_Int32 in Any now... (srx642w)
2312 // where we still want this to be a sal_Int16
2313 rVal <<= static_cast<sal_Int16>(GetValue());
2314 return true;
2315 }
2316
2317 /*************************************************************************
2318 |* class SvxCharReliefItem
2319 *************************************************************************/
2320
SvxCharReliefItem(FontRelief eValue,const sal_uInt16 nId)2321 SvxCharReliefItem::SvxCharReliefItem( FontRelief eValue,
2322 const sal_uInt16 nId )
2323 : SfxEnumItem( nId, eValue )
2324 {
2325 }
2326
Clone(SfxItemPool *) const2327 SvxCharReliefItem* SvxCharReliefItem::Clone( SfxItemPool * ) const
2328 {
2329 return new SvxCharReliefItem( *this );
2330 }
2331
2332 static const char* RID_SVXITEMS_RELIEF[] =
2333 {
2334 RID_SVXITEMS_RELIEF_NONE,
2335 RID_SVXITEMS_RELIEF_EMBOSSED,
2336 RID_SVXITEMS_RELIEF_ENGRAVED
2337 };
2338
GetValueTextByPos(sal_uInt16 nPos)2339 OUString SvxCharReliefItem::GetValueTextByPos(sal_uInt16 nPos)
2340 {
2341 assert(nPos < SAL_N_ELEMENTS(RID_SVXITEMS_RELIEF) && "enum overflow");
2342 return EditResId(RID_SVXITEMS_RELIEF[nPos]);
2343 }
2344
GetValueCount() const2345 sal_uInt16 SvxCharReliefItem::GetValueCount() const
2346 {
2347 return SAL_N_ELEMENTS(RID_SVXITEMS_RELIEF) - 1;
2348 }
2349
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const2350 bool SvxCharReliefItem::GetPresentation
2351 (
2352 SfxItemPresentation /*ePres*/,
2353 MapUnit /*eCoreUnit*/,
2354 MapUnit /*ePresUnit*/,
2355 OUString& rText, const IntlWrapper& /*rIntl*/
2356 ) const
2357 {
2358 rText = GetValueTextByPos( static_cast<sal_uInt16>(GetValue()) );
2359 return true;
2360 }
2361
PutValue(const css::uno::Any & rVal,sal_uInt8 nMemberId)2362 bool SvxCharReliefItem::PutValue( const css::uno::Any& rVal,
2363 sal_uInt8 nMemberId )
2364 {
2365 nMemberId &= ~CONVERT_TWIPS;
2366 bool bRet = true;
2367 switch( nMemberId )
2368 {
2369 case MID_RELIEF:
2370 {
2371 sal_Int16 nVal = -1;
2372 rVal >>= nVal;
2373 if(nVal >= 0 && nVal <= sal_Int16(FontRelief::Engraved))
2374 SetValue( static_cast<FontRelief>(nVal) );
2375 else
2376 bRet = false;
2377 }
2378 break;
2379 default:
2380 bRet = false;
2381 break;
2382 }
2383 return bRet;
2384 }
2385
QueryValue(css::uno::Any & rVal,sal_uInt8 nMemberId) const2386 bool SvxCharReliefItem::QueryValue( css::uno::Any& rVal,
2387 sal_uInt8 nMemberId ) const
2388 {
2389 nMemberId &= ~CONVERT_TWIPS;
2390 bool bRet = true;
2391 switch( nMemberId )
2392 {
2393 case MID_RELIEF:
2394 rVal <<= static_cast<sal_Int16>(GetValue());
2395 break;
2396 default:
2397 bRet = false;
2398 break;
2399 }
2400 return bRet;
2401 }
2402
2403 /*************************************************************************
2404 |* class SvxScriptSetItem
2405 *************************************************************************/
2406
SvxScriptSetItem(sal_uInt16 nSlotId,SfxItemPool & rPool)2407 SvxScriptSetItem::SvxScriptSetItem( sal_uInt16 nSlotId, SfxItemPool& rPool )
2408 : SfxSetItem( nSlotId, std::make_unique<SfxItemSet>( rPool,
2409 svl::Items<SID_ATTR_CHAR_FONT, SID_ATTR_CHAR_FONT>{} ))
2410 {
2411 sal_uInt16 nLatin, nAsian, nComplex;
2412 GetWhichIds( nLatin, nAsian, nComplex );
2413 GetItemSet().MergeRange( nLatin, nLatin );
2414 GetItemSet().MergeRange( nAsian, nAsian );
2415 GetItemSet().MergeRange( nComplex, nComplex );
2416 }
2417
Clone(SfxItemPool *) const2418 SvxScriptSetItem* SvxScriptSetItem::Clone( SfxItemPool * ) const
2419 {
2420 SvxScriptSetItem* p = new SvxScriptSetItem( Which(), *GetItemSet().GetPool() );
2421 p->GetItemSet().Put( GetItemSet(), false );
2422 return p;
2423 }
2424
GetItemOfScriptSet(const SfxItemSet & rSet,sal_uInt16 nId)2425 const SfxPoolItem* SvxScriptSetItem::GetItemOfScriptSet(
2426 const SfxItemSet& rSet, sal_uInt16 nId )
2427 {
2428 const SfxPoolItem* pI;
2429 SfxItemState eSt = rSet.GetItemState( nId, false, &pI );
2430 if( SfxItemState::SET != eSt )
2431 pI = SfxItemState::DEFAULT == eSt ? &rSet.Get( nId ) : nullptr;
2432 return pI;
2433 }
2434
GetItemOfScript(sal_uInt16 nSlotId,const SfxItemSet & rSet,SvtScriptType nScript)2435 const SfxPoolItem* SvxScriptSetItem::GetItemOfScript( sal_uInt16 nSlotId, const SfxItemSet& rSet, SvtScriptType nScript )
2436 {
2437 sal_uInt16 nLatin, nAsian, nComplex;
2438 GetWhichIds( nSlotId, rSet, nLatin, nAsian, nComplex );
2439
2440 const SfxPoolItem *pRet, *pAsn, *pCmplx;
2441 if (nScript == SvtScriptType::ASIAN)
2442 {
2443 pRet = GetItemOfScriptSet( rSet, nAsian );
2444 } else if (nScript == SvtScriptType::COMPLEX)
2445 {
2446 pRet = GetItemOfScriptSet( rSet, nComplex );
2447 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::ASIAN))
2448 {
2449 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2450 nullptr == (pAsn = GetItemOfScriptSet( rSet, nAsian )) ||
2451 *pRet != *pAsn )
2452 pRet = nullptr;
2453 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::COMPLEX))
2454 {
2455 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2456 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2457 *pRet != *pCmplx )
2458 pRet = nullptr;
2459 } else if (nScript == (SvtScriptType::ASIAN|SvtScriptType::COMPLEX))
2460 {
2461 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nAsian )) ||
2462 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2463 *pRet != *pCmplx )
2464 pRet = nullptr;
2465 } else if (nScript == (SvtScriptType::LATIN|SvtScriptType::ASIAN|SvtScriptType::COMPLEX))
2466 {
2467 if( nullptr == (pRet = GetItemOfScriptSet( rSet, nLatin )) ||
2468 nullptr == (pAsn = GetItemOfScriptSet( rSet, nAsian )) ||
2469 nullptr == (pCmplx = GetItemOfScriptSet( rSet, nComplex )) ||
2470 *pRet != *pAsn || *pRet != *pCmplx )
2471 pRet = nullptr;
2472 } else {
2473 //no one valid -> match to latin
2474 pRet = GetItemOfScriptSet( rSet, nLatin );
2475 }
2476 return pRet;
2477 }
2478
GetItemOfScript(SvtScriptType nScript) const2479 const SfxPoolItem* SvxScriptSetItem::GetItemOfScript( SvtScriptType nScript ) const
2480 {
2481 return GetItemOfScript( Which(), GetItemSet(), nScript );
2482 }
2483
PutItemForScriptType(SvtScriptType nScriptType,const SfxPoolItem & rItem)2484 void SvxScriptSetItem::PutItemForScriptType( SvtScriptType nScriptType,
2485 const SfxPoolItem& rItem )
2486 {
2487 sal_uInt16 nLatin, nAsian, nComplex;
2488 GetWhichIds( nLatin, nAsian, nComplex );
2489
2490 std::unique_ptr<SfxPoolItem> pCpy(rItem.Clone());
2491 if( SvtScriptType::LATIN & nScriptType )
2492 {
2493 pCpy->SetWhich( nLatin );
2494 GetItemSet().Put( *pCpy );
2495 }
2496 if( SvtScriptType::ASIAN & nScriptType )
2497 {
2498 pCpy->SetWhich( nAsian );
2499 GetItemSet().Put( *pCpy );
2500 }
2501 if( SvtScriptType::COMPLEX & nScriptType )
2502 {
2503 pCpy->SetWhich( nComplex );
2504 GetItemSet().Put( *pCpy );
2505 }
2506 }
2507
GetWhichIds(sal_uInt16 nSlotId,const SfxItemSet & rSet,sal_uInt16 & rLatin,sal_uInt16 & rAsian,sal_uInt16 & rComplex)2508 void SvxScriptSetItem::GetWhichIds( sal_uInt16 nSlotId, const SfxItemSet& rSet, sal_uInt16& rLatin, sal_uInt16& rAsian, sal_uInt16& rComplex )
2509 {
2510 const SfxItemPool& rPool = *rSet.GetPool();
2511 GetSlotIds( nSlotId, rLatin, rAsian, rComplex );
2512 rLatin = rPool.GetWhich( rLatin );
2513 rAsian = rPool.GetWhich( rAsian );
2514 rComplex = rPool.GetWhich( rComplex );
2515 }
2516
GetWhichIds(sal_uInt16 & rLatin,sal_uInt16 & rAsian,sal_uInt16 & rComplex) const2517 void SvxScriptSetItem::GetWhichIds( sal_uInt16& rLatin, sal_uInt16& rAsian,
2518 sal_uInt16& rComplex ) const
2519 {
2520 GetWhichIds( Which(), GetItemSet(), rLatin, rAsian, rComplex );
2521 }
2522
GetSlotIds(sal_uInt16 nSlotId,sal_uInt16 & rLatin,sal_uInt16 & rAsian,sal_uInt16 & rComplex)2523 void SvxScriptSetItem::GetSlotIds( sal_uInt16 nSlotId, sal_uInt16& rLatin,
2524 sal_uInt16& rAsian, sal_uInt16& rComplex )
2525 {
2526 switch( nSlotId )
2527 {
2528 default:
2529 SAL_WARN( "editeng.items", "wrong SlotId for class SvxScriptSetItem" );
2530 [[fallthrough]]; // default to font - Id Range !!
2531
2532 case SID_ATTR_CHAR_FONT:
2533 rLatin = SID_ATTR_CHAR_FONT;
2534 rAsian = SID_ATTR_CHAR_CJK_FONT;
2535 rComplex = SID_ATTR_CHAR_CTL_FONT;
2536 break;
2537 case SID_ATTR_CHAR_FONTHEIGHT:
2538 rLatin = SID_ATTR_CHAR_FONTHEIGHT;
2539 rAsian = SID_ATTR_CHAR_CJK_FONTHEIGHT;
2540 rComplex = SID_ATTR_CHAR_CTL_FONTHEIGHT;
2541 break;
2542 case SID_ATTR_CHAR_WEIGHT:
2543 rLatin = SID_ATTR_CHAR_WEIGHT;
2544 rAsian = SID_ATTR_CHAR_CJK_WEIGHT;
2545 rComplex = SID_ATTR_CHAR_CTL_WEIGHT;
2546 break;
2547 case SID_ATTR_CHAR_POSTURE:
2548 rLatin = SID_ATTR_CHAR_POSTURE;
2549 rAsian = SID_ATTR_CHAR_CJK_POSTURE;
2550 rComplex = SID_ATTR_CHAR_CTL_POSTURE;
2551 break;
2552 case SID_ATTR_CHAR_LANGUAGE:
2553 rLatin = SID_ATTR_CHAR_LANGUAGE;
2554 rAsian = SID_ATTR_CHAR_CJK_LANGUAGE;
2555 rComplex = SID_ATTR_CHAR_CTL_LANGUAGE;
2556 break;
2557 case SID_ATTR_CHAR_SHADOWED:
2558 rLatin = SID_ATTR_CHAR_SHADOWED;
2559 rAsian = SID_ATTR_CHAR_SHADOWED;
2560 rComplex = SID_ATTR_CHAR_SHADOWED;
2561 break;
2562 case SID_ATTR_CHAR_STRIKEOUT:
2563 rLatin = SID_ATTR_CHAR_STRIKEOUT;
2564 rAsian = SID_ATTR_CHAR_STRIKEOUT;
2565 rComplex = SID_ATTR_CHAR_STRIKEOUT;
2566 break;
2567 }
2568 }
2569
GetDefaultFonts(SvxFontItem & rLatin,SvxFontItem & rAsian,SvxFontItem & rComplex)2570 void GetDefaultFonts( SvxFontItem& rLatin, SvxFontItem& rAsian, SvxFontItem& rComplex )
2571 {
2572 const sal_uInt16 nItemCnt = 3;
2573
2574 static struct
2575 {
2576 DefaultFontType nFontType;
2577 LanguageType nLanguage;
2578 }
2579 const aOutTypeArr[ nItemCnt ] =
2580 {
2581 { DefaultFontType::LATIN_TEXT, LANGUAGE_ENGLISH_US },
2582 { DefaultFontType::CJK_TEXT, LANGUAGE_ENGLISH_US },
2583 { DefaultFontType::CTL_TEXT, LANGUAGE_ARABIC_SAUDI_ARABIA }
2584 };
2585
2586 SvxFontItem* aItemArr[ nItemCnt ] = { &rLatin, &rAsian, &rComplex };
2587
2588 for ( sal_uInt16 n = 0; n < nItemCnt; ++n )
2589 {
2590 vcl::Font aFont( OutputDevice::GetDefaultFont( aOutTypeArr[ n ].nFontType,
2591 aOutTypeArr[ n ].nLanguage,
2592 GetDefaultFontFlags::OnlyOne ) );
2593 SvxFontItem* pItem = aItemArr[ n ];
2594 pItem->SetFamily( aFont.GetFamilyType() );
2595 pItem->SetFamilyName( aFont.GetFamilyName() );
2596 pItem->SetStyleName( OUString() );
2597 pItem->SetPitch( aFont.GetPitch());
2598 pItem->SetCharSet(aFont.GetCharSet());
2599 }
2600 }
2601
2602
QueryValue(uno::Any & rVal,sal_uInt8) const2603 bool SvxRsidItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const
2604 {
2605 rVal <<= GetValue();
2606 return true;
2607 }
2608
PutValue(const uno::Any & rVal,sal_uInt8)2609 bool SvxRsidItem::PutValue( const uno::Any& rVal, sal_uInt8 )
2610 {
2611 sal_uInt32 nRsid = 0;
2612 if( !( rVal >>= nRsid ) )
2613 return false;
2614
2615 SetValue( nRsid );
2616 return true;
2617 }
2618
Clone(SfxItemPool *) const2619 SvxRsidItem* SvxRsidItem::Clone( SfxItemPool * ) const
2620 {
2621 return new SvxRsidItem( *this );
2622 }
2623
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const2624 bool SvxRsidItem::GetPresentation
2625 (
2626 SfxItemPresentation /*ePres*/,
2627 MapUnit /*eCoreUnit*/,
2628 MapUnit /*ePresUnit*/,
2629 OUString& rText, const IntlWrapper& /*rIntl*/
2630 ) const
2631 {
2632 rText.clear();
2633 return false;
2634 }
2635
dumpAsXml(xmlTextWriterPtr pWriter) const2636 void SvxRsidItem::dumpAsXml(xmlTextWriterPtr pWriter) const
2637 {
2638 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxRsidItem"));
2639 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("whichId"), "%d", Which());
2640 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("value"), "%" SAL_PRIuUINT32, GetValue());
2641 (void)xmlTextWriterEndElement(pWriter);
2642 }
2643
2644 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2645