Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <editeng/eeitem.hxx>
22 : #include <com/sun/star/uno/Any.hxx>
23 :
24 : #include <toolkit/helper/vclunohelper.hxx>
25 : #include <editeng/fontitem.hxx>
26 : #include <editeng/fhgtitem.hxx>
27 : #include <editeng/postitem.hxx>
28 : #include <editeng/udlnitem.hxx>
29 : #include <editeng/wghtitem.hxx>
30 : #include <editeng/crossedoutitem.hxx>
31 : #include <editeng/wrlmitem.hxx>
32 : #include <editeng/memberids.hrc>
33 : #include <svl/itempool.hxx>
34 :
35 : #include <editeng/unofdesc.hxx>
36 : #include <editeng/svxfont.hxx>
37 :
38 : using namespace ::rtl;
39 : using namespace ::com::sun::star;
40 :
41 :
42 0 : void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor& rDesc, Font& rFont )
43 : {
44 0 : rFont.SetName( rDesc.Name );
45 0 : rFont.SetStyleName( rDesc.StyleName );
46 0 : rFont.SetSize( Size( rDesc.Width, rDesc.Height ) );
47 0 : rFont.SetFamily( (FontFamily)rDesc.Family );
48 0 : rFont.SetCharSet( (rtl_TextEncoding)rDesc.CharSet );
49 0 : rFont.SetPitch( (FontPitch)rDesc.Pitch );
50 0 : rFont.SetOrientation( (short)(rDesc.Orientation*10) );
51 0 : rFont.SetKerning( rDesc.Kerning );
52 0 : rFont.SetWeight( VCLUnoHelper::ConvertFontWeight(rDesc.Weight) );
53 0 : rFont.SetItalic( (FontItalic)rDesc.Slant );
54 0 : rFont.SetUnderline( (FontUnderline)rDesc.Underline );
55 0 : rFont.SetStrikeout( (FontStrikeout)rDesc.Strikeout );
56 0 : rFont.SetWordLineMode( rDesc.WordLineMode );
57 0 : }
58 :
59 0 : void SvxUnoFontDescriptor::ConvertFromFont( const Font& rFont, awt::FontDescriptor& rDesc )
60 : {
61 0 : rDesc.Name = rFont.GetName();
62 0 : rDesc.StyleName = rFont.GetStyleName();
63 0 : rDesc.Width = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Width());
64 0 : rDesc.Height = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Height());
65 0 : rDesc.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
66 0 : rDesc.CharSet = rFont.GetCharSet();
67 0 : rDesc.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
68 0 : rDesc.Orientation = static_cast< float >(rFont.GetOrientation() / 10);
69 0 : rDesc.Kerning = rFont.IsKerning();
70 0 : rDesc.Weight = VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
71 0 : rDesc.Slant = (awt::FontSlant)rFont.GetItalic();
72 0 : rDesc.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
73 0 : rDesc.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
74 0 : rDesc.WordLineMode = rFont.IsWordLineMode();
75 0 : }
76 :
77 0 : void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor& rDesc, SfxItemSet& rSet )
78 : {
79 0 : uno::Any aTemp;
80 :
81 : {
82 0 : SvxFontItem aFontItem( EE_CHAR_FONTINFO );
83 0 : aFontItem.SetFamilyName( rDesc.Name);
84 0 : aFontItem.SetStyleName( rDesc.StyleName);
85 0 : aFontItem.SetFamily( (FontFamily)rDesc.Family);
86 0 : aFontItem.SetCharSet( rDesc.CharSet );
87 0 : aFontItem.SetPitch( (FontPitch)rDesc.Pitch);
88 0 : rSet.Put(aFontItem);
89 : }
90 :
91 : {
92 0 : SvxFontHeightItem aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT );
93 0 : aTemp <<= (float)rDesc.Height;
94 0 : ((SfxPoolItem*)&aFontHeightItem)->PutValue( aTemp, MID_FONTHEIGHT|CONVERT_TWIPS );
95 0 : rSet.Put(aFontHeightItem);
96 : }
97 :
98 : {
99 0 : SvxPostureItem aPostureItem( (FontItalic)0, EE_CHAR_ITALIC );
100 0 : aTemp <<= rDesc.Slant;
101 0 : ((SfxPoolItem*)&aPostureItem)->PutValue( aTemp, MID_POSTURE );
102 0 : rSet.Put(aPostureItem);
103 : }
104 :
105 : {
106 0 : SvxUnderlineItem aUnderlineItem( (FontUnderline)0, EE_CHAR_UNDERLINE );
107 0 : aTemp <<= (sal_Int16)rDesc.Underline;
108 0 : ((SfxPoolItem*)&aUnderlineItem)->PutValue( aTemp, MID_TL_STYLE );
109 0 : rSet.Put( aUnderlineItem );
110 : }
111 :
112 : {
113 0 : SvxWeightItem aWeightItem( (FontWeight)0, EE_CHAR_WEIGHT );
114 0 : aTemp <<= rDesc.Weight;
115 0 : ((SfxPoolItem*)&aWeightItem)->PutValue( aTemp, MID_WEIGHT );
116 0 : rSet.Put( aWeightItem );
117 : }
118 :
119 : {
120 0 : SvxCrossedOutItem aCrossedOutItem( (FontStrikeout)0, EE_CHAR_STRIKEOUT );
121 0 : aTemp <<= rDesc.Strikeout;
122 0 : ((SfxPoolItem*)&aCrossedOutItem)->PutValue( aTemp, MID_CROSS_OUT );
123 0 : rSet.Put( aCrossedOutItem );
124 : }
125 :
126 : {
127 0 : SvxWordLineModeItem aWLMItem( rDesc.WordLineMode, EE_CHAR_WLM );
128 0 : rSet.Put( aWLMItem );
129 0 : }
130 0 : }
131 :
132 0 : void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet& rSet, awt::FontDescriptor& rDesc )
133 : {
134 0 : const SfxPoolItem* pItem = NULL;
135 : {
136 0 : SvxFontItem* pFontItem = (SvxFontItem*)&rSet.Get( EE_CHAR_FONTINFO, true );
137 0 : rDesc.Name = pFontItem->GetFamilyName();
138 0 : rDesc.StyleName = pFontItem->GetStyleName();
139 : rDesc.Family = sal::static_int_cast< sal_Int16 >(
140 0 : pFontItem->GetFamily());
141 0 : rDesc.CharSet = pFontItem->GetCharSet();
142 : rDesc.Pitch = sal::static_int_cast< sal_Int16 >(
143 0 : pFontItem->GetPitch());
144 : }
145 : {
146 0 : pItem = &rSet.Get( EE_CHAR_FONTHEIGHT, true );
147 0 : uno::Any aHeight;
148 0 : if( pItem->QueryValue( aHeight, MID_FONTHEIGHT ) )
149 0 : aHeight >>= rDesc.Height;
150 : }
151 : {
152 0 : pItem = &rSet.Get( EE_CHAR_ITALIC, true );
153 0 : uno::Any aFontSlant;
154 0 : if(pItem->QueryValue( aFontSlant, MID_POSTURE ))
155 0 : aFontSlant >>= rDesc.Slant;
156 : }
157 : {
158 0 : pItem = &rSet.Get( EE_CHAR_UNDERLINE, true );
159 0 : uno::Any aUnderline;
160 0 : if(pItem->QueryValue( aUnderline, MID_TL_STYLE ))
161 0 : aUnderline >>= rDesc.Underline;
162 : }
163 : {
164 0 : pItem = &rSet.Get( EE_CHAR_WEIGHT, true );
165 0 : uno::Any aWeight;
166 0 : if(pItem->QueryValue( aWeight, MID_WEIGHT ))
167 0 : aWeight >>= rDesc.Weight;
168 : }
169 : {
170 0 : pItem = &rSet.Get( EE_CHAR_STRIKEOUT, true );
171 0 : uno::Any aStrikeOut;
172 0 : if(pItem->QueryValue( aStrikeOut, MID_CROSS_OUT ))
173 0 : aStrikeOut >>= rDesc.Strikeout;
174 : }
175 : {
176 0 : SvxWordLineModeItem* pWLMItem = (SvxWordLineModeItem*)&rSet.Get( EE_CHAR_WLM, true );
177 0 : rDesc.WordLineMode = pWLMItem->GetValue();
178 : }
179 0 : }
180 :
181 0 : void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet& rSet )
182 : {
183 0 : rSet.InvalidateItem( EE_CHAR_FONTINFO );
184 0 : rSet.InvalidateItem( EE_CHAR_FONTHEIGHT );
185 0 : rSet.InvalidateItem( EE_CHAR_ITALIC );
186 0 : rSet.InvalidateItem( EE_CHAR_UNDERLINE );
187 0 : rSet.InvalidateItem( EE_CHAR_WEIGHT );
188 0 : rSet.InvalidateItem( EE_CHAR_STRIKEOUT );
189 0 : rSet.InvalidateItem( EE_CHAR_WLM );
190 0 : }
191 :
192 0 : uno::Any SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool* pPool )
193 : {
194 : SfxItemSet aSet( *pPool, EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
195 : EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT,
196 : EE_CHAR_ITALIC, EE_CHAR_ITALIC,
197 : EE_CHAR_UNDERLINE, EE_CHAR_UNDERLINE,
198 : EE_CHAR_WEIGHT, EE_CHAR_WEIGHT,
199 : EE_CHAR_STRIKEOUT, EE_CHAR_STRIKEOUT,
200 0 : EE_CHAR_WLM, EE_CHAR_WLM, 0 );
201 :
202 0 : uno::Any aAny;
203 :
204 0 : if(!pPool->IsWhich(EE_CHAR_FONTINFO)||
205 0 : !pPool->IsWhich(EE_CHAR_FONTHEIGHT)||
206 0 : !pPool->IsWhich(EE_CHAR_ITALIC)||
207 0 : !pPool->IsWhich(EE_CHAR_UNDERLINE)||
208 0 : !pPool->IsWhich(EE_CHAR_WEIGHT)||
209 0 : !pPool->IsWhich(EE_CHAR_STRIKEOUT)||
210 0 : !pPool->IsWhich(EE_CHAR_WLM))
211 0 : return aAny;
212 :
213 0 : aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTINFO));
214 0 : aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTHEIGHT));
215 0 : aSet.Put(pPool->GetDefaultItem(EE_CHAR_ITALIC));
216 0 : aSet.Put(pPool->GetDefaultItem(EE_CHAR_UNDERLINE));
217 0 : aSet.Put(pPool->GetDefaultItem(EE_CHAR_WEIGHT));
218 0 : aSet.Put(pPool->GetDefaultItem(EE_CHAR_STRIKEOUT));
219 0 : aSet.Put(pPool->GetDefaultItem(EE_CHAR_WLM));
220 :
221 0 : awt::FontDescriptor aDesc;
222 :
223 0 : FillFromItemSet( aSet, aDesc );
224 :
225 0 : aAny <<= aDesc;
226 :
227 0 : return aAny;
228 : }
229 :
230 :
231 :
232 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|