1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <fontcfg.hxx>
29 #include <i18npool/mslangid.hxx>
30 #include <vcl/outdev.hxx>
31 #include <unotools/lingucfg.hxx>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <com/sun/star/i18n/ScriptType.hpp>
35 #include <swtypes.hxx>
36
37 #include <unomid.h>
38
39 using namespace utl;
40 using rtl::OUString;
41 using namespace com::sun::star::uno;
42
43 /* -----------------07.10.2002 12:15-----------------
44 *
45 * --------------------------------------------------*/
lcl_LanguageOfType(sal_Int16 nType,sal_Int16 eWestern,sal_Int16 eCJK,sal_Int16 eCTL)46 inline LanguageType lcl_LanguageOfType(sal_Int16 nType, sal_Int16 eWestern, sal_Int16 eCJK, sal_Int16 eCTL)
47 {
48 return LanguageType(
49 nType < FONT_STANDARD_CJK ? eWestern :
50 nType >= FONT_STANDARD_CTL ? eCTL : eCJK);
51 }
52 /* -----------------------------08.09.00 15:52--------------------------------
53
54 ---------------------------------------------------------------------------*/
GetPropertyNames()55 Sequence<OUString> SwStdFontConfig::GetPropertyNames()
56 {
57 Sequence<OUString> aNames;
58 if(!aNames.getLength())
59 {
60 static const char* aPropNames[] =
61 {
62 "DefaultFont/Standard", // 0
63 "DefaultFont/Heading", // 1
64 "DefaultFont/List", // 2
65 "DefaultFont/Caption", // 3
66 "DefaultFont/Index", // 4
67 "DefaultFontCJK/Standard", // 5
68 "DefaultFontCJK/Heading", // 6
69 "DefaultFontCJK/List", // 7
70 "DefaultFontCJK/Caption", // 8
71 "DefaultFontCJK/Index", // 9
72 "DefaultFontCTL/Standard", // 10
73 "DefaultFontCTL/Heading", // 11
74 "DefaultFontCTL/List", // 12
75 "DefaultFontCTL/Caption", // 13
76 "DefaultFontCTL/Index", // 14
77 "DefaultFont/StandardHeight", // 15
78 "DefaultFont/HeadingHeight", // 16
79 "DefaultFont/ListHeight", // 17
80 "DefaultFont/CaptionHeight", // 18
81 "DefaultFont/IndexHeight", // 19
82 "DefaultFontCJK/StandardHeight", // 20
83 "DefaultFontCJK/HeadingHeight", // 21
84 "DefaultFontCJK/ListHeight", // 22
85 "DefaultFontCJK/CaptionHeight", // 23
86 "DefaultFontCJK/IndexHeight", // 24
87 "DefaultFontCTL/StandardHeight", // 25
88 "DefaultFontCTL/HeadingHeight", // 26
89 "DefaultFontCTL/ListHeight", // 27
90 "DefaultFontCTL/CaptionHeight", // 28
91 "DefaultFontCTL/IndexHeight" // 29
92 };
93 const int nCount = sizeof(aPropNames)/sizeof(const char*);
94 aNames.realloc(nCount);
95 OUString* pNames = aNames.getArray();
96 for(int i = 0; i < nCount; i++)
97 {
98 pNames[i] = OUString::createFromAscii(aPropNames[i]);
99 }
100 }
101 return aNames;
102 }
103 /*-----------------03.09.96 15.00-------------------
104
105 --------------------------------------------------*/
106
SwStdFontConfig()107 SwStdFontConfig::SwStdFontConfig() :
108 utl::ConfigItem(C2U("Office.Writer"))
109 {
110 SvtLinguOptions aLinguOpt;
111
112 SvtLinguConfig().GetOptions( aLinguOpt );
113
114 sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
115 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
116 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
117
118 for(sal_Int16 i = 0; i < DEF_FONT_COUNT; i++)
119 {
120 sDefaultFonts[i] = GetDefaultFor(i,
121 lcl_LanguageOfType(i, eWestern, eCJK, eCTL));
122 nDefaultFontHeight[i] = -1;
123 }
124
125 Sequence<OUString> aNames = GetPropertyNames();
126 Sequence<Any> aValues = GetProperties(aNames);
127 const Any* pValues = aValues.getConstArray();
128 DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
129 if(aValues.getLength() == aNames.getLength())
130 {
131 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
132 {
133 if(pValues[nProp].hasValue())
134 {
135 if( nProp < DEF_FONT_COUNT)
136 {
137 OUString sVal;
138 pValues[nProp] >>= sVal;
139 sDefaultFonts[nProp] = sVal;
140 }
141 else
142 {
143 pValues[nProp] >>= nDefaultFontHeight[nProp - DEF_FONT_COUNT];
144 nDefaultFontHeight[nProp - DEF_FONT_COUNT] = MM100_TO_TWIP(nDefaultFontHeight[nProp - DEF_FONT_COUNT]);
145 }
146 }
147 }
148 }
149 }
150 /* -----------------------------08.09.00 15:58--------------------------------
151
152 ---------------------------------------------------------------------------*/
Commit()153 void SwStdFontConfig::Commit()
154 {
155 Sequence<OUString> aNames = GetPropertyNames();
156 Sequence<Any> aValues(aNames.getLength());
157 Any* pValues = aValues.getArray();
158 SvtLinguOptions aLinguOpt;
159
160 SvtLinguConfig().GetOptions( aLinguOpt );
161
162 sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
163 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
164 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
165
166 for(sal_uInt16 nProp = 0;
167 nProp < sal::static_int_cast< sal_uInt16, sal_Int32 >( aNames.getLength() );
168 nProp++)
169 {
170 if( nProp < DEF_FONT_COUNT )
171 {
172 if(GetDefaultFor(nProp, lcl_LanguageOfType(nProp, eWestern, eCJK, eCTL)) != sDefaultFonts[nProp])
173 pValues[nProp] <<= OUString(sDefaultFonts[nProp]);
174 }
175 else
176 {
177 if(nDefaultFontHeight[nProp - DEF_FONT_COUNT] > 0)
178 pValues[nProp] <<= static_cast<sal_Int32>(TWIP_TO_MM100(nDefaultFontHeight[nProp - DEF_FONT_COUNT]));
179 }
180 }
181 PutProperties(aNames, aValues);
182 }
183 /* -----------------------------08.09.00 15:56--------------------------------
184
185 ---------------------------------------------------------------------------*/
~SwStdFontConfig()186 SwStdFontConfig::~SwStdFontConfig()
187 {}
188 /*-----------------18.01.97 10.05-------------------
189
190 --------------------------------------------------*/
IsFontDefault(sal_uInt16 nFontType) const191 sal_Bool SwStdFontConfig::IsFontDefault(sal_uInt16 nFontType) const
192 {
193 sal_Bool bSame = sal_False;
194 SvtLinguOptions aLinguOpt;
195
196 SvtLinguConfig().GetOptions( aLinguOpt );
197
198 sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
199 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
200 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
201
202 String sDefFont(GetDefaultFor(FONT_STANDARD, eWestern));
203 String sDefFontCJK(GetDefaultFor(FONT_STANDARD_CJK, eCJK));
204 String sDefFontCTL(GetDefaultFor(FONT_STANDARD_CTL, eCTL));
205 LanguageType eLang = lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL);
206 switch( nFontType )
207 {
208 case FONT_STANDARD:
209 bSame = sDefaultFonts[nFontType] == sDefFont;
210 break;
211 case FONT_STANDARD_CJK:
212 bSame = sDefaultFonts[nFontType] == sDefFontCJK;
213 break;
214 case FONT_STANDARD_CTL:
215 bSame = sDefaultFonts[nFontType] == sDefFontCTL;
216 break;
217 case FONT_OUTLINE :
218 case FONT_OUTLINE_CJK :
219 case FONT_OUTLINE_CTL :
220 bSame = sDefaultFonts[nFontType] ==
221 GetDefaultFor(nFontType, eLang);
222 break;
223 case FONT_LIST :
224 case FONT_CAPTION :
225 case FONT_INDEX :
226 bSame = sDefaultFonts[nFontType] == sDefFont &&
227 sDefaultFonts[FONT_STANDARD] == sDefFont;
228 break;
229 case FONT_LIST_CJK :
230 case FONT_CAPTION_CJK :
231 case FONT_INDEX_CJK :
232 {
233 sal_Bool b1 = sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCJK;
234 bSame = b1 && sDefaultFonts[nFontType] == sDefFontCJK;
235 }
236 break;
237 case FONT_LIST_CTL :
238 case FONT_CAPTION_CTL :
239 case FONT_INDEX_CTL :
240 {
241 sal_Bool b1 = sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCTL;
242 bSame = b1 && sDefaultFonts[nFontType] == sDefFontCTL;
243 }
244 break;
245 }
246 return bSame;
247 }
248
249 /* -----------------11.01.99 13:16-------------------
250 * Standards auslesen
251 * --------------------------------------------------*/
GetDefaultFor(sal_uInt16 nFontType,LanguageType eLang)252 String SwStdFontConfig::GetDefaultFor(sal_uInt16 nFontType, LanguageType eLang)
253 {
254 String sRet;
255 sal_uInt16 nFontId;
256 switch( nFontType )
257 {
258 case FONT_OUTLINE :
259 nFontId = DEFAULTFONT_LATIN_HEADING;
260 break;
261 case FONT_OUTLINE_CJK :
262 nFontId = DEFAULTFONT_CJK_HEADING;
263 break;
264 case FONT_OUTLINE_CTL :
265 nFontId = DEFAULTFONT_CTL_HEADING;
266 break;
267 case FONT_STANDARD_CJK:
268 case FONT_LIST_CJK :
269 case FONT_CAPTION_CJK :
270 case FONT_INDEX_CJK :
271 nFontId = DEFAULTFONT_CJK_TEXT;
272 break;
273 case FONT_STANDARD_CTL:
274 case FONT_LIST_CTL :
275 case FONT_CAPTION_CTL :
276 case FONT_INDEX_CTL :
277 nFontId = DEFAULTFONT_CTL_TEXT;
278 break;
279 // case FONT_STANDARD:
280 // case FONT_LIST :
281 // case FONT_CAPTION :
282 // case FONT_INDEX :
283 default:
284 nFontId = DEFAULTFONT_LATIN_TEXT;
285 }
286 Font aFont = OutputDevice::GetDefaultFont(nFontId, eLang, DEFAULTFONT_FLAGS_ONLYONE);
287 return aFont.GetName();
288 }
289
290 /*-- 11.10.2005 10:43:43---------------------------------------------------
291
292 -----------------------------------------------------------------------*/
GetDefaultHeightFor(sal_uInt16 nFontType,LanguageType eLang)293 sal_Int32 SwStdFontConfig::GetDefaultHeightFor(sal_uInt16 nFontType, LanguageType eLang)
294 {
295 sal_Int32 nRet = FONTSIZE_DEFAULT;
296 switch( nFontType )
297 {
298 case FONT_OUTLINE:
299 case FONT_OUTLINE_CJK:
300 case FONT_OUTLINE_CTL:
301 nRet = FONTSIZE_OUTLINE;
302 break;
303 }
304 if( eLang == LANGUAGE_THAI && nFontType >= FONT_STANDARD_CTL )
305 {
306 nRet = nRet * 4 / 3;
307 }
308 return nRet;
309 }
310
311 /*-- 11.10.2005 10:50:06---------------------------------------------------
312
313 -----------------------------------------------------------------------*/
ChangeInt(sal_uInt16 nFontType,sal_Int32 nHeight)314 void SwStdFontConfig::ChangeInt( sal_uInt16 nFontType, sal_Int32 nHeight )
315 {
316 DBG_ASSERT( nFontType < DEF_FONT_COUNT, "invalid index in SwStdFontConfig::ChangInt()");
317 if( nFontType < DEF_FONT_COUNT && nDefaultFontHeight[nFontType] != nHeight)
318 {
319 SvtLinguOptions aLinguOpt;
320 SvtLinguConfig().GetOptions( aLinguOpt );
321
322 sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
323 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
324 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
325
326 // #i92090# default height value sets back to -1
327 const sal_Int32 nDefaultHeight = GetDefaultHeightFor(nFontType, lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL));
328 const bool bIsDefaultHeight = nHeight == nDefaultHeight;
329 if( bIsDefaultHeight && nDefaultFontHeight[nFontType] > 0 )
330 {
331 SetModified();
332 nDefaultFontHeight[nFontType] = -1;
333 }
334 else if( !bIsDefaultHeight && nHeight != nDefaultFontHeight[nFontType] )
335 {
336 SetModified();
337 nDefaultFontHeight[nFontType] = nHeight;
338 }
339 }
340 }
341
342 /*-- 08.11.2005 14:18:26---------------------------------------------------
343
344 -----------------------------------------------------------------------*/
GetFontHeight(sal_uInt8 nFont,sal_uInt8 nScriptType,LanguageType eLang)345 sal_Int32 SwStdFontConfig::GetFontHeight( sal_uInt8 nFont, sal_uInt8 nScriptType, LanguageType eLang )
346 {
347 DBG_ASSERT(nFont + FONT_PER_GROUP * nScriptType < DEF_FONT_COUNT, "wrong index in SwStdFontConfig::GetFontHeight()");
348 sal_Int32 nRet = nDefaultFontHeight[nFont + FONT_PER_GROUP * nScriptType];
349 if(nRet <= 0)
350 return GetDefaultHeightFor(nFont + FONT_PER_GROUP * nScriptType, eLang);
351 return nRet;
352 }
353
Notify(const::com::sun::star::uno::Sequence<rtl::OUString> &)354 void SwStdFontConfig::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
355
356