/src/libreoffice/editeng/source/uno/unofdesc.cxx
Line | Count | Source |
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 | | #include <com/sun/star/awt/FontDescriptor.hpp> |
24 | | |
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/fntstyle.hxx> |
36 | | #include <vcl/unohelp.hxx> |
37 | | #include <tools/gen.hxx> |
38 | | |
39 | | #include <editeng/unofdesc.hxx> |
40 | | |
41 | | using namespace ::com::sun::star; |
42 | | |
43 | | |
44 | | void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor& rDesc, vcl::Font& rFont ) |
45 | 398k | { |
46 | 398k | rFont.SetFamilyName( rDesc.Name ); |
47 | 398k | rFont.SetStyleName( rDesc.StyleName ); |
48 | 398k | rFont.SetFontSize( Size( rDesc.Width, rDesc.Height ) ); |
49 | 398k | rFont.SetFamily( static_cast<FontFamily>(rDesc.Family) ); |
50 | 398k | rFont.SetCharSet( static_cast<rtl_TextEncoding>(rDesc.CharSet) ); |
51 | 398k | rFont.SetPitch( static_cast<FontPitch>(rDesc.Pitch) ); |
52 | 398k | rFont.SetOrientation( Degree10(static_cast<sal_Int16>(rDesc.Orientation*10)) ); |
53 | 398k | rFont.SetKerning( rDesc.Kerning ? FontKerning::FontSpecific : FontKerning::NONE ); |
54 | 398k | rFont.SetWeight( vcl::unohelper::ConvertFontWeight(rDesc.Weight) ); |
55 | 398k | rFont.SetItalic( static_cast<FontItalic>(rDesc.Slant) ); |
56 | 398k | rFont.SetUnderline( static_cast<FontLineStyle>(rDesc.Underline) ); |
57 | 398k | rFont.SetStrikeout( static_cast<FontStrikeout>(rDesc.Strikeout) ); |
58 | 398k | rFont.SetWordLineMode( rDesc.WordLineMode ); |
59 | 398k | } |
60 | | |
61 | | void SvxUnoFontDescriptor::ConvertFromFont( const vcl::Font& rFont, awt::FontDescriptor& rDesc ) |
62 | 751k | { |
63 | 751k | rDesc.Name = rFont.GetFamilyName(); |
64 | 751k | rDesc.StyleName = rFont.GetStyleName(); |
65 | 751k | rDesc.Width = sal::static_int_cast< sal_Int16 >(rFont.GetFontSize().Width()); |
66 | 751k | rDesc.Height = sal::static_int_cast< sal_Int16 >(rFont.GetFontSize().Height()); |
67 | 751k | rDesc.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType()); |
68 | 751k | rDesc.CharSet = rFont.GetCharSet(); |
69 | 751k | rDesc.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch()); |
70 | 751k | rDesc.Orientation = static_cast< float >(rFont.GetOrientation().get() / 10); |
71 | 751k | rDesc.Kerning = rFont.IsKerning(); |
72 | 751k | rDesc.Weight = vcl::unohelper::ConvertFontWeight( rFont.GetWeight() ); |
73 | 751k | rDesc.Slant = vcl::unohelper::ConvertFontSlant( rFont.GetItalic() ); |
74 | 751k | rDesc.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline()); |
75 | 751k | rDesc.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout()); |
76 | 751k | rDesc.WordLineMode = rFont.IsWordLineMode(); |
77 | 751k | } |
78 | | |
79 | | void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor& rDesc, SfxItemSet& rSet ) |
80 | 0 | { |
81 | 0 | uno::Any aTemp; |
82 | |
|
83 | 0 | { |
84 | 0 | SvxFontItem aFontItem( EE_CHAR_FONTINFO ); |
85 | 0 | aFontItem.SetFamilyName( rDesc.Name); |
86 | 0 | aFontItem.SetStyleName( rDesc.StyleName); |
87 | 0 | aFontItem.SetFamily( static_cast<FontFamily>(rDesc.Family)); |
88 | 0 | aFontItem.SetCharSet( rDesc.CharSet ); |
89 | 0 | aFontItem.SetPitch( static_cast<FontPitch>(rDesc.Pitch)); |
90 | 0 | rSet.Put(aFontItem); |
91 | 0 | } |
92 | |
|
93 | 0 | { |
94 | 0 | SvxFontHeightItem aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT ); |
95 | 0 | aTemp <<= static_cast<float>(rDesc.Height); |
96 | 0 | static_cast<SfxPoolItem*>(&aFontHeightItem)->PutValue( aTemp, MID_FONTHEIGHT|CONVERT_TWIPS ); |
97 | 0 | rSet.Put(aFontHeightItem); |
98 | 0 | } |
99 | |
|
100 | 0 | { |
101 | 0 | SvxPostureItem aPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ); |
102 | 0 | aTemp <<= rDesc.Slant; |
103 | 0 | static_cast<SfxPoolItem*>(&aPostureItem)->PutValue( aTemp, MID_POSTURE ); |
104 | 0 | rSet.Put(aPostureItem); |
105 | 0 | } |
106 | |
|
107 | 0 | { |
108 | 0 | SvxUnderlineItem aUnderlineItem( LINESTYLE_NONE, EE_CHAR_UNDERLINE ); |
109 | 0 | aTemp <<= rDesc.Underline; |
110 | 0 | static_cast<SfxPoolItem*>(&aUnderlineItem)->PutValue( aTemp, MID_TL_STYLE ); |
111 | 0 | rSet.Put( aUnderlineItem ); |
112 | 0 | } |
113 | |
|
114 | 0 | { |
115 | 0 | SvxWeightItem aWeightItem( WEIGHT_DONTKNOW, EE_CHAR_WEIGHT ); |
116 | 0 | aTemp <<= rDesc.Weight; |
117 | 0 | static_cast<SfxPoolItem*>(&aWeightItem)->PutValue( aTemp, MID_WEIGHT ); |
118 | 0 | rSet.Put( aWeightItem ); |
119 | 0 | } |
120 | |
|
121 | 0 | { |
122 | 0 | SvxCrossedOutItem aCrossedOutItem( STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ); |
123 | 0 | aTemp <<= rDesc.Strikeout; |
124 | 0 | static_cast<SfxPoolItem*>(&aCrossedOutItem)->PutValue( aTemp, MID_CROSS_OUT ); |
125 | 0 | rSet.Put( aCrossedOutItem ); |
126 | 0 | } |
127 | |
|
128 | 0 | { |
129 | 0 | SvxWordLineModeItem aWLMItem( rDesc.WordLineMode, EE_CHAR_WLM ); |
130 | 0 | rSet.Put( aWLMItem ); |
131 | 0 | } |
132 | 0 | } |
133 | | |
134 | | void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet& rSet, awt::FontDescriptor& rDesc ) |
135 | 0 | { |
136 | 0 | const SfxPoolItem* pItem = nullptr; |
137 | 0 | { |
138 | 0 | const SvxFontItem* pFontItem = &rSet.Get( EE_CHAR_FONTINFO ); |
139 | 0 | rDesc.Name = pFontItem->GetFamilyName(); |
140 | 0 | rDesc.StyleName = pFontItem->GetStyleName(); |
141 | 0 | rDesc.Family = sal::static_int_cast< sal_Int16 >( |
142 | 0 | pFontItem->GetFamily()); |
143 | 0 | rDesc.CharSet = pFontItem->GetCharSet(); |
144 | 0 | rDesc.Pitch = sal::static_int_cast< sal_Int16 >( |
145 | 0 | pFontItem->GetPitch()); |
146 | 0 | } |
147 | 0 | { |
148 | 0 | pItem = &rSet.Get( EE_CHAR_FONTHEIGHT ); |
149 | 0 | uno::Any aHeight; |
150 | 0 | if( pItem->QueryValue( aHeight, MID_FONTHEIGHT ) ) |
151 | 0 | aHeight >>= rDesc.Height; |
152 | 0 | } |
153 | 0 | { |
154 | 0 | pItem = &rSet.Get( EE_CHAR_ITALIC ); |
155 | 0 | uno::Any aFontSlant; |
156 | 0 | if(pItem->QueryValue( aFontSlant, MID_POSTURE )) |
157 | 0 | aFontSlant >>= rDesc.Slant; |
158 | 0 | } |
159 | 0 | { |
160 | 0 | pItem = &rSet.Get( EE_CHAR_UNDERLINE ); |
161 | 0 | uno::Any aUnderline; |
162 | 0 | if(pItem->QueryValue( aUnderline, MID_TL_STYLE )) |
163 | 0 | aUnderline >>= rDesc.Underline; |
164 | 0 | } |
165 | 0 | { |
166 | 0 | pItem = &rSet.Get( EE_CHAR_WEIGHT ); |
167 | 0 | uno::Any aWeight; |
168 | 0 | if(pItem->QueryValue( aWeight, MID_WEIGHT )) |
169 | 0 | aWeight >>= rDesc.Weight; |
170 | 0 | } |
171 | 0 | { |
172 | 0 | pItem = &rSet.Get( EE_CHAR_STRIKEOUT ); |
173 | 0 | uno::Any aStrikeOut; |
174 | 0 | if(pItem->QueryValue( aStrikeOut, MID_CROSS_OUT )) |
175 | 0 | aStrikeOut >>= rDesc.Strikeout; |
176 | 0 | } |
177 | 0 | { |
178 | 0 | const SvxWordLineModeItem* pWLMItem = &rSet.Get( EE_CHAR_WLM ); |
179 | 0 | rDesc.WordLineMode = pWLMItem->GetValue(); |
180 | 0 | } |
181 | 0 | } |
182 | | |
183 | | void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet& rSet ) |
184 | 0 | { |
185 | 0 | rSet.InvalidateItem( EE_CHAR_FONTINFO ); |
186 | 0 | rSet.InvalidateItem( EE_CHAR_FONTHEIGHT ); |
187 | 0 | rSet.InvalidateItem( EE_CHAR_ITALIC ); |
188 | 0 | rSet.InvalidateItem( EE_CHAR_UNDERLINE ); |
189 | 0 | rSet.InvalidateItem( EE_CHAR_WEIGHT ); |
190 | 0 | rSet.InvalidateItem( EE_CHAR_STRIKEOUT ); |
191 | 0 | rSet.InvalidateItem( EE_CHAR_WLM ); |
192 | 0 | } |
193 | | |
194 | | uno::Any SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool* pPool ) |
195 | 0 | { |
196 | 0 | SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet< |
197 | 0 | EE_CHAR_FONTINFO, EE_CHAR_FONTHEIGHT, |
198 | 0 | EE_CHAR_WEIGHT, EE_CHAR_ITALIC, |
199 | 0 | EE_CHAR_WLM, EE_CHAR_WLM> (*pPool)); |
200 | |
|
201 | 0 | uno::Any aAny; |
202 | |
|
203 | 0 | if(!SfxItemPool::IsWhich(EE_CHAR_FONTINFO)|| |
204 | 0 | !SfxItemPool::IsWhich(EE_CHAR_FONTHEIGHT)|| |
205 | 0 | !SfxItemPool::IsWhich(EE_CHAR_ITALIC)|| |
206 | 0 | !SfxItemPool::IsWhich(EE_CHAR_UNDERLINE)|| |
207 | 0 | !SfxItemPool::IsWhich(EE_CHAR_WEIGHT)|| |
208 | 0 | !SfxItemPool::IsWhich(EE_CHAR_STRIKEOUT)|| |
209 | 0 | !SfxItemPool::IsWhich(EE_CHAR_WLM)) |
210 | 0 | return aAny; |
211 | | |
212 | 0 | aSet.Put(pPool->GetUserOrPoolDefaultItem(EE_CHAR_FONTINFO)); |
213 | 0 | aSet.Put(pPool->GetUserOrPoolDefaultItem(EE_CHAR_FONTHEIGHT)); |
214 | 0 | aSet.Put(pPool->GetUserOrPoolDefaultItem(EE_CHAR_ITALIC)); |
215 | 0 | aSet.Put(pPool->GetUserOrPoolDefaultItem(EE_CHAR_UNDERLINE)); |
216 | 0 | aSet.Put(pPool->GetUserOrPoolDefaultItem(EE_CHAR_WEIGHT)); |
217 | 0 | aSet.Put(pPool->GetUserOrPoolDefaultItem(EE_CHAR_STRIKEOUT)); |
218 | 0 | aSet.Put(pPool->GetUserOrPoolDefaultItem(EE_CHAR_WLM)); |
219 | |
|
220 | 0 | awt::FontDescriptor aDesc; |
221 | |
|
222 | 0 | FillFromItemSet( aSet, aDesc ); |
223 | |
|
224 | 0 | aAny <<= aDesc; |
225 | |
|
226 | 0 | return aAny; |
227 | 0 | } |
228 | | |
229 | | |
230 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |