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