xref: /aoo4110/main/editeng/source/uno/unofdesc.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 
27 #include <editeng/eeitem.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 
30 #ifndef _TOOLKIT_HELPRE_VCLUNOHELPER_HXX_
31 #include <toolkit/helper/vclunohelper.hxx>
32 #endif
33 #include <editeng/fontitem.hxx>
34 #include <editeng/fhgtitem.hxx>
35 #include <editeng/postitem.hxx>
36 #include <editeng/udlnitem.hxx>
37 #include <editeng/wghtitem.hxx>
38 #include <editeng/crsditem.hxx>
39 #include <editeng/wrlmitem.hxx>
40 #include <editeng/memberids.hrc>
41 #include <svl/itempool.hxx>
42 
43 #include <editeng/unofdesc.hxx>
44 
45 using namespace ::rtl;
46 using namespace ::com::sun::star;
47 
48 
ConvertToFont(const awt::FontDescriptor & rDesc,Font & rFont)49 void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor& rDesc, Font& rFont )
50 {
51 	rFont.SetName( rDesc.Name );
52 	rFont.SetStyleName( rDesc.StyleName );
53 	rFont.SetSize( Size( rDesc.Width, rDesc.Height ) );
54 	rFont.SetFamily( (FontFamily)rDesc.Family );
55 	rFont.SetCharSet( (CharSet)rDesc.CharSet );
56 	rFont.SetPitch( (FontPitch)rDesc.Pitch );
57 	rFont.SetOrientation( (short)(rDesc.Orientation*10) );
58 	rFont.SetKerning( rDesc.Kerning );
59 	rFont.SetWeight( VCLUnoHelper::ConvertFontWeight(rDesc.Weight) );
60 	rFont.SetItalic( (FontItalic)rDesc.Slant );
61 	rFont.SetUnderline( (FontUnderline)rDesc.Underline );
62 	rFont.SetStrikeout( (FontStrikeout)rDesc.Strikeout );
63 	rFont.SetWordLineMode( rDesc.WordLineMode );
64 }
65 
ConvertFromFont(const Font & rFont,awt::FontDescriptor & rDesc)66 void SvxUnoFontDescriptor::ConvertFromFont( const Font& rFont, awt::FontDescriptor& rDesc )
67 {
68 	rDesc.Name = rFont.GetName();
69 	rDesc.StyleName = rFont.GetStyleName();
70 	rDesc.Width = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Width());
71 	rDesc.Height = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Height());
72 	rDesc.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
73 	rDesc.CharSet = rFont.GetCharSet();
74 	rDesc.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
75 	rDesc.Orientation = static_cast< float >(rFont.GetOrientation() / 10);
76 	rDesc.Kerning = rFont.IsKerning();
77 	rDesc.Weight = VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
78 	rDesc.Slant = (awt::FontSlant)rFont.GetItalic();
79 	rDesc.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
80 	rDesc.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
81 	rDesc.WordLineMode = rFont.IsWordLineMode();
82 }
83 
FillItemSet(const awt::FontDescriptor & rDesc,SfxItemSet & rSet)84 void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor& rDesc, SfxItemSet& rSet )
85 {
86 	uno::Any aTemp;
87 
88 	{
89 		SvxFontItem aFontItem( EE_CHAR_FONTINFO );
90         aFontItem.SetFamilyName( rDesc.Name);
91         aFontItem.SetStyleName( rDesc.StyleName);
92         aFontItem.SetFamily( (FontFamily)rDesc.Family);
93         aFontItem.SetCharSet( rDesc.CharSet );
94         aFontItem.SetPitch( (FontPitch)rDesc.Pitch);
95 		rSet.Put(aFontItem);
96 	}
97 
98 	{
99 		SvxFontHeightItem aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT );
100 		aTemp <<= (float)rDesc.Height;
101 		((SfxPoolItem*)&aFontHeightItem)->PutValue( aTemp, MID_FONTHEIGHT|CONVERT_TWIPS );
102 		rSet.Put(aFontHeightItem);
103 	}
104 
105 	{
106 		SvxPostureItem aPostureItem( (FontItalic)0, EE_CHAR_ITALIC );
107 		aTemp <<= rDesc.Slant;
108 		((SfxPoolItem*)&aPostureItem)->PutValue( aTemp, MID_POSTURE );
109 		rSet.Put(aPostureItem);
110 	}
111 
112 	{
113 		SvxUnderlineItem aUnderlineItem( (FontUnderline)0, EE_CHAR_UNDERLINE );
114 		aTemp <<= (sal_Int16)rDesc.Underline;
115 		((SfxPoolItem*)&aUnderlineItem)->PutValue( aTemp, MID_TL_STYLE );
116 		rSet.Put( aUnderlineItem );
117 	}
118 
119 	{
120 		SvxWeightItem aWeightItem( (FontWeight)0, EE_CHAR_WEIGHT );
121 		aTemp <<= rDesc.Weight;
122 		((SfxPoolItem*)&aWeightItem)->PutValue( aTemp, MID_WEIGHT );
123 		rSet.Put( aWeightItem );
124 	}
125 
126 	{
127 		SvxCrossedOutItem aCrossedOutItem( (FontStrikeout)0, EE_CHAR_STRIKEOUT );
128 		aTemp <<= rDesc.Strikeout;
129 		((SfxPoolItem*)&aCrossedOutItem)->PutValue( aTemp, MID_CROSS_OUT );
130 		rSet.Put( aCrossedOutItem );
131 	}
132 
133 	{
134 		SvxWordLineModeItem aWLMItem( rDesc.WordLineMode, EE_CHAR_WLM );
135 		rSet.Put( aWLMItem );
136 	}
137 }
138 
FillFromItemSet(const SfxItemSet & rSet,awt::FontDescriptor & rDesc)139 void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet& rSet, awt::FontDescriptor& rDesc )
140 {
141 	const SfxPoolItem* pItem = NULL;
142 	{
143 		SvxFontItem* pFontItem = (SvxFontItem*)&rSet.Get( EE_CHAR_FONTINFO, sal_True );
144 		rDesc.Name		= pFontItem->GetFamilyName();
145 		rDesc.StyleName	= pFontItem->GetStyleName();
146 		rDesc.Family	= sal::static_int_cast< sal_Int16 >(
147             pFontItem->GetFamily());
148 		rDesc.CharSet	= pFontItem->GetCharSet();
149 		rDesc.Pitch		= sal::static_int_cast< sal_Int16 >(
150             pFontItem->GetPitch());
151 	}
152 	{
153 		pItem = &rSet.Get( EE_CHAR_FONTHEIGHT, sal_True );
154 		uno::Any aHeight;
155 		if( pItem->QueryValue( aHeight, MID_FONTHEIGHT ) )
156 			aHeight >>= rDesc.Height;
157 	}
158 	{
159 		pItem = &rSet.Get( EE_CHAR_ITALIC, sal_True );
160 		uno::Any aFontSlant;
161 		if(pItem->QueryValue( aFontSlant, MID_POSTURE ))
162 			aFontSlant >>= rDesc.Slant;
163 	}
164 	{
165 		pItem = &rSet.Get( EE_CHAR_UNDERLINE, sal_True );
166 		uno::Any aUnderline;
167 		if(pItem->QueryValue( aUnderline, MID_TL_STYLE ))
168 			aUnderline >>= rDesc.Underline;
169 	}
170 	{
171 		pItem = &rSet.Get( EE_CHAR_WEIGHT, sal_True );
172 		uno::Any aWeight;
173 		if(pItem->QueryValue( aWeight, MID_WEIGHT ))
174 			aWeight >>= rDesc.Weight;
175 	}
176 	{
177 		pItem = &rSet.Get( EE_CHAR_STRIKEOUT, sal_True );
178 		uno::Any aStrikeOut;
179 		if(pItem->QueryValue( aStrikeOut, MID_CROSS_OUT ))
180 			aStrikeOut >>= rDesc.Strikeout;
181 	}
182 	{
183 		SvxWordLineModeItem* pWLMItem = (SvxWordLineModeItem*)&rSet.Get( EE_CHAR_WLM, sal_True );
184 		rDesc.WordLineMode = pWLMItem->GetValue();
185 	}
186 }
187 
188 #define CheckState( state ) \
189 	switch( state ) \
190 	{ \
191 	case SFX_ITEM_DONTCARE: \
192 	case SFX_ITEM_DISABLED: \
193 		return beans::PropertyState_AMBIGUOUS_VALUE; \
194 	case SFX_ITEM_READONLY: \
195 	case SFX_ITEM_SET: \
196 		return beans::PropertyState_DIRECT_VALUE; \
197 	}
198 
getPropertyState(const SfxItemSet & rSet)199 beans::PropertyState SvxUnoFontDescriptor::getPropertyState( const SfxItemSet& rSet )
200 {
201 	CheckState(rSet.GetItemState( EE_CHAR_FONTINFO, sal_False ));
202 	CheckState(rSet.GetItemState( EE_CHAR_FONTHEIGHT, sal_False ));
203 	CheckState(rSet.GetItemState( EE_CHAR_ITALIC, sal_False ));
204 	CheckState(rSet.GetItemState( EE_CHAR_UNDERLINE, sal_False ));
205 	CheckState(rSet.GetItemState( EE_CHAR_WEIGHT, sal_False ));
206 	CheckState(rSet.GetItemState( EE_CHAR_STRIKEOUT, sal_False ));
207 	CheckState(rSet.GetItemState( EE_CHAR_WLM, sal_False ));
208 
209 	return beans::PropertyState_DEFAULT_VALUE;
210 }
211 
setPropertyToDefault(SfxItemSet & rSet)212 void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet& rSet )
213 {
214 	rSet.InvalidateItem( EE_CHAR_FONTINFO );
215 	rSet.InvalidateItem( EE_CHAR_FONTHEIGHT );
216 	rSet.InvalidateItem( EE_CHAR_ITALIC );
217 	rSet.InvalidateItem( EE_CHAR_UNDERLINE );
218 	rSet.InvalidateItem( EE_CHAR_WEIGHT );
219 	rSet.InvalidateItem( EE_CHAR_STRIKEOUT );
220 	rSet.InvalidateItem( EE_CHAR_WLM );
221 }
222 
getPropertyDefault(SfxItemPool * pPool)223 uno::Any SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool* pPool )
224 {
225 	SfxItemSet aSet( *pPool, EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
226 							 EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT,
227 							 EE_CHAR_ITALIC, EE_CHAR_ITALIC,
228 							 EE_CHAR_UNDERLINE, EE_CHAR_UNDERLINE,
229 							 EE_CHAR_WEIGHT, EE_CHAR_WEIGHT,
230 							 EE_CHAR_STRIKEOUT, EE_CHAR_STRIKEOUT,
231 							 EE_CHAR_WLM, EE_CHAR_WLM, 0 );
232 
233 	uno::Any aAny;
234 
235 	if(!pPool->IsWhich(EE_CHAR_FONTINFO)||
236 		!pPool->IsWhich(EE_CHAR_FONTHEIGHT)||
237 		!pPool->IsWhich(EE_CHAR_ITALIC)||
238 		!pPool->IsWhich(EE_CHAR_UNDERLINE)||
239 		!pPool->IsWhich(EE_CHAR_WEIGHT)||
240 		!pPool->IsWhich(EE_CHAR_STRIKEOUT)||
241 		!pPool->IsWhich(EE_CHAR_WLM))
242 		return aAny;
243 
244 	aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTINFO));
245 	aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTHEIGHT));
246 	aSet.Put(pPool->GetDefaultItem(EE_CHAR_ITALIC));
247 	aSet.Put(pPool->GetDefaultItem(EE_CHAR_UNDERLINE));
248 	aSet.Put(pPool->GetDefaultItem(EE_CHAR_WEIGHT));
249 	aSet.Put(pPool->GetDefaultItem(EE_CHAR_STRIKEOUT));
250 	aSet.Put(pPool->GetDefaultItem(EE_CHAR_WLM));
251 
252 	awt::FontDescriptor aDesc;
253 
254 	FillFromItemSet( aSet, aDesc );
255 
256 	aAny <<= aDesc;
257 
258 	return aAny;
259 }
260 
261 
262 
263