1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editattr.cxx,v $
10 * $Revision: 1.16.212.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <eeng_pch.hxx>
36 #include <svx/svxfont.hxx>
37 #include <svx/flditem.hxx>
38 #include <fontitem.hxx>
39 #include <svx/postitem.hxx>
40 #include <svx/wghtitem.hxx>
41 #include <svx/udlnitem.hxx>
42 #include <svx/cntritem.hxx>
43 #include <svx/shdditem.hxx>
44 #include <svx/escpitem.hxx>
45 #include <svx/colritem.hxx>
46 #include <svx/wrlmitem.hxx>
47 #include <svx/fhgtitem.hxx>
48 #include <svx/crsditem.hxx>
49 #include <svx/cscoitem.hxx>
50 #include <svx/kernitem.hxx>
51 #include <svx/akrnitem.hxx>
52 #include <svx/langitem.hxx>
53 #include <svx/emphitem.hxx>
54 #include <svx/charscaleitem.hxx>
55 #include <svx/charreliefitem.hxx>
58 #include <editattr.hxx>
60 DBG_NAME( EE_EditAttrib
)
62 // -------------------------------------------------------------------------
64 // -------------------------------------------------------------------------
65 EditAttrib::EditAttrib( const SfxPoolItem
& rAttr
)
67 DBG_CTOR( EE_EditAttrib
, 0 );
71 EditAttrib::~EditAttrib()
73 DBG_DTOR( EE_EditAttrib
, 0 );
76 // -------------------------------------------------------------------------
77 // class EditCharAttrib
78 // -------------------------------------------------------------------------
79 EditCharAttrib::EditCharAttrib( const SfxPoolItem
& rAttr
, USHORT nS
, USHORT nE
)
87 DBG_ASSERT( ( rAttr
.Which() >= EE_ITEMS_START
) && ( rAttr
.Which() <= EE_ITEMS_END
), "EditCharAttrib CTOR: Invalid id!" );
88 DBG_ASSERT( ( rAttr
.Which() < EE_FEATURE_START
) || ( rAttr
.Which() > EE_FEATURE_END
) || ( nE
== (nS
+1) ), "EditCharAttrib CTOR: Invalid feature!" );
91 void EditCharAttrib::SetFont( SvxFont
&, OutputDevice
* )
96 // -------------------------------------------------------------------------
97 // class EditCharAttribFont
98 // -------------------------------------------------------------------------
99 EditCharAttribFont::EditCharAttribFont( const SvxFontItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
100 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
102 DBG_ASSERT( rAttr
.Which() == EE_CHAR_FONTINFO
|| rAttr
.Which() == EE_CHAR_FONTINFO_CJK
|| rAttr
.Which() == EE_CHAR_FONTINFO_CTL
, "Kein Fontattribut!" );
105 void EditCharAttribFont::SetFont( SvxFont
& rFont
, OutputDevice
* )
107 const SvxFontItem
& rAttr
= (const SvxFontItem
&)(*GetItem());
109 rFont
.SetName( rAttr
.GetFamilyName() );
110 rFont
.SetFamily( rAttr
.GetFamily() );
111 rFont
.SetPitch( rAttr
.GetPitch() );
112 rFont
.SetCharSet( rAttr
.GetCharSet() );
115 // -------------------------------------------------------------------------
116 // class EditCharAttribItalic
117 // -------------------------------------------------------------------------
118 EditCharAttribItalic::EditCharAttribItalic( const SvxPostureItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
119 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
121 DBG_ASSERT( rAttr
.Which() == EE_CHAR_ITALIC
|| rAttr
.Which() == EE_CHAR_ITALIC_CJK
|| rAttr
.Which() == EE_CHAR_ITALIC_CTL
, "Kein Italicattribut!" );
124 void EditCharAttribItalic::SetFont( SvxFont
& rFont
, OutputDevice
* )
126 rFont
.SetItalic( ((const SvxPostureItem
*)GetItem())->GetPosture() );
129 // -------------------------------------------------------------------------
130 // class EditCharAttribWeight
131 // -------------------------------------------------------------------------
132 EditCharAttribWeight::EditCharAttribWeight( const SvxWeightItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
133 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
135 DBG_ASSERT( rAttr
.Which() == EE_CHAR_WEIGHT
|| rAttr
.Which() == EE_CHAR_WEIGHT_CJK
|| rAttr
.Which() == EE_CHAR_WEIGHT_CTL
, "Kein Weightttribut!" );
138 void EditCharAttribWeight::SetFont( SvxFont
& rFont
, OutputDevice
* )
140 rFont
.SetWeight( (FontWeight
)((const SvxWeightItem
*)GetItem())->GetValue() );
143 // -------------------------------------------------------------------------
144 // class EditCharAttribUnderline
145 // -------------------------------------------------------------------------
146 EditCharAttribUnderline::EditCharAttribUnderline( const SvxUnderlineItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
147 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
149 DBG_ASSERT( rAttr
.Which() == EE_CHAR_UNDERLINE
, "Kein Underlineattribut!" );
152 void EditCharAttribUnderline::SetFont( SvxFont
& rFont
, OutputDevice
* pOutDev
)
154 rFont
.SetUnderline( (FontUnderline
)((const SvxUnderlineItem
*)GetItem())->GetValue() );
156 pOutDev
->SetTextLineColor( ((const SvxUnderlineItem
*)GetItem())->GetColor() );
159 // -------------------------------------------------------------------------
160 // class EditCharAttribOverline
161 // -------------------------------------------------------------------------
162 EditCharAttribOverline::EditCharAttribOverline( const SvxOverlineItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
163 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
165 DBG_ASSERT( rAttr
.Which() == EE_CHAR_OVERLINE
, "Kein Overlineattribut!" );
168 void EditCharAttribOverline::SetFont( SvxFont
& rFont
, OutputDevice
* pOutDev
)
170 rFont
.SetOverline( (FontUnderline
)((const SvxOverlineItem
*)GetItem())->GetValue() );
172 pOutDev
->SetOverlineColor( ((const SvxOverlineItem
*)GetItem())->GetColor() );
175 // -------------------------------------------------------------------------
176 // class EditCharAttribFontHeight
177 // -------------------------------------------------------------------------
178 EditCharAttribFontHeight::EditCharAttribFontHeight( const SvxFontHeightItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
179 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
181 DBG_ASSERT( rAttr
.Which() == EE_CHAR_FONTHEIGHT
|| rAttr
.Which() == EE_CHAR_FONTHEIGHT_CJK
|| rAttr
.Which() == EE_CHAR_FONTHEIGHT_CTL
, "Kein Heightattribut!" );
184 void EditCharAttribFontHeight::SetFont( SvxFont
& rFont
, OutputDevice
* )
186 // Prop wird ignoriert
187 rFont
.SetSize( Size( rFont
.GetSize().Width(), ((const SvxFontHeightItem
*)GetItem())->GetHeight() ) );
190 // -------------------------------------------------------------------------
191 // class EditCharAttribFontWidth
192 // -------------------------------------------------------------------------
193 EditCharAttribFontWidth::EditCharAttribFontWidth( const SvxCharScaleWidthItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
194 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
196 DBG_ASSERT( rAttr
.Which() == EE_CHAR_FONTWIDTH
, "Kein Widthattribut!" );
199 void EditCharAttribFontWidth::SetFont( SvxFont
& /*rFont*/, OutputDevice
* )
201 // must be calculated outside, because f(device)...
204 // -------------------------------------------------------------------------
205 // class EditCharAttribStrikeout
206 // -------------------------------------------------------------------------
207 EditCharAttribStrikeout::EditCharAttribStrikeout( const SvxCrossedOutItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
208 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
210 DBG_ASSERT( rAttr
.Which() == EE_CHAR_STRIKEOUT
, "Kein Sizeattribut!" );
213 void EditCharAttribStrikeout::SetFont( SvxFont
& rFont
, OutputDevice
* )
215 rFont
.SetStrikeout( (FontStrikeout
)((const SvxCrossedOutItem
*)GetItem())->GetValue() );
218 // -------------------------------------------------------------------------
219 // class EditCharAttribColor
220 // -------------------------------------------------------------------------
221 EditCharAttribColor::EditCharAttribColor( const SvxColorItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
222 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
224 DBG_ASSERT( rAttr
.Which() == EE_CHAR_COLOR
, "Kein Colorattribut!" );
227 void EditCharAttribColor::SetFont( SvxFont
& rFont
, OutputDevice
* )
229 rFont
.SetColor( ((const SvxColorItem
*)GetItem())->GetValue() );
232 // -------------------------------------------------------------------------
233 // class EditCharAttribLanguage
234 // -------------------------------------------------------------------------
235 EditCharAttribLanguage::EditCharAttribLanguage( const SvxLanguageItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
236 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
238 DBG_ASSERT( ( rAttr
.Which() == EE_CHAR_LANGUAGE
) || ( rAttr
.Which() == EE_CHAR_LANGUAGE_CJK
) || ( rAttr
.Which() == EE_CHAR_LANGUAGE_CTL
), "Kein Languageattribut!" );
241 void EditCharAttribLanguage::SetFont( SvxFont
& rFont
, OutputDevice
* )
243 rFont
.SetLanguage( ((const SvxLanguageItem
*)GetItem())->GetLanguage() );
246 // -------------------------------------------------------------------------
247 // class EditCharAttribShadow
248 // -------------------------------------------------------------------------
249 EditCharAttribShadow::EditCharAttribShadow( const SvxShadowedItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
250 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
252 DBG_ASSERT( rAttr
.Which() == EE_CHAR_SHADOW
, "Kein Shadowattribut!" );
255 void EditCharAttribShadow::SetFont( SvxFont
& rFont
, OutputDevice
* )
257 rFont
.SetShadow( (BOOL
)((const SvxShadowedItem
*)GetItem())->GetValue() );
260 // -------------------------------------------------------------------------
261 // class EditCharAttribEscapement
262 // -------------------------------------------------------------------------
263 EditCharAttribEscapement::EditCharAttribEscapement( const SvxEscapementItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
264 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
266 DBG_ASSERT( rAttr
.Which() == EE_CHAR_ESCAPEMENT
, "Kein Escapementattribut!" );
269 #if defined( WIN ) && !defined( WNT )
270 #pragma optimize ("", off)
273 void EditCharAttribEscapement::SetFont( SvxFont
& rFont
, OutputDevice
* )
275 USHORT nProp
= ((const SvxEscapementItem
*)GetItem())->GetProp();
276 rFont
.SetPropr( (BYTE
)nProp
);
278 short nEsc
= ((const SvxEscapementItem
*)GetItem())->GetEsc();
279 if ( nEsc
== DFLT_ESC_AUTO_SUPER
)
281 else if ( nEsc
== DFLT_ESC_AUTO_SUB
)
282 nEsc
= sal::static_int_cast
< short >( -( 100 - nProp
) );
283 rFont
.SetEscapement( nEsc
);
286 #if defined( WIN ) && !defined( WNT )
287 #pragma optimize ("", on)
291 // -------------------------------------------------------------------------
292 // class EditCharAttribOutline
293 // -------------------------------------------------------------------------
294 EditCharAttribOutline::EditCharAttribOutline( const SvxContourItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
295 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
297 DBG_ASSERT( rAttr
.Which() == EE_CHAR_OUTLINE
, "Kein Outlineattribut!" );
300 void EditCharAttribOutline::SetFont( SvxFont
& rFont
, OutputDevice
* )
302 rFont
.SetOutline( (BOOL
)((const SvxContourItem
*)GetItem())->GetValue() );
305 // -------------------------------------------------------------------------
306 // class EditCharAttribTab
307 // -------------------------------------------------------------------------
308 EditCharAttribTab::EditCharAttribTab( const SfxVoidItem
& rAttr
, USHORT nPos
)
309 : EditCharAttrib( rAttr
, nPos
, nPos
+1 )
314 void EditCharAttribTab::SetFont( SvxFont
&, OutputDevice
* )
318 // -------------------------------------------------------------------------
319 // class EditCharAttribLineBreak
320 // -------------------------------------------------------------------------
321 EditCharAttribLineBreak::EditCharAttribLineBreak( const SfxVoidItem
& rAttr
, USHORT nPos
)
322 : EditCharAttrib( rAttr
, nPos
, nPos
+1 )
327 void EditCharAttribLineBreak::SetFont( SvxFont
&, OutputDevice
* )
331 // -------------------------------------------------------------------------
332 // class EditCharAttribField
333 // -------------------------------------------------------------------------
334 EditCharAttribField::EditCharAttribField( const SvxFieldItem
& rAttr
, USHORT nPos
)
335 : EditCharAttrib( rAttr
, nPos
, nPos
+1 )
337 SetFeature( TRUE
); // !!!
342 void EditCharAttribField::SetFont( SvxFont
& rFont
, OutputDevice
* )
346 rFont
.SetFillColor( *pFldColor
);
347 rFont
.SetTransparent( FALSE
);
350 rFont
.SetColor( *pTxtColor
);
353 EditCharAttribField::EditCharAttribField( const EditCharAttribField
& rAttr
)
354 : EditCharAttrib( *rAttr
.GetItem(), rAttr
.GetStart(), rAttr
.GetEnd() ),
355 aFieldValue( rAttr
.aFieldValue
)
357 // Diesen CCTOR nur fuer temporaeres Object verwenden,
358 // Item wird nicht gepoolt.
359 pTxtColor
= rAttr
.pTxtColor
? new Color( *rAttr
.pTxtColor
) : 0;
360 pFldColor
= rAttr
.pFldColor
? new Color( *rAttr
.pFldColor
) : 0;
363 EditCharAttribField::~EditCharAttribField()
368 BOOL
EditCharAttribField::operator == ( const EditCharAttribField
& rAttr
) const
370 if ( aFieldValue
!= rAttr
.aFieldValue
)
373 if ( ( pTxtColor
&& !rAttr
.pTxtColor
) || ( !pTxtColor
&& rAttr
.pTxtColor
) )
375 if ( ( pTxtColor
&& rAttr
.pTxtColor
) && ( *pTxtColor
!= *rAttr
.pTxtColor
) )
378 if ( ( pFldColor
&& !rAttr
.pFldColor
) || ( !pFldColor
&& rAttr
.pFldColor
) )
380 if ( ( pFldColor
&& rAttr
.pFldColor
) && ( *pFldColor
!= *rAttr
.pFldColor
) )
386 // -------------------------------------------------------------------------
387 // class EditCharAttribPairKerning
388 // -------------------------------------------------------------------------
389 EditCharAttribPairKerning::EditCharAttribPairKerning( const SvxAutoKernItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
390 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
392 DBG_ASSERT( rAttr
.Which() == EE_CHAR_PAIRKERNING
, "Kein PairKerning!" );
395 void EditCharAttribPairKerning::SetFont( SvxFont
& rFont
, OutputDevice
* )
397 rFont
.SetKerning( ((const SvxAutoKernItem
*)GetItem())->GetValue() );
400 // -------------------------------------------------------------------------
401 // class EditCharAttribKerning
402 // -------------------------------------------------------------------------
403 EditCharAttribKerning::EditCharAttribKerning( const SvxKerningItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
404 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
406 DBG_ASSERT( rAttr
.Which() == EE_CHAR_KERNING
, "Kein Kerning!" );
409 void EditCharAttribKerning::SetFont( SvxFont
& rFont
, OutputDevice
* )
411 rFont
.SetFixKerning( ((const SvxKerningItem
*)GetItem())->GetValue() );
414 // -------------------------------------------------------------------------
415 // class EditCharAttribWordLineMode
416 // -------------------------------------------------------------------------
417 EditCharAttribWordLineMode::EditCharAttribWordLineMode( const SvxWordLineModeItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
418 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
420 DBG_ASSERT( rAttr
.Which() == EE_CHAR_WLM
, "Kein Kerning!" );
423 void EditCharAttribWordLineMode::SetFont( SvxFont
& rFont
, OutputDevice
* )
425 rFont
.SetWordLineMode( ((const SvxWordLineModeItem
*)GetItem())->GetValue() );
428 // -------------------------------------------------------------------------
429 // class EditCharAttribEmphasisMark
430 // -------------------------------------------------------------------------
431 EditCharAttribEmphasisMark::EditCharAttribEmphasisMark( const SvxEmphasisMarkItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
432 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
434 DBG_ASSERT( rAttr
.Which() == EE_CHAR_EMPHASISMARK
, "Kein Emphasisattribut!" );
437 void EditCharAttribEmphasisMark::SetFont( SvxFont
& rFont
, OutputDevice
* )
439 rFont
.SetEmphasisMark( ((const SvxEmphasisMarkItem
*)GetItem())->GetEmphasisMark() );
442 // -------------------------------------------------------------------------
443 // class EditCharAttribRelief
444 // -------------------------------------------------------------------------
445 EditCharAttribRelief::EditCharAttribRelief( const SvxCharReliefItem
& rAttr
, USHORT _nStart
, USHORT _nEnd
)
446 : EditCharAttrib( rAttr
, _nStart
, _nEnd
)
448 DBG_ASSERT( rAttr
.Which() == EE_CHAR_RELIEF
, "Not a relief attribute!" );
451 void EditCharAttribRelief::SetFont( SvxFont
& rFont
, OutputDevice
* )
453 rFont
.SetRelief( (FontRelief
)((const SvxCharReliefItem
*)GetItem())->GetValue() );