Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <fontcfg.hxx>
31 : : #include <i18npool/mslangid.hxx>
32 : : #include <vcl/outdev.hxx>
33 : : #include <unotools/lingucfg.hxx>
34 : : #include <com/sun/star/uno/Any.hxx>
35 : : #include <com/sun/star/uno/Sequence.hxx>
36 : : #include <com/sun/star/i18n/ScriptType.hpp>
37 : : #include <swtypes.hxx>
38 : :
39 : : #include <unomid.h>
40 : :
41 : : using namespace utl;
42 : : using rtl::OUString;
43 : : using namespace com::sun::star::uno;
44 : :
45 : 23355 : inline LanguageType lcl_LanguageOfType(sal_Int16 nType, sal_Int16 eWestern, sal_Int16 eCJK, sal_Int16 eCTL)
46 : : {
47 : : return LanguageType(
48 : : nType < FONT_STANDARD_CJK ? eWestern :
49 [ + + ][ + + ]: 23355 : nType >= FONT_STANDARD_CTL ? eCTL : eCJK);
50 : : }
51 : :
52 : 73 : Sequence<OUString> SwStdFontConfig::GetPropertyNames()
53 : : {
54 : 73 : Sequence<OUString> aNames;
55 [ + - ]: 73 : if(!aNames.getLength())
56 : : {
57 : : static const char* aPropNames[] =
58 : : {
59 : : "DefaultFont/Standard", // 0
60 : : "DefaultFont/Heading", // 1
61 : : "DefaultFont/List", // 2
62 : : "DefaultFont/Caption", // 3
63 : : "DefaultFont/Index", // 4
64 : : "DefaultFontCJK/Standard", // 5
65 : : "DefaultFontCJK/Heading", // 6
66 : : "DefaultFontCJK/List", // 7
67 : : "DefaultFontCJK/Caption", // 8
68 : : "DefaultFontCJK/Index", // 9
69 : : "DefaultFontCTL/Standard", // 10
70 : : "DefaultFontCTL/Heading", // 11
71 : : "DefaultFontCTL/List", // 12
72 : : "DefaultFontCTL/Caption", // 13
73 : : "DefaultFontCTL/Index", // 14
74 : : "DefaultFont/StandardHeight", // 15
75 : : "DefaultFont/HeadingHeight", // 16
76 : : "DefaultFont/ListHeight", // 17
77 : : "DefaultFont/CaptionHeight", // 18
78 : : "DefaultFont/IndexHeight", // 19
79 : : "DefaultFontCJK/StandardHeight", // 20
80 : : "DefaultFontCJK/HeadingHeight", // 21
81 : : "DefaultFontCJK/ListHeight", // 22
82 : : "DefaultFontCJK/CaptionHeight", // 23
83 : : "DefaultFontCJK/IndexHeight", // 24
84 : : "DefaultFontCTL/StandardHeight", // 25
85 : : "DefaultFontCTL/HeadingHeight", // 26
86 : : "DefaultFontCTL/ListHeight", // 27
87 : : "DefaultFontCTL/CaptionHeight", // 28
88 : : "DefaultFontCTL/IndexHeight" // 29
89 : : };
90 : 73 : const int nCount = sizeof(aPropNames)/sizeof(const char*);
91 [ + - ]: 73 : aNames.realloc(nCount);
92 [ + - ]: 73 : OUString* pNames = aNames.getArray();
93 [ + + ]: 2263 : for(int i = 0; i < nCount; i++)
94 : : {
95 : 2190 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
96 : : }
97 : : }
98 : 73 : return aNames;
99 : : }
100 : :
101 : 73 : SwStdFontConfig::SwStdFontConfig() :
102 [ + - ][ + - ]: 1168 : utl::ConfigItem(C2U("Office.Writer"))
[ + + # #
# # ]
103 : : {
104 [ + - ]: 73 : SvtLinguOptions aLinguOpt;
105 : :
106 [ + - ][ + - ]: 73 : SvtLinguConfig().GetOptions( aLinguOpt );
[ + - ]
107 : :
108 [ + - ]: 73 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
109 [ + - ]: 73 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
110 [ + - ]: 73 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
111 : :
112 [ + + ]: 1168 : for(sal_Int16 i = 0; i < DEF_FONT_COUNT; i++)
113 : : {
114 : 1095 : sDefaultFonts[i] = GetDefaultFor(i,
115 [ + - ][ + - ]: 1095 : lcl_LanguageOfType(i, eWestern, eCJK, eCTL));
[ + - ]
116 : 1095 : nDefaultFontHeight[i] = -1;
117 : : }
118 : :
119 [ + - ]: 73 : Sequence<OUString> aNames = GetPropertyNames();
120 [ + - ]: 73 : Sequence<Any> aValues = GetProperties(aNames);
121 : 73 : const Any* pValues = aValues.getConstArray();
122 : : OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
123 [ + - ]: 73 : if(aValues.getLength() == aNames.getLength())
124 : : {
125 [ + + ]: 2263 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
126 : : {
127 [ - + ]: 2190 : if(pValues[nProp].hasValue())
128 : : {
129 [ # # ]: 0 : if( nProp < DEF_FONT_COUNT)
130 : : {
131 : 0 : OUString sVal;
132 : 0 : pValues[nProp] >>= sVal;
133 [ # # ]: 0 : sDefaultFonts[nProp] = sVal;
134 : : }
135 : : else
136 : : {
137 : 0 : pValues[nProp] >>= nDefaultFontHeight[nProp - DEF_FONT_COUNT];
138 [ # # ]: 0 : nDefaultFontHeight[nProp - DEF_FONT_COUNT] = MM100_TO_TWIP(nDefaultFontHeight[nProp - DEF_FONT_COUNT]);
139 : : }
140 : : }
141 : : }
142 [ + - ][ + - ]: 73 : }
[ + - ]
143 [ # # # # ]: 73 : }
144 : :
145 : 0 : void SwStdFontConfig::Commit()
146 : : {
147 [ # # ]: 0 : Sequence<OUString> aNames = GetPropertyNames();
148 [ # # ]: 0 : Sequence<Any> aValues(aNames.getLength());
149 [ # # ]: 0 : Any* pValues = aValues.getArray();
150 [ # # ]: 0 : SvtLinguOptions aLinguOpt;
151 : :
152 [ # # ][ # # ]: 0 : SvtLinguConfig().GetOptions( aLinguOpt );
[ # # ]
153 : :
154 [ # # ]: 0 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
155 [ # # ]: 0 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
156 [ # # ]: 0 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
157 : :
158 [ # # ]: 0 : for(sal_uInt16 nProp = 0;
159 : 0 : nProp < sal::static_int_cast< sal_uInt16, sal_Int32 >( aNames.getLength() );
160 : : nProp++)
161 : : {
162 [ # # ]: 0 : if( nProp < DEF_FONT_COUNT )
163 : : {
164 [ # # ][ # # ]: 0 : if(GetDefaultFor(nProp, lcl_LanguageOfType(nProp, eWestern, eCJK, eCTL)) != sDefaultFonts[nProp])
[ # # ][ # # ]
165 [ # # ][ # # ]: 0 : pValues[nProp] <<= OUString(sDefaultFonts[nProp]);
166 : : }
167 : : else
168 : : {
169 [ # # ]: 0 : if(nDefaultFontHeight[nProp - DEF_FONT_COUNT] > 0)
170 [ # # ][ # # ]: 0 : pValues[nProp] <<= static_cast<sal_Int32>(TWIP_TO_MM100(nDefaultFontHeight[nProp - DEF_FONT_COUNT]));
171 : : }
172 : : }
173 [ # # ][ # # ]: 0 : PutProperties(aNames, aValues);
[ # # ][ # # ]
174 : 0 : }
175 : :
176 [ + - ]: 640 : SwStdFontConfig::~SwStdFontConfig()
177 : : {
178 [ + - ][ + + ]: 720 : }
[ - + ]
179 : :
180 : 22260 : sal_Bool SwStdFontConfig::IsFontDefault(sal_uInt16 nFontType) const
181 : : {
182 : 22260 : sal_Bool bSame = sal_False;
183 [ + - ]: 22260 : SvtLinguOptions aLinguOpt;
184 : :
185 [ + - ][ + - ]: 22260 : SvtLinguConfig().GetOptions( aLinguOpt );
[ + - ]
186 : :
187 [ + - ]: 22260 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
188 [ + - ]: 22260 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
189 [ + - ]: 22260 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
190 : :
191 [ + - ]: 22260 : String sDefFont(GetDefaultFor(FONT_STANDARD, eWestern));
192 [ + - ]: 22260 : String sDefFontCJK(GetDefaultFor(FONT_STANDARD_CJK, eCJK));
193 [ + - ]: 22260 : String sDefFontCTL(GetDefaultFor(FONT_STANDARD_CTL, eCTL));
194 : 22260 : LanguageType eLang = lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL);
195 [ + + + + : 22260 : switch( nFontType )
+ + + - ]
196 : : {
197 : : case FONT_STANDARD:
198 [ + - ]: 1484 : bSame = sDefaultFonts[nFontType] == sDefFont;
199 : 1484 : break;
200 : : case FONT_STANDARD_CJK:
201 [ + - ]: 1484 : bSame = sDefaultFonts[nFontType] == sDefFontCJK;
202 : 1484 : break;
203 : : case FONT_STANDARD_CTL:
204 [ + - ]: 1484 : bSame = sDefaultFonts[nFontType] == sDefFontCTL;
205 : 1484 : break;
206 : : case FONT_OUTLINE :
207 : : case FONT_OUTLINE_CJK :
208 : : case FONT_OUTLINE_CTL :
209 : 4452 : bSame = sDefaultFonts[nFontType] ==
210 [ + - ][ + - ]: 4452 : GetDefaultFor(nFontType, eLang);
[ + - ]
211 : 4452 : break;
212 : : case FONT_LIST :
213 : : case FONT_CAPTION :
214 : : case FONT_INDEX :
215 [ + - ]: 4452 : bSame = sDefaultFonts[nFontType] == sDefFont &&
216 [ + + ][ + - ]: 4452 : sDefaultFonts[FONT_STANDARD] == sDefFont;
[ + - ]
217 : 4452 : break;
218 : : case FONT_LIST_CJK :
219 : : case FONT_CAPTION_CJK :
220 : : case FONT_INDEX_CJK :
221 : : {
222 [ + - ]: 4452 : sal_Bool b1 = sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCJK;
223 [ + + ][ + - ]: 4452 : bSame = b1 && sDefaultFonts[nFontType] == sDefFontCJK;
[ + - ]
224 : : }
225 : 4452 : break;
226 : : case FONT_LIST_CTL :
227 : : case FONT_CAPTION_CTL :
228 : : case FONT_INDEX_CTL :
229 : : {
230 [ + - ]: 4452 : sal_Bool b1 = sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCTL;
231 [ - + ][ # # ]: 4452 : bSame = b1 && sDefaultFonts[nFontType] == sDefFontCTL;
[ # # ]
232 : : }
233 : 4452 : break;
234 : : }
235 [ + - ][ + - ]: 22260 : return bSame;
[ + - ][ + - ]
236 : : }
237 : :
238 : 72327 : String SwStdFontConfig::GetDefaultFor(sal_uInt16 nFontType, LanguageType eLang)
239 : : {
240 [ + - ]: 72327 : String sRet;
241 : : sal_uInt16 nFontId;
242 [ + + + + : 72327 : switch( nFontType )
+ + ]
243 : : {
244 : : case FONT_OUTLINE :
245 : 1557 : nFontId = DEFAULTFONT_LATIN_HEADING;
246 : 1557 : break;
247 : : case FONT_OUTLINE_CJK :
248 : 1557 : nFontId = DEFAULTFONT_CJK_HEADING;
249 : 1557 : break;
250 : : case FONT_OUTLINE_CTL :
251 : 1557 : nFontId = DEFAULTFONT_CTL_HEADING;
252 : 1557 : break;
253 : : case FONT_STANDARD_CJK:
254 : : case FONT_LIST_CJK :
255 : : case FONT_CAPTION_CJK :
256 : : case FONT_INDEX_CJK :
257 : 22552 : nFontId = DEFAULTFONT_CJK_TEXT;
258 : 22552 : break;
259 : : case FONT_STANDARD_CTL:
260 : : case FONT_LIST_CTL :
261 : : case FONT_CAPTION_CTL :
262 : : case FONT_INDEX_CTL :
263 : 22552 : nFontId = DEFAULTFONT_CTL_TEXT;
264 : 22552 : break;
265 : : default:
266 : 22552 : nFontId = DEFAULTFONT_LATIN_TEXT;
267 : : }
268 [ + - ]: 72327 : Font aFont = OutputDevice::GetDefaultFont(nFontId, eLang, DEFAULTFONT_FLAGS_ONLYONE);
269 [ + - ][ + - ]: 72327 : return aFont.GetName();
[ + - ][ + - ]
270 : : }
271 : :
272 : 22260 : sal_Int32 SwStdFontConfig::GetDefaultHeightFor(sal_uInt16 nFontType, LanguageType eLang)
273 : : {
274 : 22260 : sal_Int32 nRet = FONTSIZE_DEFAULT;
275 [ + + + ]: 22260 : switch( nFontType )
276 : : {
277 : : case FONT_OUTLINE:
278 : : case FONT_OUTLINE_CJK:
279 : : case FONT_OUTLINE_CTL:
280 : 4452 : nRet = FONTSIZE_OUTLINE;
281 : 4452 : break;
282 : : case FONT_STANDARD_CJK:
283 : 1484 : nRet = FONTSIZE_CJK_DEFAULT;
284 : 1484 : break;
285 : : }
286 [ - + ][ # # ]: 22260 : if( eLang == LANGUAGE_THAI && nFontType >= FONT_STANDARD_CTL )
287 : : {
288 : 0 : nRet = nRet * 4 / 3;
289 : : }
290 : 22260 : return nRet;
291 : : }
292 : :
293 : 0 : void SwStdFontConfig::ChangeInt( sal_uInt16 nFontType, sal_Int32 nHeight )
294 : : {
295 : : OSL_ENSURE( nFontType < DEF_FONT_COUNT, "invalid index in SwStdFontConfig::ChangInt()");
296 [ # # ][ # # ]: 0 : if( nFontType < DEF_FONT_COUNT && nDefaultFontHeight[nFontType] != nHeight)
297 : : {
298 [ # # ]: 0 : SvtLinguOptions aLinguOpt;
299 [ # # ][ # # ]: 0 : SvtLinguConfig().GetOptions( aLinguOpt );
[ # # ]
300 : :
301 [ # # ]: 0 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
302 [ # # ]: 0 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
303 [ # # ]: 0 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
304 : :
305 : : // #i92090# default height value sets back to -1
306 [ # # ]: 0 : const sal_Int32 nDefaultHeight = GetDefaultHeightFor(nFontType, lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL));
307 : 0 : const bool bIsDefaultHeight = nHeight == nDefaultHeight;
308 [ # # ][ # # ]: 0 : if( bIsDefaultHeight && nDefaultFontHeight[nFontType] > 0 )
309 : : {
310 [ # # ]: 0 : SetModified();
311 : 0 : nDefaultFontHeight[nFontType] = -1;
312 : : }
313 [ # # ][ # # ]: 0 : else if( !bIsDefaultHeight && nHeight != nDefaultFontHeight[nFontType] )
314 : : {
315 [ # # ]: 0 : SetModified();
316 : 0 : nDefaultFontHeight[nFontType] = nHeight;
317 [ # # ]: 0 : }
318 : : }
319 : 0 : }
320 : :
321 : 22260 : sal_Int32 SwStdFontConfig::GetFontHeight( sal_uInt8 nFont, sal_uInt8 nScriptType, LanguageType eLang )
322 : : {
323 : : OSL_ENSURE(nFont + FONT_PER_GROUP * nScriptType < DEF_FONT_COUNT, "wrong index in SwStdFontConfig::GetFontHeight()");
324 : 22260 : sal_Int32 nRet = nDefaultFontHeight[nFont + FONT_PER_GROUP * nScriptType];
325 [ + - ]: 22260 : if(nRet <= 0)
326 : 22260 : return GetDefaultHeightFor(nFont + FONT_PER_GROUP * nScriptType, eLang);
327 : 22260 : return nRet;
328 : : }
329 : :
330 : 0 : void SwStdFontConfig::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
331 : :
332 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|