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