LCOV - code coverage report
Current view: top level - svtools/source/config - fontsubstconfig.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 105 31.4 %
Date: 2012-08-25 Functions: 5 12 41.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 112 22.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <svtools/fontsubstconfig.hxx>
      30                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      31                 :            : #include <com/sun/star/uno/Any.hxx>
      32                 :            : #include <com/sun/star/uno/Sequence.hxx>
      33                 :            : #include <tools/debug.hxx>
      34                 :            : #include <vcl/outdev.hxx>
      35                 :            : #include <rtl/logfile.hxx>
      36                 :            : 
      37                 :            : #include <boost/ptr_container/ptr_vector.hpp>
      38                 :            : 
      39                 :            : using namespace utl;
      40                 :            : using namespace com::sun::star;
      41                 :            : using namespace com::sun::star::uno;
      42                 :            : using namespace com::sun::star::beans;
      43                 :            : 
      44                 :            : using ::rtl::OUString;
      45                 :            : 
      46                 :            : #define C2U(cChar) OUString::createFromAscii(cChar)
      47                 :            : 
      48                 :            : const sal_Char cReplacement[] = "Replacement";
      49                 :            : const sal_Char cFontPairs[] = "FontPairs";
      50                 :            : 
      51                 :            : const sal_Char cReplaceFont[]   = "ReplaceFont";
      52                 :            : const sal_Char cSubstituteFont[]= "SubstituteFont";
      53                 :            : const sal_Char cOnScreenOnly[]  = "OnScreenOnly";
      54                 :            : const sal_Char cAlways[]        = "Always";
      55                 :            : 
      56                 :            : typedef boost::ptr_vector<SubstitutionStruct> SubstitutionStructArr;
      57                 :            : 
      58                 :        316 : struct SvtFontSubstConfig_Impl
      59                 :            : {
      60                 :            :     SubstitutionStructArr   aSubstArr;
      61                 :            : };
      62                 :            : 
      63                 :        158 : SvtFontSubstConfig::SvtFontSubstConfig() :
      64                 :            :     ConfigItem(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Font/Substitution"))),
      65                 :            :     bIsEnabled(sal_False),
      66 [ +  - ][ +  - ]:        158 :     pImpl(new SvtFontSubstConfig_Impl)
                 [ +  - ]
      67                 :            : {
      68                 :            :     RTL_LOGFILE_CONTEXT(aLog, "svtools SvtFontSubstConfig::SvtFontSubstConfig()");
      69                 :            : 
      70         [ +  - ]:        158 :     Sequence<OUString> aNames(1);
      71         [ +  - ]:        158 :     aNames.getArray()[0] = C2U(cReplacement);
      72         [ +  - ]:        158 :     Sequence<Any> aValues = GetProperties(aNames);
      73                 :            :     DBG_ASSERT(aValues.getConstArray()[0].hasValue(), "no value available");
      74         [ +  - ]:        158 :     if(aValues.getConstArray()[0].hasValue())
      75                 :        158 :         bIsEnabled = *(sal_Bool*)aValues.getConstArray()[0].getValue();
      76                 :            : 
      77                 :        158 :     OUString sPropPrefix(C2U(cFontPairs));
      78         [ +  - ]:        158 :     Sequence<OUString> aNodeNames = GetNodeNames(sPropPrefix, CONFIG_NAME_LOCAL_PATH);
      79                 :        158 :     const OUString* pNodeNames = aNodeNames.getConstArray();
      80         [ +  - ]:        158 :     Sequence<OUString> aPropNames(aNodeNames.getLength() * 4);
      81         [ +  - ]:        158 :     OUString* pNames = aPropNames.getArray();
      82                 :        158 :     sal_Int32 nName = 0;
      83         [ +  - ]:        158 :     sPropPrefix += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
      84                 :            :     sal_Int32 nNode;
      85         [ -  + ]:        158 :     for(nNode = 0; nNode < aNodeNames.getLength(); nNode++)
      86                 :            :     {
      87                 :          0 :         OUString sStart(sPropPrefix);
      88                 :          0 :         sStart += pNodeNames[nNode];
      89         [ #  # ]:          0 :         sStart += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
      90                 :          0 :         pNames[nName] = sStart;     pNames[nName++] += C2U(cReplaceFont);
      91                 :          0 :         pNames[nName] = sStart;     pNames[nName++] += C2U(cSubstituteFont);
      92                 :          0 :         pNames[nName] = sStart;     pNames[nName++] += C2U(cAlways);
      93                 :          0 :         pNames[nName] = sStart;     pNames[nName++] += C2U(cOnScreenOnly);
      94                 :          0 :     }
      95         [ +  - ]:        158 :     Sequence<Any> aNodeValues = GetProperties(aPropNames);
      96                 :        158 :     const Any* pNodeValues = aNodeValues.getConstArray();
      97                 :        158 :     nName = 0;
      98         [ -  + ]:        158 :     for(nNode = 0; nNode < aNodeNames.getLength(); nNode++)
      99                 :            :     {
     100         [ #  # ]:          0 :         SubstitutionStruct* pInsert = new SubstitutionStruct;
     101                 :          0 :         pNodeValues[nName++] >>= pInsert->sFont;
     102                 :          0 :         pNodeValues[nName++] >>= pInsert->sReplaceBy;
     103                 :          0 :         pInsert->bReplaceAlways = *(sal_Bool*)pNodeValues[nName++].getValue();
     104                 :          0 :         pInsert->bReplaceOnScreenOnly = *(sal_Bool*)pNodeValues[nName++].getValue();
     105         [ #  # ]:          0 :         pImpl->aSubstArr.push_back(pInsert);
     106 [ +  - ][ +  - ]:        158 :     }
         [ +  - ][ +  - ]
                 [ +  - ]
     107                 :        158 : }
     108                 :            : 
     109                 :        158 : SvtFontSubstConfig::~SvtFontSubstConfig()
     110                 :            : {
     111 [ +  - ][ +  - ]:        158 :     delete pImpl;
     112         [ -  + ]:        158 : }
     113                 :            : 
     114                 :          0 : void SvtFontSubstConfig::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
     115                 :            : {
     116                 :          0 : }
     117                 :            : 
     118                 :          0 : void SvtFontSubstConfig::Commit()
     119                 :            : {
     120         [ #  # ]:          0 :     Sequence<OUString> aNames(1);
     121         [ #  # ]:          0 :     aNames.getArray()[0] = C2U(cReplacement);
     122         [ #  # ]:          0 :     Sequence<Any> aValues(1);
     123 [ #  # ][ #  # ]:          0 :     aValues.getArray()[0].setValue(&bIsEnabled, ::getBooleanCppuType());
     124         [ #  # ]:          0 :     PutProperties(aNames, aValues);
     125                 :            : 
     126                 :          0 :     OUString sNode(C2U(cFontPairs));
     127         [ #  # ]:          0 :     if(pImpl->aSubstArr.empty())
     128         [ #  # ]:          0 :         ClearNodeSet(sNode);
     129                 :            :     else
     130                 :            :     {
     131         [ #  # ]:          0 :         Sequence<PropertyValue> aSetValues(4 * pImpl->aSubstArr.size());
     132         [ #  # ]:          0 :         PropertyValue* pSetValues = aSetValues.getArray();
     133                 :          0 :         sal_Int32 nSetValue = 0;
     134                 :            : 
     135                 :          0 :         const OUString sReplaceFont(C2U(cReplaceFont));
     136                 :          0 :         const OUString sSubstituteFont(C2U(cSubstituteFont));
     137                 :          0 :         const OUString sAlways(C2U(cAlways));
     138                 :          0 :         const OUString sOnScreenOnly(C2U(cOnScreenOnly));
     139                 :            : 
     140         [ #  # ]:          0 :         const uno::Type& rBoolType = ::getBooleanCppuType();
     141         [ #  # ]:          0 :         for(size_t i = 0; i < pImpl->aSubstArr.size(); i++)
     142                 :            :         {
     143                 :          0 :             OUString sPrefix(sNode);
     144                 :          0 :             sPrefix += C2U("/_");
     145                 :          0 :             sPrefix += OUString::valueOf((sal_Int32)i);
     146                 :          0 :             sPrefix += C2U("/");
     147                 :            : 
     148         [ #  # ]:          0 :             SubstitutionStruct& pSubst = pImpl->aSubstArr[i];
     149                 :          0 :             pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sReplaceFont;
     150         [ #  # ]:          0 :             pSetValues[nSetValue++].Value <<= pSubst.sFont;
     151                 :          0 :             pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sSubstituteFont;
     152         [ #  # ]:          0 :             pSetValues[nSetValue++].Value <<= pSubst.sReplaceBy;
     153                 :          0 :             pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sAlways;
     154                 :          0 :             pSetValues[nSetValue++].Value.setValue(&pSubst.bReplaceAlways, rBoolType);
     155                 :          0 :             pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sOnScreenOnly;
     156                 :          0 :             pSetValues[nSetValue++].Value.setValue(&pSubst.bReplaceOnScreenOnly, rBoolType);
     157                 :          0 :         }
     158 [ #  # ][ #  # ]:          0 :         ReplaceSetProperties(sNode, aSetValues);
         [ #  # ][ #  # ]
     159 [ #  # ][ #  # ]:          0 :     }
     160                 :          0 : }
     161                 :            : 
     162                 :          0 : sal_Int32 SvtFontSubstConfig::SubstitutionCount() const
     163                 :            : {
     164                 :          0 :     return pImpl->aSubstArr.size();
     165                 :            : }
     166                 :            : 
     167                 :          0 : void SvtFontSubstConfig::ClearSubstitutions()
     168                 :            : {
     169                 :          0 :     pImpl->aSubstArr.clear();
     170                 :          0 : }
     171                 :            : 
     172                 :          0 : const SubstitutionStruct* SvtFontSubstConfig::GetSubstitution(sal_Int32 nPos)
     173                 :            : {
     174                 :          0 :     sal_Int32 nCount = static_cast<sal_Int32>(pImpl->aSubstArr.size());
     175                 :            :     DBG_ASSERT(nPos >= 0 && nPos < nCount, "illegal array index");
     176 [ #  # ][ #  # ]:          0 :     if(nPos >= 0 && nPos < nCount)
     177                 :          0 :         return &pImpl->aSubstArr[nPos];
     178                 :          0 :     return NULL;
     179                 :            : }
     180                 :            : 
     181                 :          0 : void SvtFontSubstConfig::AddSubstitution(const SubstitutionStruct& rToAdd)
     182                 :            : {
     183                 :          0 :     pImpl->aSubstArr.push_back(new SubstitutionStruct(rToAdd));
     184                 :          0 : }
     185                 :            : 
     186                 :        158 : void SvtFontSubstConfig::Apply()
     187                 :            : {
     188                 :        158 :     OutputDevice::BeginFontSubstitution();
     189                 :            : 
     190                 :            :     // remove old substitions
     191                 :        158 :     sal_uInt16 nOldCount = OutputDevice::GetFontSubstituteCount();
     192                 :            : 
     193         [ -  + ]:        158 :     while (nOldCount)
     194                 :          0 :         OutputDevice::RemoveFontSubstitute(--nOldCount);
     195                 :            : 
     196                 :            :     // read new substitutions
     197         [ -  + ]:        158 :     sal_Int32 nCount = IsEnabled() ? SubstitutionCount() : 0;
     198                 :            : 
     199         [ -  + ]:        158 :     for (sal_Int32  i = 0; i < nCount; i++)
     200                 :            :     {
     201                 :          0 :         sal_uInt16 nFlags = 0;
     202                 :          0 :         const SubstitutionStruct* pSubs = GetSubstitution(i);
     203         [ #  # ]:          0 :         if(pSubs->bReplaceAlways)
     204                 :          0 :             nFlags |= FONT_SUBSTITUTE_ALWAYS;
     205         [ #  # ]:          0 :         if(pSubs->bReplaceOnScreenOnly)
     206                 :          0 :             nFlags |= FONT_SUBSTITUTE_SCREENONLY;
     207 [ #  # ][ #  # ]:          0 :         OutputDevice::AddFontSubstitute( String(pSubs->sFont), String(pSubs->sReplaceBy), nFlags );
                 [ #  # ]
     208                 :            :     }
     209                 :            : 
     210                 :        158 :     OutputDevice::EndFontSubstitution();
     211                 :        158 : }
     212                 :            : 
     213                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10