1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <editeng/eeitem.hxx>
22 #include <com/sun/star/uno/Any.hxx>
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>
35 #include <editeng/unofdesc.hxx>
36 #include <editeng/svxfont.hxx>
38 using namespace ::com::sun::star
;
41 void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor
& rDesc
, vcl::Font
& rFont
)
43 rFont
.SetName( rDesc
.Name
);
44 rFont
.SetStyleName( rDesc
.StyleName
);
45 rFont
.SetSize( Size( rDesc
.Width
, rDesc
.Height
) );
46 rFont
.SetFamily( (FontFamily
)rDesc
.Family
);
47 rFont
.SetCharSet( (rtl_TextEncoding
)rDesc
.CharSet
);
48 rFont
.SetPitch( (FontPitch
)rDesc
.Pitch
);
49 rFont
.SetOrientation( (short)(rDesc
.Orientation
*10) );
50 rFont
.SetKerning( rDesc
.Kerning
? FontKerning::FontSpecific
: FontKerning::NONE
);
51 rFont
.SetWeight( VCLUnoHelper::ConvertFontWeight(rDesc
.Weight
) );
52 rFont
.SetItalic( (FontItalic
)rDesc
.Slant
);
53 rFont
.SetUnderline( (FontUnderline
)rDesc
.Underline
);
54 rFont
.SetStrikeout( (FontStrikeout
)rDesc
.Strikeout
);
55 rFont
.SetWordLineMode( rDesc
.WordLineMode
);
58 void SvxUnoFontDescriptor::ConvertFromFont( const vcl::Font
& rFont
, awt::FontDescriptor
& rDesc
)
60 rDesc
.Name
= rFont
.GetName();
61 rDesc
.StyleName
= rFont
.GetStyleName();
62 rDesc
.Width
= sal::static_int_cast
< sal_Int16
>(rFont
.GetSize().Width());
63 rDesc
.Height
= sal::static_int_cast
< sal_Int16
>(rFont
.GetSize().Height());
64 rDesc
.Family
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFamily());
65 rDesc
.CharSet
= rFont
.GetCharSet();
66 rDesc
.Pitch
= sal::static_int_cast
< sal_Int16
>(rFont
.GetPitch());
67 rDesc
.Orientation
= static_cast< float >(rFont
.GetOrientation() / 10);
68 rDesc
.Kerning
= rFont
.IsKerning();
69 rDesc
.Weight
= VCLUnoHelper::ConvertFontWeight( rFont
.GetWeight() );
70 rDesc
.Slant
= VCLUnoHelper::ConvertFontSlant( rFont
.GetItalic() );
71 rDesc
.Underline
= sal::static_int_cast
< sal_Int16
>(rFont
.GetUnderline());
72 rDesc
.Strikeout
= sal::static_int_cast
< sal_Int16
>(rFont
.GetStrikeout());
73 rDesc
.WordLineMode
= rFont
.IsWordLineMode();
76 void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor
& rDesc
, SfxItemSet
& rSet
)
81 SvxFontItem
aFontItem( EE_CHAR_FONTINFO
);
82 aFontItem
.SetFamilyName( rDesc
.Name
);
83 aFontItem
.SetStyleName( rDesc
.StyleName
);
84 aFontItem
.SetFamily( (FontFamily
)rDesc
.Family
);
85 aFontItem
.SetCharSet( rDesc
.CharSet
);
86 aFontItem
.SetPitch( (FontPitch
)rDesc
.Pitch
);
91 SvxFontHeightItem
aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT
);
92 aTemp
<<= (float)rDesc
.Height
;
93 ((SfxPoolItem
*)&aFontHeightItem
)->PutValue( aTemp
, MID_FONTHEIGHT
|CONVERT_TWIPS
);
94 rSet
.Put(aFontHeightItem
);
98 SvxPostureItem
aPostureItem( (FontItalic
)0, EE_CHAR_ITALIC
);
99 aTemp
<<= rDesc
.Slant
;
100 ((SfxPoolItem
*)&aPostureItem
)->PutValue( aTemp
, MID_POSTURE
);
101 rSet
.Put(aPostureItem
);
105 SvxUnderlineItem
aUnderlineItem( (FontUnderline
)0, EE_CHAR_UNDERLINE
);
106 aTemp
<<= (sal_Int16
)rDesc
.Underline
;
107 ((SfxPoolItem
*)&aUnderlineItem
)->PutValue( aTemp
, MID_TL_STYLE
);
108 rSet
.Put( aUnderlineItem
);
112 SvxWeightItem
aWeightItem( (FontWeight
)0, EE_CHAR_WEIGHT
);
113 aTemp
<<= rDesc
.Weight
;
114 ((SfxPoolItem
*)&aWeightItem
)->PutValue( aTemp
, MID_WEIGHT
);
115 rSet
.Put( aWeightItem
);
119 SvxCrossedOutItem
aCrossedOutItem( (FontStrikeout
)0, EE_CHAR_STRIKEOUT
);
120 aTemp
<<= rDesc
.Strikeout
;
121 ((SfxPoolItem
*)&aCrossedOutItem
)->PutValue( aTemp
, MID_CROSS_OUT
);
122 rSet
.Put( aCrossedOutItem
);
126 SvxWordLineModeItem
aWLMItem( rDesc
.WordLineMode
, EE_CHAR_WLM
);
127 rSet
.Put( aWLMItem
);
131 void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet
& rSet
, awt::FontDescriptor
& rDesc
)
133 const SfxPoolItem
* pItem
= NULL
;
135 const SvxFontItem
* pFontItem
= static_cast<const SvxFontItem
*>(&rSet
.Get( EE_CHAR_FONTINFO
, true ));
136 rDesc
.Name
= pFontItem
->GetFamilyName();
137 rDesc
.StyleName
= pFontItem
->GetStyleName();
138 rDesc
.Family
= sal::static_int_cast
< sal_Int16
>(
139 pFontItem
->GetFamily());
140 rDesc
.CharSet
= pFontItem
->GetCharSet();
141 rDesc
.Pitch
= sal::static_int_cast
< sal_Int16
>(
142 pFontItem
->GetPitch());
145 pItem
= &rSet
.Get( EE_CHAR_FONTHEIGHT
, true );
147 if( pItem
->QueryValue( aHeight
, MID_FONTHEIGHT
) )
148 aHeight
>>= rDesc
.Height
;
151 pItem
= &rSet
.Get( EE_CHAR_ITALIC
, true );
153 if(pItem
->QueryValue( aFontSlant
, MID_POSTURE
))
154 aFontSlant
>>= rDesc
.Slant
;
157 pItem
= &rSet
.Get( EE_CHAR_UNDERLINE
, true );
159 if(pItem
->QueryValue( aUnderline
, MID_TL_STYLE
))
160 aUnderline
>>= rDesc
.Underline
;
163 pItem
= &rSet
.Get( EE_CHAR_WEIGHT
, true );
165 if(pItem
->QueryValue( aWeight
, MID_WEIGHT
))
166 aWeight
>>= rDesc
.Weight
;
169 pItem
= &rSet
.Get( EE_CHAR_STRIKEOUT
, true );
171 if(pItem
->QueryValue( aStrikeOut
, MID_CROSS_OUT
))
172 aStrikeOut
>>= rDesc
.Strikeout
;
175 const SvxWordLineModeItem
* pWLMItem
= static_cast<const SvxWordLineModeItem
*>(&rSet
.Get( EE_CHAR_WLM
, true ));
176 rDesc
.WordLineMode
= pWLMItem
->GetValue();
180 void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet
& rSet
)
182 rSet
.InvalidateItem( EE_CHAR_FONTINFO
);
183 rSet
.InvalidateItem( EE_CHAR_FONTHEIGHT
);
184 rSet
.InvalidateItem( EE_CHAR_ITALIC
);
185 rSet
.InvalidateItem( EE_CHAR_UNDERLINE
);
186 rSet
.InvalidateItem( EE_CHAR_WEIGHT
);
187 rSet
.InvalidateItem( EE_CHAR_STRIKEOUT
);
188 rSet
.InvalidateItem( EE_CHAR_WLM
);
191 uno::Any
SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool
* pPool
)
193 SfxItemSet
aSet( *pPool
, EE_CHAR_FONTINFO
, EE_CHAR_FONTINFO
,
194 EE_CHAR_FONTHEIGHT
, EE_CHAR_FONTHEIGHT
,
195 EE_CHAR_ITALIC
, EE_CHAR_ITALIC
,
196 EE_CHAR_UNDERLINE
, EE_CHAR_UNDERLINE
,
197 EE_CHAR_WEIGHT
, EE_CHAR_WEIGHT
,
198 EE_CHAR_STRIKEOUT
, EE_CHAR_STRIKEOUT
,
199 EE_CHAR_WLM
, EE_CHAR_WLM
, 0 );
203 if(!SfxItemPool::IsWhich(EE_CHAR_FONTINFO
)||
204 !SfxItemPool::IsWhich(EE_CHAR_FONTHEIGHT
)||
205 !SfxItemPool::IsWhich(EE_CHAR_ITALIC
)||
206 !SfxItemPool::IsWhich(EE_CHAR_UNDERLINE
)||
207 !SfxItemPool::IsWhich(EE_CHAR_WEIGHT
)||
208 !SfxItemPool::IsWhich(EE_CHAR_STRIKEOUT
)||
209 !SfxItemPool::IsWhich(EE_CHAR_WLM
))
212 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_FONTINFO
));
213 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_FONTHEIGHT
));
214 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_ITALIC
));
215 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_UNDERLINE
));
216 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_WEIGHT
));
217 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_STRIKEOUT
));
218 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_WLM
));
220 awt::FontDescriptor aDesc
;
222 FillFromItemSet( aSet
, aDesc
);
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */