Line data Source code
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 : #include <fontcfg.hxx>
21 : #include <i18nlangtag/mslangid.hxx>
22 : #include <vcl/outdev.hxx>
23 : #include <unotools/lingucfg.hxx>
24 : #include <com/sun/star/uno/Any.hxx>
25 : #include <com/sun/star/uno/Sequence.hxx>
26 : #include <com/sun/star/i18n/ScriptType.hpp>
27 : #include <swtypes.hxx>
28 :
29 : #include <unomid.h>
30 :
31 : using namespace utl;
32 : using namespace com::sun::star::uno;
33 :
34 72360 : static inline LanguageType lcl_LanguageOfType(sal_Int16 nType, sal_Int16 eWestern, sal_Int16 eCJK, sal_Int16 eCTL)
35 : {
36 : return LanguageType(
37 : nType < FONT_STANDARD_CJK ? eWestern :
38 72360 : nType >= FONT_STANDARD_CTL ? eCTL : eCJK);
39 : }
40 :
41 90 : Sequence<OUString> SwStdFontConfig::GetPropertyNames()
42 : {
43 90 : Sequence<OUString> aNames;
44 90 : if(!aNames.getLength())
45 : {
46 : static const char* aPropNames[] =
47 : {
48 : "DefaultFont/Standard", // 0
49 : "DefaultFont/Heading", // 1
50 : "DefaultFont/List", // 2
51 : "DefaultFont/Caption", // 3
52 : "DefaultFont/Index", // 4
53 : "DefaultFontCJK/Standard", // 5
54 : "DefaultFontCJK/Heading", // 6
55 : "DefaultFontCJK/List", // 7
56 : "DefaultFontCJK/Caption", // 8
57 : "DefaultFontCJK/Index", // 9
58 : "DefaultFontCTL/Standard", // 10
59 : "DefaultFontCTL/Heading", // 11
60 : "DefaultFontCTL/List", // 12
61 : "DefaultFontCTL/Caption", // 13
62 : "DefaultFontCTL/Index", // 14
63 : "DefaultFont/StandardHeight", // 15
64 : "DefaultFont/HeadingHeight", // 16
65 : "DefaultFont/ListHeight", // 17
66 : "DefaultFont/CaptionHeight", // 18
67 : "DefaultFont/IndexHeight", // 19
68 : "DefaultFontCJK/StandardHeight", // 20
69 : "DefaultFontCJK/HeadingHeight", // 21
70 : "DefaultFontCJK/ListHeight", // 22
71 : "DefaultFontCJK/CaptionHeight", // 23
72 : "DefaultFontCJK/IndexHeight", // 24
73 : "DefaultFontCTL/StandardHeight", // 25
74 : "DefaultFontCTL/HeadingHeight", // 26
75 : "DefaultFontCTL/ListHeight", // 27
76 : "DefaultFontCTL/CaptionHeight", // 28
77 : "DefaultFontCTL/IndexHeight" // 29
78 : };
79 90 : const int nCount = sizeof(aPropNames)/sizeof(const char*);
80 90 : aNames.realloc(nCount);
81 90 : OUString* pNames = aNames.getArray();
82 2790 : for(int i = 0; i < nCount; i++)
83 : {
84 2700 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
85 : }
86 : }
87 90 : return aNames;
88 : }
89 :
90 90 : SwStdFontConfig::SwStdFontConfig() :
91 90 : utl::ConfigItem("Office.Writer")
92 : {
93 90 : SvtLinguOptions aLinguOpt;
94 :
95 90 : SvtLinguConfig().GetOptions( aLinguOpt );
96 :
97 90 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
98 90 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
99 90 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
100 :
101 1440 : for(sal_Int16 i = 0; i < DEF_FONT_COUNT; i++)
102 : {
103 2700 : sDefaultFonts[i] = GetDefaultFor(i,
104 2700 : lcl_LanguageOfType(i, eWestern, eCJK, eCTL));
105 1350 : nDefaultFontHeight[i] = -1;
106 : }
107 :
108 180 : Sequence<OUString> aNames = GetPropertyNames();
109 180 : Sequence<Any> aValues = GetProperties(aNames);
110 90 : const Any* pValues = aValues.getConstArray();
111 : OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
112 90 : if(aValues.getLength() == aNames.getLength())
113 : {
114 2790 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
115 : {
116 2700 : if(pValues[nProp].hasValue())
117 : {
118 0 : if( nProp < DEF_FONT_COUNT)
119 : {
120 0 : OUString sVal;
121 0 : pValues[nProp] >>= sVal;
122 0 : sDefaultFonts[nProp] = sVal;
123 : }
124 : else
125 : {
126 0 : pValues[nProp] >>= nDefaultFontHeight[nProp - DEF_FONT_COUNT];
127 0 : nDefaultFontHeight[nProp - DEF_FONT_COUNT] = convertMm100ToTwip(nDefaultFontHeight[nProp - DEF_FONT_COUNT]);
128 : }
129 : }
130 : }
131 90 : }
132 90 : }
133 :
134 0 : void SwStdFontConfig::Commit()
135 : {
136 0 : Sequence<OUString> aNames = GetPropertyNames();
137 0 : Sequence<Any> aValues(aNames.getLength());
138 0 : Any* pValues = aValues.getArray();
139 0 : SvtLinguOptions aLinguOpt;
140 :
141 0 : SvtLinguConfig().GetOptions( aLinguOpt );
142 :
143 0 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
144 0 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
145 0 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
146 :
147 0 : for(sal_uInt16 nProp = 0;
148 0 : nProp < sal::static_int_cast< sal_uInt16, sal_Int32 >( aNames.getLength() );
149 : nProp++)
150 : {
151 0 : if( nProp < DEF_FONT_COUNT )
152 : {
153 0 : if(GetDefaultFor(nProp, lcl_LanguageOfType(nProp, eWestern, eCJK, eCTL)) != sDefaultFonts[nProp])
154 0 : pValues[nProp] <<= OUString(sDefaultFonts[nProp]);
155 : }
156 : else
157 : {
158 0 : if(nDefaultFontHeight[nProp - DEF_FONT_COUNT] > 0)
159 0 : pValues[nProp] <<= static_cast<sal_Int32>(convertTwipToMm100(nDefaultFontHeight[nProp - DEF_FONT_COUNT]));
160 : }
161 : }
162 0 : PutProperties(aNames, aValues);
163 0 : }
164 :
165 72 : SwStdFontConfig::~SwStdFontConfig()
166 : {
167 72 : }
168 :
169 71010 : bool SwStdFontConfig::IsFontDefault(sal_uInt16 nFontType) const
170 : {
171 71010 : bool bSame = false;
172 71010 : SvtLinguOptions aLinguOpt;
173 :
174 71010 : SvtLinguConfig().GetOptions( aLinguOpt );
175 :
176 71010 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
177 71010 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
178 71010 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
179 :
180 142020 : OUString sDefFont(GetDefaultFor(FONT_STANDARD, eWestern));
181 142020 : OUString sDefFontCJK(GetDefaultFor(FONT_STANDARD_CJK, eCJK));
182 142020 : OUString sDefFontCTL(GetDefaultFor(FONT_STANDARD_CTL, eCTL));
183 71010 : LanguageType eLang = lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL);
184 71010 : switch( nFontType )
185 : {
186 : case FONT_STANDARD:
187 4734 : bSame = sDefaultFonts[nFontType] == sDefFont;
188 4734 : break;
189 : case FONT_STANDARD_CJK:
190 4734 : bSame = sDefaultFonts[nFontType] == sDefFontCJK;
191 4734 : break;
192 : case FONT_STANDARD_CTL:
193 4734 : bSame = sDefaultFonts[nFontType] == sDefFontCTL;
194 4734 : break;
195 : case FONT_OUTLINE :
196 : case FONT_OUTLINE_CJK :
197 : case FONT_OUTLINE_CTL :
198 28404 : bSame = sDefaultFonts[nFontType] ==
199 14202 : GetDefaultFor(nFontType, eLang);
200 14202 : break;
201 : case FONT_LIST :
202 : case FONT_CAPTION :
203 : case FONT_INDEX :
204 28404 : bSame = sDefaultFonts[nFontType] == sDefFont &&
205 28404 : sDefaultFonts[FONT_STANDARD] == sDefFont;
206 14202 : break;
207 : case FONT_LIST_CJK :
208 : case FONT_CAPTION_CJK :
209 : case FONT_INDEX_CJK :
210 : {
211 14202 : bool b1 = sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCJK;
212 14202 : bSame = b1 && sDefaultFonts[nFontType] == sDefFontCJK;
213 : }
214 14202 : break;
215 : case FONT_LIST_CTL :
216 : case FONT_CAPTION_CTL :
217 : case FONT_INDEX_CTL :
218 : {
219 14202 : bool b1 = sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCTL;
220 14202 : bSame = b1 && sDefaultFonts[nFontType] == sDefFontCTL;
221 : }
222 14202 : break;
223 : }
224 142020 : return bSame;
225 : }
226 :
227 228582 : OUString SwStdFontConfig::GetDefaultFor(sal_uInt16 nFontType, LanguageType eLang)
228 : {
229 : sal_uInt16 nFontId;
230 228582 : switch( nFontType )
231 : {
232 : case FONT_OUTLINE :
233 4824 : nFontId = DEFAULTFONT_LATIN_HEADING;
234 4824 : break;
235 : case FONT_OUTLINE_CJK :
236 4824 : nFontId = DEFAULTFONT_CJK_HEADING;
237 4824 : break;
238 : case FONT_OUTLINE_CTL :
239 4824 : nFontId = DEFAULTFONT_CTL_HEADING;
240 4824 : break;
241 : case FONT_STANDARD_CJK:
242 : case FONT_LIST_CJK :
243 : case FONT_CAPTION_CJK :
244 : case FONT_INDEX_CJK :
245 71370 : nFontId = DEFAULTFONT_CJK_TEXT;
246 71370 : break;
247 : case FONT_STANDARD_CTL:
248 : case FONT_LIST_CTL :
249 : case FONT_CAPTION_CTL :
250 : case FONT_INDEX_CTL :
251 71370 : nFontId = DEFAULTFONT_CTL_TEXT;
252 71370 : break;
253 : default:
254 71370 : nFontId = DEFAULTFONT_LATIN_TEXT;
255 : }
256 228582 : vcl::Font aFont = OutputDevice::GetDefaultFont(nFontId, eLang, DEFAULTFONT_FLAGS_ONLYONE);
257 228582 : return aFont.GetName();
258 : }
259 :
260 71010 : sal_Int32 SwStdFontConfig::GetDefaultHeightFor(sal_uInt16 nFontType, LanguageType eLang)
261 : {
262 71010 : sal_Int32 nRet = FONTSIZE_DEFAULT;
263 71010 : switch( nFontType )
264 : {
265 : case FONT_OUTLINE:
266 : case FONT_OUTLINE_CJK:
267 : case FONT_OUTLINE_CTL:
268 14202 : nRet = FONTSIZE_OUTLINE;
269 14202 : break;
270 : case FONT_STANDARD_CJK:
271 4734 : nRet = FONTSIZE_CJK_DEFAULT;
272 4734 : break;
273 : }
274 71010 : if( eLang == LANGUAGE_THAI && nFontType >= FONT_STANDARD_CTL )
275 : {
276 0 : nRet = nRet * 4 / 3;
277 : }
278 71010 : return nRet;
279 : }
280 :
281 0 : void SwStdFontConfig::ChangeInt( sal_uInt16 nFontType, sal_Int32 nHeight )
282 : {
283 : OSL_ENSURE( nFontType < DEF_FONT_COUNT, "invalid index in SwStdFontConfig::ChangInt()");
284 0 : if( nFontType < DEF_FONT_COUNT && nDefaultFontHeight[nFontType] != nHeight)
285 : {
286 0 : SvtLinguOptions aLinguOpt;
287 0 : SvtLinguConfig().GetOptions( aLinguOpt );
288 :
289 0 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
290 0 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
291 0 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
292 :
293 : // #i92090# default height value sets back to -1
294 0 : const sal_Int32 nDefaultHeight = GetDefaultHeightFor(nFontType, lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL));
295 0 : const bool bIsDefaultHeight = nHeight == nDefaultHeight;
296 0 : if( bIsDefaultHeight && nDefaultFontHeight[nFontType] > 0 )
297 : {
298 0 : SetModified();
299 0 : nDefaultFontHeight[nFontType] = -1;
300 : }
301 0 : else if( !bIsDefaultHeight && nHeight != nDefaultFontHeight[nFontType] )
302 : {
303 0 : SetModified();
304 0 : nDefaultFontHeight[nFontType] = nHeight;
305 0 : }
306 : }
307 0 : }
308 :
309 71010 : sal_Int32 SwStdFontConfig::GetFontHeight( sal_uInt8 nFont, sal_uInt8 nScriptType, LanguageType eLang )
310 : {
311 : OSL_ENSURE(nFont + FONT_PER_GROUP * nScriptType < DEF_FONT_COUNT, "wrong index in SwStdFontConfig::GetFontHeight()");
312 71010 : sal_Int32 nRet = nDefaultFontHeight[nFont + FONT_PER_GROUP * nScriptType];
313 71010 : if(nRet <= 0)
314 71010 : return GetDefaultHeightFor(nFont + FONT_PER_GROUP * nScriptType, eLang);
315 0 : return nRet;
316 : }
317 :
318 270 : void SwStdFontConfig::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
319 :
320 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|