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: unofdesc.cxx,v $
10 * $Revision: 1.7.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 <svx/eeitem.hxx>
35 #include <com/sun/star/uno/Any.hxx>
37 #ifndef _TOOLKIT_HELPRE_VCLUNOHELPER_HXX_
38 #include <toolkit/helper/vclunohelper.hxx>
40 #include <fontitem.hxx>
41 #include <svx/fhgtitem.hxx>
42 #include <svx/postitem.hxx>
43 #include <svx/udlnitem.hxx>
44 #include <svx/wghtitem.hxx>
45 #include <svx/crsditem.hxx>
46 #include <svx/wrlmitem.hxx>
47 #include <svx/unomid.hxx>
48 #include <svtools/itempool.hxx>
50 #include "unofdesc.hxx"
52 using namespace ::rtl
;
53 using namespace ::com::sun::star
;
56 void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor
& rDesc
, Font
& rFont
)
58 rFont
.SetName( rDesc
.Name
);
59 rFont
.SetStyleName( rDesc
.StyleName
);
60 rFont
.SetSize( Size( rDesc
.Width
, rDesc
.Height
) );
61 rFont
.SetFamily( (FontFamily
)rDesc
.Family
);
62 rFont
.SetCharSet( (CharSet
)rDesc
.CharSet
);
63 rFont
.SetPitch( (FontPitch
)rDesc
.Pitch
);
64 rFont
.SetOrientation( (short)(rDesc
.Orientation
*10) );
65 rFont
.SetKerning( rDesc
.Kerning
);
66 rFont
.SetWeight( VCLUnoHelper::ConvertFontWeight(rDesc
.Weight
) );
67 rFont
.SetItalic( (FontItalic
)rDesc
.Slant
);
68 rFont
.SetUnderline( (FontUnderline
)rDesc
.Underline
);
69 rFont
.SetStrikeout( (FontStrikeout
)rDesc
.Strikeout
);
70 rFont
.SetWordLineMode( rDesc
.WordLineMode
);
73 void SvxUnoFontDescriptor::ConvertFromFont( const Font
& rFont
, awt::FontDescriptor
& rDesc
)
75 rDesc
.Name
= rFont
.GetName();
76 rDesc
.StyleName
= rFont
.GetStyleName();
77 rDesc
.Width
= sal::static_int_cast
< sal_Int16
>(rFont
.GetSize().Width());
78 rDesc
.Height
= sal::static_int_cast
< sal_Int16
>(rFont
.GetSize().Height());
79 rDesc
.Family
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFamily());
80 rDesc
.CharSet
= rFont
.GetCharSet();
81 rDesc
.Pitch
= sal::static_int_cast
< sal_Int16
>(rFont
.GetPitch());
82 rDesc
.Orientation
= static_cast< float >(rFont
.GetOrientation() / 10);
83 rDesc
.Kerning
= rFont
.IsKerning();
84 rDesc
.Weight
= VCLUnoHelper::ConvertFontWeight( rFont
.GetWeight() );
85 rDesc
.Slant
= (awt::FontSlant
)rFont
.GetItalic();
86 rDesc
.Underline
= sal::static_int_cast
< sal_Int16
>(rFont
.GetUnderline());
87 rDesc
.Strikeout
= sal::static_int_cast
< sal_Int16
>(rFont
.GetStrikeout());
88 rDesc
.WordLineMode
= rFont
.IsWordLineMode();
91 void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor
& rDesc
, SfxItemSet
& rSet
)
96 SvxFontItem
aFontItem( EE_CHAR_FONTINFO
);
97 aFontItem
.GetFamilyName()= rDesc
.Name
;
98 aFontItem
.GetStyleName() = rDesc
.StyleName
;
99 aFontItem
.GetFamily() = (FontFamily
)rDesc
.Family
;
100 aFontItem
.GetCharSet() = rDesc
.CharSet
;
101 aFontItem
.GetPitch() = (FontPitch
)rDesc
.Pitch
;
106 SvxFontHeightItem
aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT
);
107 aTemp
<<= (float)rDesc
.Height
;
108 ((SfxPoolItem
*)&aFontHeightItem
)->PutValue( aTemp
, MID_FONTHEIGHT
|CONVERT_TWIPS
);
109 rSet
.Put(aFontHeightItem
);
113 SvxPostureItem
aPostureItem( (FontItalic
)0, EE_CHAR_ITALIC
);
114 aTemp
<<= rDesc
.Slant
;
115 ((SfxPoolItem
*)&aPostureItem
)->PutValue( aTemp
, MID_POSTURE
);
116 rSet
.Put(aPostureItem
);
120 SvxUnderlineItem
aUnderlineItem( (FontUnderline
)0, EE_CHAR_UNDERLINE
);
121 aTemp
<<= (sal_Int16
)rDesc
.Underline
;
122 ((SfxPoolItem
*)&aUnderlineItem
)->PutValue( aTemp
, MID_TL_STYLE
);
123 rSet
.Put( aUnderlineItem
);
127 SvxWeightItem
aWeightItem( (FontWeight
)0, EE_CHAR_WEIGHT
);
128 aTemp
<<= rDesc
.Weight
;
129 ((SfxPoolItem
*)&aWeightItem
)->PutValue( aTemp
, MID_WEIGHT
);
130 rSet
.Put( aWeightItem
);
134 SvxCrossedOutItem
aCrossedOutItem( (FontStrikeout
)0, EE_CHAR_STRIKEOUT
);
135 aTemp
<<= rDesc
.Strikeout
;
136 ((SfxPoolItem
*)&aCrossedOutItem
)->PutValue( aTemp
, MID_CROSS_OUT
);
137 rSet
.Put( aCrossedOutItem
);
141 SvxWordLineModeItem
aWLMItem( rDesc
.WordLineMode
, EE_CHAR_WLM
);
142 rSet
.Put( aWLMItem
);
146 void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet
& rSet
, awt::FontDescriptor
& rDesc
)
148 const SfxPoolItem
* pItem
= NULL
;
150 SvxFontItem
* pFontItem
= (SvxFontItem
*)&rSet
.Get( EE_CHAR_FONTINFO
, TRUE
);
151 rDesc
.Name
= pFontItem
->GetFamilyName();
152 rDesc
.StyleName
= pFontItem
->GetStyleName();
153 rDesc
.Family
= sal::static_int_cast
< sal_Int16
>(
154 pFontItem
->GetFamily());
155 rDesc
.CharSet
= pFontItem
->GetCharSet();
156 rDesc
.Pitch
= sal::static_int_cast
< sal_Int16
>(
157 pFontItem
->GetPitch());
160 pItem
= &rSet
.Get( EE_CHAR_FONTHEIGHT
, TRUE
);
162 if( pItem
->QueryValue( aHeight
, MID_FONTHEIGHT
) )
163 aHeight
>>= rDesc
.Height
;
166 pItem
= &rSet
.Get( EE_CHAR_ITALIC
, TRUE
);
168 if(pItem
->QueryValue( aFontSlant
, MID_POSTURE
))
169 aFontSlant
>>= rDesc
.Slant
;
172 pItem
= &rSet
.Get( EE_CHAR_UNDERLINE
, TRUE
);
174 if(pItem
->QueryValue( aUnderline
, MID_TL_STYLE
))
175 aUnderline
>>= rDesc
.Underline
;
178 pItem
= &rSet
.Get( EE_CHAR_WEIGHT
, TRUE
);
180 if(pItem
->QueryValue( aWeight
, MID_WEIGHT
))
181 aWeight
>>= rDesc
.Weight
;
184 pItem
= &rSet
.Get( EE_CHAR_STRIKEOUT
, TRUE
);
186 if(pItem
->QueryValue( aStrikeOut
, MID_CROSS_OUT
))
187 aStrikeOut
>>= rDesc
.Strikeout
;
190 SvxWordLineModeItem
* pWLMItem
= (SvxWordLineModeItem
*)&rSet
.Get( EE_CHAR_WLM
, TRUE
);
191 rDesc
.WordLineMode
= pWLMItem
->GetValue();
195 #define CheckState( state ) \
198 case SFX_ITEM_DONTCARE: \
199 case SFX_ITEM_DISABLED: \
200 return beans::PropertyState_AMBIGUOUS_VALUE; \
201 case SFX_ITEM_READONLY: \
203 return beans::PropertyState_DIRECT_VALUE; \
206 beans::PropertyState
SvxUnoFontDescriptor::getPropertyState( const SfxItemSet
& rSet
)
208 CheckState(rSet
.GetItemState( EE_CHAR_FONTINFO
, FALSE
));
209 CheckState(rSet
.GetItemState( EE_CHAR_FONTHEIGHT
, FALSE
));
210 CheckState(rSet
.GetItemState( EE_CHAR_ITALIC
, FALSE
));
211 CheckState(rSet
.GetItemState( EE_CHAR_UNDERLINE
, FALSE
));
212 CheckState(rSet
.GetItemState( EE_CHAR_WEIGHT
, FALSE
));
213 CheckState(rSet
.GetItemState( EE_CHAR_STRIKEOUT
, FALSE
));
214 CheckState(rSet
.GetItemState( EE_CHAR_WLM
, FALSE
));
216 return beans::PropertyState_DEFAULT_VALUE
;
219 void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet
& rSet
)
221 rSet
.InvalidateItem( EE_CHAR_FONTINFO
);
222 rSet
.InvalidateItem( EE_CHAR_FONTHEIGHT
);
223 rSet
.InvalidateItem( EE_CHAR_ITALIC
);
224 rSet
.InvalidateItem( EE_CHAR_UNDERLINE
);
225 rSet
.InvalidateItem( EE_CHAR_WEIGHT
);
226 rSet
.InvalidateItem( EE_CHAR_STRIKEOUT
);
227 rSet
.InvalidateItem( EE_CHAR_WLM
);
230 uno::Any
SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool
* pPool
)
232 SfxItemSet
aSet( *pPool
, EE_CHAR_FONTINFO
, EE_CHAR_FONTINFO
,
233 EE_CHAR_FONTHEIGHT
, EE_CHAR_FONTHEIGHT
,
234 EE_CHAR_ITALIC
, EE_CHAR_ITALIC
,
235 EE_CHAR_UNDERLINE
, EE_CHAR_UNDERLINE
,
236 EE_CHAR_WEIGHT
, EE_CHAR_WEIGHT
,
237 EE_CHAR_STRIKEOUT
, EE_CHAR_STRIKEOUT
,
238 EE_CHAR_WLM
, EE_CHAR_WLM
, 0 );
242 if(!pPool
->IsWhich(EE_CHAR_FONTINFO
)||
243 !pPool
->IsWhich(EE_CHAR_FONTHEIGHT
)||
244 !pPool
->IsWhich(EE_CHAR_ITALIC
)||
245 !pPool
->IsWhich(EE_CHAR_UNDERLINE
)||
246 !pPool
->IsWhich(EE_CHAR_WEIGHT
)||
247 !pPool
->IsWhich(EE_CHAR_STRIKEOUT
)||
248 !pPool
->IsWhich(EE_CHAR_WLM
))
251 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_FONTINFO
));
252 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_FONTHEIGHT
));
253 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_ITALIC
));
254 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_UNDERLINE
));
255 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_WEIGHT
));
256 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_STRIKEOUT
));
257 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_WLM
));
259 awt::FontDescriptor aDesc
;
261 FillFromItemSet( aSet
, aDesc
);