LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/config - fontcfg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 92 135 68.1 %
Date: 2013-07-09 Functions: 11 14 78.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10