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 40890 : 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 40890 : nType >= FONT_STANDARD_CTL ? eCTL : eCJK);
39 : }
40 :
41 59 : Sequence<OUString> SwStdFontConfig::GetPropertyNames()
42 : {
43 59 : Sequence<OUString> aNames;
44 59 : 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 59 : const int nCount = sizeof(aPropNames)/sizeof(const char*);
80 59 : aNames.realloc(nCount);
81 59 : OUString* pNames = aNames.getArray();
82 1829 : for(int i = 0; i < nCount; i++)
83 : {
84 1770 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
85 : }
86 : }
87 59 : return aNames;
88 : }
89 :
90 59 : SwStdFontConfig::SwStdFontConfig() :
91 59 : utl::ConfigItem("Office.Writer")
92 : {
93 59 : SvtLinguOptions aLinguOpt;
94 :
95 59 : SvtLinguConfig().GetOptions( aLinguOpt );
96 :
97 59 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
98 59 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
99 59 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
100 :
101 944 : for(sal_Int16 i = 0; i < DEF_FONT_COUNT; i++)
102 : {
103 1770 : sDefaultFonts[i] = GetDefaultFor(i,
104 1770 : lcl_LanguageOfType(i, eWestern, eCJK, eCTL));
105 885 : nDefaultFontHeight[i] = -1;
106 : }
107 :
108 118 : Sequence<OUString> aNames = GetPropertyNames();
109 118 : Sequence<Any> aValues = GetProperties(aNames);
110 59 : const Any* pValues = aValues.getConstArray();
111 : OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
112 59 : if(aValues.getLength() == aNames.getLength())
113 : {
114 1829 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
115 : {
116 1770 : 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 59 : }
132 59 : }
133 :
134 0 : void SwStdFontConfig::ImplCommit()
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 52 : SwStdFontConfig::~SwStdFontConfig()
166 : {
167 52 : }
168 :
169 40005 : bool SwStdFontConfig::IsFontDefault(sal_uInt16 nFontType) const
170 : {
171 40005 : bool bSame = false;
172 40005 : SvtLinguOptions aLinguOpt;
173 :
174 40005 : SvtLinguConfig().GetOptions( aLinguOpt );
175 :
176 40005 : sal_Int16 eWestern = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
177 40005 : eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
178 40005 : eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
179 :
180 80010 : OUString sDefFont(GetDefaultFor(FONT_STANDARD, eWestern));
181 80010 : OUString sDefFontCJK(GetDefaultFor(FONT_STANDARD_CJK, eCJK));
182 80010 : OUString sDefFontCTL(GetDefaultFor(FONT_STANDARD_CTL, eCTL));
183 40005 : LanguageType eLang = lcl_LanguageOfType(nFontType, eWestern, eCJK, eCTL);
184 40005 : switch( nFontType )
185 : {
186 : case FONT_STANDARD:
187 2667 : bSame = sDefaultFonts[nFontType] == sDefFont;
188 2667 : break;
189 : case FONT_STANDARD_CJK:
190 2667 : bSame = sDefaultFonts[nFontType] == sDefFontCJK;
191 2667 : break;
192 : case FONT_STANDARD_CTL:
193 2667 : bSame = sDefaultFonts[nFontType] == sDefFontCTL;
194 2667 : break;
195 : case FONT_OUTLINE :
196 : case FONT_OUTLINE_CJK :
197 : case FONT_OUTLINE_CTL :
198 16002 : bSame = sDefaultFonts[nFontType] ==
199 8001 : GetDefaultFor(nFontType, eLang);
200 8001 : break;
201 : case FONT_LIST :
202 : case FONT_CAPTION :
203 : case FONT_INDEX :
204 16002 : bSame = sDefaultFonts[nFontType] == sDefFont &&
205 16002 : sDefaultFonts[FONT_STANDARD] == sDefFont;
206 8001 : break;
207 : case FONT_LIST_CJK :
208 : case FONT_CAPTION_CJK :
209 : case FONT_INDEX_CJK :
210 : {
211 8001 : bool b1 = sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCJK;
212 8001 : bSame = b1 && sDefaultFonts[nFontType] == sDefFontCJK;
213 : }
214 8001 : break;
215 : case FONT_LIST_CTL :
216 : case FONT_CAPTION_CTL :
217 : case FONT_INDEX_CTL :
218 : {
219 8001 : bool b1 = sDefaultFonts[FONT_STANDARD_CJK] == sDefFontCTL;
220 8001 : bSame = b1 && sDefaultFonts[nFontType] == sDefFontCTL;
221 : }
222 8001 : break;
223 : }
224 80010 : return bSame;
225 : }
226 :
227 128901 : OUString SwStdFontConfig::GetDefaultFor(sal_uInt16 nFontType, LanguageType eLang)
228 : {
229 : DefaultFontType nFontId;
230 128901 : switch( nFontType )
231 : {
232 : case FONT_OUTLINE :
233 2726 : nFontId = DefaultFontType::LATIN_HEADING;
234 2726 : break;
235 : case FONT_OUTLINE_CJK :
236 2726 : nFontId = DefaultFontType::CJK_HEADING;
237 2726 : break;
238 : case FONT_OUTLINE_CTL :
239 2726 : nFontId = DefaultFontType::CTL_HEADING;
240 2726 : break;
241 : case FONT_STANDARD_CJK:
242 : case FONT_LIST_CJK :
243 : case FONT_CAPTION_CJK :
244 : case FONT_INDEX_CJK :
245 40241 : nFontId = DefaultFontType::CJK_TEXT;
246 40241 : break;
247 : case FONT_STANDARD_CTL:
248 : case FONT_LIST_CTL :
249 : case FONT_CAPTION_CTL :
250 : case FONT_INDEX_CTL :
251 40241 : nFontId = DefaultFontType::CTL_TEXT;
252 40241 : break;
253 : default:
254 40241 : nFontId = DefaultFontType::LATIN_TEXT;
255 : }
256 128901 : vcl::Font aFont = OutputDevice::GetDefaultFont(nFontId, eLang, GetDefaultFontFlags::OnlyOne);
257 128901 : return aFont.GetName();
258 : }
259 :
260 40005 : sal_Int32 SwStdFontConfig::GetDefaultHeightFor(sal_uInt16 nFontType, LanguageType eLang)
261 : {
262 40005 : sal_Int32 nRet = FONTSIZE_DEFAULT;
263 40005 : switch( nFontType )
264 : {
265 : case FONT_OUTLINE:
266 : case FONT_OUTLINE_CJK:
267 : case FONT_OUTLINE_CTL:
268 8001 : nRet = FONTSIZE_OUTLINE;
269 8001 : break;
270 : case FONT_STANDARD_CJK:
271 2667 : nRet = FONTSIZE_CJK_DEFAULT;
272 2667 : break;
273 : }
274 40005 : if( eLang == LANGUAGE_THAI && nFontType >= FONT_STANDARD_CTL )
275 : {
276 0 : nRet = nRet * 4 / 3;
277 : }
278 40005 : 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 40005 : 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 40005 : sal_Int32 nRet = nDefaultFontHeight[nFont + FONT_PER_GROUP * nScriptType];
313 40005 : if(nRet <= 0)
314 40005 : return GetDefaultHeightFor(nFont + FONT_PER_GROUP * nScriptType, eLang);
315 0 : return nRet;
316 : }
317 :
318 0 : void SwStdFontConfig::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
319 :
320 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|