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>
23 #include <com/sun/star/awt/FontDescriptor.hpp>
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.h>
33 #include <svl/itempool.hxx>
34 #include <vcl/font.hxx>
35 #include <vcl/unohelp.hxx>
36 #include <tools/gen.hxx>
38 #include <editeng/unofdesc.hxx>
40 using namespace ::com::sun::star
;
43 void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor
& rDesc
, vcl::Font
& rFont
)
45 rFont
.SetFamilyName( rDesc
.Name
);
46 rFont
.SetStyleName( rDesc
.StyleName
);
47 rFont
.SetFontSize( Size( rDesc
.Width
, rDesc
.Height
) );
48 rFont
.SetFamily( static_cast<FontFamily
>(rDesc
.Family
) );
49 rFont
.SetCharSet( static_cast<rtl_TextEncoding
>(rDesc
.CharSet
) );
50 rFont
.SetPitch( static_cast<FontPitch
>(rDesc
.Pitch
) );
51 rFont
.SetOrientation( Degree10(static_cast<sal_Int16
>(rDesc
.Orientation
*10)) );
52 rFont
.SetKerning( rDesc
.Kerning
? FontKerning::FontSpecific
: FontKerning::NONE
);
53 rFont
.SetWeight( vcl::unohelper::ConvertFontWeight(rDesc
.Weight
) );
54 rFont
.SetItalic( static_cast<FontItalic
>(rDesc
.Slant
) );
55 rFont
.SetUnderline( static_cast<FontLineStyle
>(rDesc
.Underline
) );
56 rFont
.SetStrikeout( static_cast<FontStrikeout
>(rDesc
.Strikeout
) );
57 rFont
.SetWordLineMode( rDesc
.WordLineMode
);
60 void SvxUnoFontDescriptor::ConvertFromFont( const vcl::Font
& rFont
, awt::FontDescriptor
& rDesc
)
62 rDesc
.Name
= rFont
.GetFamilyName();
63 rDesc
.StyleName
= rFont
.GetStyleName();
64 rDesc
.Width
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFontSize().Width());
65 rDesc
.Height
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFontSize().Height());
66 rDesc
.Family
= sal::static_int_cast
< sal_Int16
>(rFont
.GetFamilyType());
67 rDesc
.CharSet
= rFont
.GetCharSet();
68 rDesc
.Pitch
= sal::static_int_cast
< sal_Int16
>(rFont
.GetPitch());
69 rDesc
.Orientation
= static_cast< float >(rFont
.GetOrientation().get() / 10);
70 rDesc
.Kerning
= rFont
.IsKerning();
71 rDesc
.Weight
= vcl::unohelper::ConvertFontWeight( rFont
.GetWeight() );
72 rDesc
.Slant
= vcl::unohelper::ConvertFontSlant( rFont
.GetItalic() );
73 rDesc
.Underline
= sal::static_int_cast
< sal_Int16
>(rFont
.GetUnderline());
74 rDesc
.Strikeout
= sal::static_int_cast
< sal_Int16
>(rFont
.GetStrikeout());
75 rDesc
.WordLineMode
= rFont
.IsWordLineMode();
78 void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor
& rDesc
, SfxItemSet
& rSet
)
83 SvxFontItem
aFontItem( EE_CHAR_FONTINFO
);
84 aFontItem
.SetFamilyName( rDesc
.Name
);
85 aFontItem
.SetStyleName( rDesc
.StyleName
);
86 aFontItem
.SetFamily( static_cast<FontFamily
>(rDesc
.Family
));
87 aFontItem
.SetCharSet( rDesc
.CharSet
);
88 aFontItem
.SetPitch( static_cast<FontPitch
>(rDesc
.Pitch
));
93 SvxFontHeightItem
aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT
);
94 aTemp
<<= static_cast<float>(rDesc
.Height
);
95 static_cast<SfxPoolItem
*>(&aFontHeightItem
)->PutValue( aTemp
, MID_FONTHEIGHT
|CONVERT_TWIPS
);
96 rSet
.Put(aFontHeightItem
);
100 SvxPostureItem
aPostureItem( ITALIC_NONE
, EE_CHAR_ITALIC
);
101 aTemp
<<= rDesc
.Slant
;
102 static_cast<SfxPoolItem
*>(&aPostureItem
)->PutValue( aTemp
, MID_POSTURE
);
103 rSet
.Put(aPostureItem
);
107 SvxUnderlineItem
aUnderlineItem( LINESTYLE_NONE
, EE_CHAR_UNDERLINE
);
108 aTemp
<<= rDesc
.Underline
;
109 static_cast<SfxPoolItem
*>(&aUnderlineItem
)->PutValue( aTemp
, MID_TL_STYLE
);
110 rSet
.Put( aUnderlineItem
);
114 SvxWeightItem
aWeightItem( WEIGHT_DONTKNOW
, EE_CHAR_WEIGHT
);
115 aTemp
<<= rDesc
.Weight
;
116 static_cast<SfxPoolItem
*>(&aWeightItem
)->PutValue( aTemp
, MID_WEIGHT
);
117 rSet
.Put( aWeightItem
);
121 SvxCrossedOutItem
aCrossedOutItem( STRIKEOUT_NONE
, EE_CHAR_STRIKEOUT
);
122 aTemp
<<= rDesc
.Strikeout
;
123 static_cast<SfxPoolItem
*>(&aCrossedOutItem
)->PutValue( aTemp
, MID_CROSS_OUT
);
124 rSet
.Put( aCrossedOutItem
);
128 SvxWordLineModeItem
aWLMItem( rDesc
.WordLineMode
, EE_CHAR_WLM
);
129 rSet
.Put( aWLMItem
);
133 void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet
& rSet
, awt::FontDescriptor
& rDesc
)
135 const SfxPoolItem
* pItem
= nullptr;
137 const SvxFontItem
* pFontItem
= &rSet
.Get( EE_CHAR_FONTINFO
);
138 rDesc
.Name
= pFontItem
->GetFamilyName();
139 rDesc
.StyleName
= pFontItem
->GetStyleName();
140 rDesc
.Family
= sal::static_int_cast
< sal_Int16
>(
141 pFontItem
->GetFamily());
142 rDesc
.CharSet
= pFontItem
->GetCharSet();
143 rDesc
.Pitch
= sal::static_int_cast
< sal_Int16
>(
144 pFontItem
->GetPitch());
147 pItem
= &rSet
.Get( EE_CHAR_FONTHEIGHT
);
149 if( pItem
->QueryValue( aHeight
, MID_FONTHEIGHT
) )
150 aHeight
>>= rDesc
.Height
;
153 pItem
= &rSet
.Get( EE_CHAR_ITALIC
);
155 if(pItem
->QueryValue( aFontSlant
, MID_POSTURE
))
156 aFontSlant
>>= rDesc
.Slant
;
159 pItem
= &rSet
.Get( EE_CHAR_UNDERLINE
);
161 if(pItem
->QueryValue( aUnderline
, MID_TL_STYLE
))
162 aUnderline
>>= rDesc
.Underline
;
165 pItem
= &rSet
.Get( EE_CHAR_WEIGHT
);
167 if(pItem
->QueryValue( aWeight
, MID_WEIGHT
))
168 aWeight
>>= rDesc
.Weight
;
171 pItem
= &rSet
.Get( EE_CHAR_STRIKEOUT
);
173 if(pItem
->QueryValue( aStrikeOut
, MID_CROSS_OUT
))
174 aStrikeOut
>>= rDesc
.Strikeout
;
177 const SvxWordLineModeItem
* pWLMItem
= &rSet
.Get( EE_CHAR_WLM
);
178 rDesc
.WordLineMode
= pWLMItem
->GetValue();
182 void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet
& rSet
)
184 rSet
.InvalidateItem( EE_CHAR_FONTINFO
);
185 rSet
.InvalidateItem( EE_CHAR_FONTHEIGHT
);
186 rSet
.InvalidateItem( EE_CHAR_ITALIC
);
187 rSet
.InvalidateItem( EE_CHAR_UNDERLINE
);
188 rSet
.InvalidateItem( EE_CHAR_WEIGHT
);
189 rSet
.InvalidateItem( EE_CHAR_STRIKEOUT
);
190 rSet
.InvalidateItem( EE_CHAR_WLM
);
193 uno::Any
SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool
* pPool
)
196 EE_CHAR_FONTINFO
, EE_CHAR_FONTHEIGHT
,
197 EE_CHAR_WEIGHT
, EE_CHAR_ITALIC
,
198 EE_CHAR_WLM
, EE_CHAR_WLM
> aSet(*pPool
);
202 if(!SfxItemPool::IsWhich(EE_CHAR_FONTINFO
)||
203 !SfxItemPool::IsWhich(EE_CHAR_FONTHEIGHT
)||
204 !SfxItemPool::IsWhich(EE_CHAR_ITALIC
)||
205 !SfxItemPool::IsWhich(EE_CHAR_UNDERLINE
)||
206 !SfxItemPool::IsWhich(EE_CHAR_WEIGHT
)||
207 !SfxItemPool::IsWhich(EE_CHAR_STRIKEOUT
)||
208 !SfxItemPool::IsWhich(EE_CHAR_WLM
))
211 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_FONTINFO
));
212 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_FONTHEIGHT
));
213 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_ITALIC
));
214 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_UNDERLINE
));
215 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_WEIGHT
));
216 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_STRIKEOUT
));
217 aSet
.Put(pPool
->GetDefaultItem(EE_CHAR_WLM
));
219 awt::FontDescriptor aDesc
;
221 FillFromItemSet( aSet
, aDesc
);
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */