Bump for 3.6-28
[LibreOffice.git] / editeng / source / uno / unofdesc.cxx
blobae9981dfd348f21ff86688e2214d03c79cc5505c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <editeng/eeitem.hxx>
31 #include <com/sun/star/uno/Any.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <editeng/fontitem.hxx>
35 #include <editeng/fhgtitem.hxx>
36 #include <editeng/postitem.hxx>
37 #include <editeng/udlnitem.hxx>
38 #include <editeng/wghtitem.hxx>
39 #include <editeng/crsditem.hxx>
40 #include <editeng/wrlmitem.hxx>
41 #include <editeng/memberids.hrc>
42 #include <svl/itempool.hxx>
44 #include <editeng/unofdesc.hxx>
46 using namespace ::rtl;
47 using namespace ::com::sun::star;
50 void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor& rDesc, Font& rFont )
52 rFont.SetName( rDesc.Name );
53 rFont.SetStyleName( rDesc.StyleName );
54 rFont.SetSize( Size( rDesc.Width, rDesc.Height ) );
55 rFont.SetFamily( (FontFamily)rDesc.Family );
56 rFont.SetCharSet( (CharSet)rDesc.CharSet );
57 rFont.SetPitch( (FontPitch)rDesc.Pitch );
58 rFont.SetOrientation( (short)(rDesc.Orientation*10) );
59 rFont.SetKerning( rDesc.Kerning );
60 rFont.SetWeight( VCLUnoHelper::ConvertFontWeight(rDesc.Weight) );
61 rFont.SetItalic( (FontItalic)rDesc.Slant );
62 rFont.SetUnderline( (FontUnderline)rDesc.Underline );
63 rFont.SetStrikeout( (FontStrikeout)rDesc.Strikeout );
64 rFont.SetWordLineMode( rDesc.WordLineMode );
67 void SvxUnoFontDescriptor::ConvertFromFont( const Font& rFont, awt::FontDescriptor& rDesc )
69 rDesc.Name = rFont.GetName();
70 rDesc.StyleName = rFont.GetStyleName();
71 rDesc.Width = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Width());
72 rDesc.Height = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Height());
73 rDesc.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
74 rDesc.CharSet = rFont.GetCharSet();
75 rDesc.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
76 rDesc.Orientation = static_cast< float >(rFont.GetOrientation() / 10);
77 rDesc.Kerning = rFont.IsKerning();
78 rDesc.Weight = VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
79 rDesc.Slant = (awt::FontSlant)rFont.GetItalic();
80 rDesc.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
81 rDesc.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
82 rDesc.WordLineMode = rFont.IsWordLineMode();
85 void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor& rDesc, SfxItemSet& rSet )
87 uno::Any aTemp;
90 SvxFontItem aFontItem( EE_CHAR_FONTINFO );
91 aFontItem.SetFamilyName( rDesc.Name);
92 aFontItem.SetStyleName( rDesc.StyleName);
93 aFontItem.SetFamily( (FontFamily)rDesc.Family);
94 aFontItem.SetCharSet( rDesc.CharSet );
95 aFontItem.SetPitch( (FontPitch)rDesc.Pitch);
96 rSet.Put(aFontItem);
100 SvxFontHeightItem aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT );
101 aTemp <<= (float)rDesc.Height;
102 ((SfxPoolItem*)&aFontHeightItem)->PutValue( aTemp, MID_FONTHEIGHT|CONVERT_TWIPS );
103 rSet.Put(aFontHeightItem);
107 SvxPostureItem aPostureItem( (FontItalic)0, EE_CHAR_ITALIC );
108 aTemp <<= rDesc.Slant;
109 ((SfxPoolItem*)&aPostureItem)->PutValue( aTemp, MID_POSTURE );
110 rSet.Put(aPostureItem);
114 SvxUnderlineItem aUnderlineItem( (FontUnderline)0, EE_CHAR_UNDERLINE );
115 aTemp <<= (sal_Int16)rDesc.Underline;
116 ((SfxPoolItem*)&aUnderlineItem)->PutValue( aTemp, MID_TL_STYLE );
117 rSet.Put( aUnderlineItem );
121 SvxWeightItem aWeightItem( (FontWeight)0, EE_CHAR_WEIGHT );
122 aTemp <<= rDesc.Weight;
123 ((SfxPoolItem*)&aWeightItem)->PutValue( aTemp, MID_WEIGHT );
124 rSet.Put( aWeightItem );
128 SvxCrossedOutItem aCrossedOutItem( (FontStrikeout)0, EE_CHAR_STRIKEOUT );
129 aTemp <<= rDesc.Strikeout;
130 ((SfxPoolItem*)&aCrossedOutItem)->PutValue( aTemp, MID_CROSS_OUT );
131 rSet.Put( aCrossedOutItem );
135 SvxWordLineModeItem aWLMItem( rDesc.WordLineMode, EE_CHAR_WLM );
136 rSet.Put( aWLMItem );
140 void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet& rSet, awt::FontDescriptor& rDesc )
142 const SfxPoolItem* pItem = NULL;
144 SvxFontItem* pFontItem = (SvxFontItem*)&rSet.Get( EE_CHAR_FONTINFO, sal_True );
145 rDesc.Name = pFontItem->GetFamilyName();
146 rDesc.StyleName = pFontItem->GetStyleName();
147 rDesc.Family = sal::static_int_cast< sal_Int16 >(
148 pFontItem->GetFamily());
149 rDesc.CharSet = pFontItem->GetCharSet();
150 rDesc.Pitch = sal::static_int_cast< sal_Int16 >(
151 pFontItem->GetPitch());
154 pItem = &rSet.Get( EE_CHAR_FONTHEIGHT, sal_True );
155 uno::Any aHeight;
156 if( pItem->QueryValue( aHeight, MID_FONTHEIGHT ) )
157 aHeight >>= rDesc.Height;
160 pItem = &rSet.Get( EE_CHAR_ITALIC, sal_True );
161 uno::Any aFontSlant;
162 if(pItem->QueryValue( aFontSlant, MID_POSTURE ))
163 aFontSlant >>= rDesc.Slant;
166 pItem = &rSet.Get( EE_CHAR_UNDERLINE, sal_True );
167 uno::Any aUnderline;
168 if(pItem->QueryValue( aUnderline, MID_TL_STYLE ))
169 aUnderline >>= rDesc.Underline;
172 pItem = &rSet.Get( EE_CHAR_WEIGHT, sal_True );
173 uno::Any aWeight;
174 if(pItem->QueryValue( aWeight, MID_WEIGHT ))
175 aWeight >>= rDesc.Weight;
178 pItem = &rSet.Get( EE_CHAR_STRIKEOUT, sal_True );
179 uno::Any aStrikeOut;
180 if(pItem->QueryValue( aStrikeOut, MID_CROSS_OUT ))
181 aStrikeOut >>= rDesc.Strikeout;
184 SvxWordLineModeItem* pWLMItem = (SvxWordLineModeItem*)&rSet.Get( EE_CHAR_WLM, sal_True );
185 rDesc.WordLineMode = pWLMItem->GetValue();
189 void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet& rSet )
191 rSet.InvalidateItem( EE_CHAR_FONTINFO );
192 rSet.InvalidateItem( EE_CHAR_FONTHEIGHT );
193 rSet.InvalidateItem( EE_CHAR_ITALIC );
194 rSet.InvalidateItem( EE_CHAR_UNDERLINE );
195 rSet.InvalidateItem( EE_CHAR_WEIGHT );
196 rSet.InvalidateItem( EE_CHAR_STRIKEOUT );
197 rSet.InvalidateItem( EE_CHAR_WLM );
200 uno::Any SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool* pPool )
202 SfxItemSet aSet( *pPool, EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
203 EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT,
204 EE_CHAR_ITALIC, EE_CHAR_ITALIC,
205 EE_CHAR_UNDERLINE, EE_CHAR_UNDERLINE,
206 EE_CHAR_WEIGHT, EE_CHAR_WEIGHT,
207 EE_CHAR_STRIKEOUT, EE_CHAR_STRIKEOUT,
208 EE_CHAR_WLM, EE_CHAR_WLM, 0 );
210 uno::Any aAny;
212 if(!pPool->IsWhich(EE_CHAR_FONTINFO)||
213 !pPool->IsWhich(EE_CHAR_FONTHEIGHT)||
214 !pPool->IsWhich(EE_CHAR_ITALIC)||
215 !pPool->IsWhich(EE_CHAR_UNDERLINE)||
216 !pPool->IsWhich(EE_CHAR_WEIGHT)||
217 !pPool->IsWhich(EE_CHAR_STRIKEOUT)||
218 !pPool->IsWhich(EE_CHAR_WLM))
219 return aAny;
221 aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTINFO));
222 aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTHEIGHT));
223 aSet.Put(pPool->GetDefaultItem(EE_CHAR_ITALIC));
224 aSet.Put(pPool->GetDefaultItem(EE_CHAR_UNDERLINE));
225 aSet.Put(pPool->GetDefaultItem(EE_CHAR_WEIGHT));
226 aSet.Put(pPool->GetDefaultItem(EE_CHAR_STRIKEOUT));
227 aSet.Put(pPool->GetDefaultItem(EE_CHAR_WLM));
229 awt::FontDescriptor aDesc;
231 FillFromItemSet( aSet, aDesc );
233 aAny <<= aDesc;
235 return aAny;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */