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