LCOV - code coverage report
Current view: top level - svtools/source/config - fontsubstconfig.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 100 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
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             : #include <svtools/fontsubstconfig.hxx>
      21             : #include <com/sun/star/beans/PropertyValue.hpp>
      22             : #include <com/sun/star/uno/Any.hxx>
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <tools/debug.hxx>
      25             : #include <vcl/outdev.hxx>
      26             : 
      27             : #include <boost/ptr_container/ptr_vector.hpp>
      28             : 
      29             : using namespace utl;
      30             : using namespace com::sun::star;
      31             : using namespace com::sun::star::uno;
      32             : using namespace com::sun::star::beans;
      33             : 
      34             : 
      35             : const sal_Char cReplacement[] = "Replacement";
      36             : const sal_Char cFontPairs[] = "FontPairs";
      37             : 
      38             : const sal_Char cReplaceFont[]   = "ReplaceFont";
      39             : const sal_Char cSubstituteFont[]= "SubstituteFont";
      40             : const sal_Char cOnScreenOnly[]  = "OnScreenOnly";
      41             : const sal_Char cAlways[]        = "Always";
      42             : 
      43             : typedef boost::ptr_vector<SubstitutionStruct> SubstitutionStructArr;
      44             : 
      45           0 : struct SvtFontSubstConfig_Impl
      46             : {
      47             :     SubstitutionStructArr   aSubstArr;
      48             : };
      49             : 
      50           0 : SvtFontSubstConfig::SvtFontSubstConfig() :
      51             :     ConfigItem(OUString("Office.Common/Font/Substitution")),
      52             :     bIsEnabled(false),
      53           0 :     pImpl(new SvtFontSubstConfig_Impl)
      54             : {
      55           0 :     Sequence<OUString> aNames(1);
      56           0 :     aNames.getArray()[0] = cReplacement;
      57           0 :     Sequence<Any> aValues = GetProperties(aNames);
      58             :     DBG_ASSERT(aValues.getConstArray()[0].hasValue(), "no value available");
      59           0 :     if(aValues.getConstArray()[0].hasValue())
      60           0 :         bIsEnabled = *(sal_Bool*)aValues.getConstArray()[0].getValue();
      61             : 
      62           0 :     OUString sPropPrefix(cFontPairs);
      63           0 :     Sequence<OUString> aNodeNames = GetNodeNames(sPropPrefix, CONFIG_NAME_LOCAL_PATH);
      64           0 :     const OUString* pNodeNames = aNodeNames.getConstArray();
      65           0 :     Sequence<OUString> aPropNames(aNodeNames.getLength() * 4);
      66           0 :     OUString* pNames = aPropNames.getArray();
      67           0 :     sal_Int32 nName = 0;
      68           0 :     sPropPrefix += "/";
      69             :     sal_Int32 nNode;
      70           0 :     for(nNode = 0; nNode < aNodeNames.getLength(); nNode++)
      71             :     {
      72           0 :         OUString sStart = sPropPrefix + pNodeNames[nNode] + "/";
      73           0 :         pNames[nName] = sStart;     pNames[nName++] += cReplaceFont;
      74           0 :         pNames[nName] = sStart;     pNames[nName++] += cSubstituteFont;
      75           0 :         pNames[nName] = sStart;     pNames[nName++] += cAlways;
      76           0 :         pNames[nName] = sStart;     pNames[nName++] += cOnScreenOnly;
      77           0 :     }
      78           0 :     Sequence<Any> aNodeValues = GetProperties(aPropNames);
      79           0 :     const Any* pNodeValues = aNodeValues.getConstArray();
      80           0 :     nName = 0;
      81           0 :     for(nNode = 0; nNode < aNodeNames.getLength(); nNode++)
      82             :     {
      83           0 :         SubstitutionStruct* pInsert = new SubstitutionStruct;
      84           0 :         pNodeValues[nName++] >>= pInsert->sFont;
      85           0 :         pNodeValues[nName++] >>= pInsert->sReplaceBy;
      86           0 :         pInsert->bReplaceAlways = *(sal_Bool*)pNodeValues[nName++].getValue();
      87           0 :         pInsert->bReplaceOnScreenOnly = *(sal_Bool*)pNodeValues[nName++].getValue();
      88           0 :         pImpl->aSubstArr.push_back(pInsert);
      89           0 :     }
      90           0 : }
      91             : 
      92           0 : SvtFontSubstConfig::~SvtFontSubstConfig()
      93             : {
      94           0 :     delete pImpl;
      95           0 : }
      96             : 
      97           0 : void SvtFontSubstConfig::Notify( const com::sun::star::uno::Sequence< OUString >& )
      98             : {
      99           0 : }
     100             : 
     101           0 : void SvtFontSubstConfig::Commit()
     102             : {
     103           0 :     Sequence<OUString> aNames(1);
     104           0 :     aNames.getArray()[0] = cReplacement;
     105           0 :     Sequence<Any> aValues(1);
     106           0 :     aValues.getArray()[0].setValue(&bIsEnabled, ::getBooleanCppuType());
     107           0 :     PutProperties(aNames, aValues);
     108             : 
     109           0 :     OUString sNode(cFontPairs);
     110           0 :     if(pImpl->aSubstArr.empty())
     111           0 :         ClearNodeSet(sNode);
     112             :     else
     113             :     {
     114           0 :         Sequence<PropertyValue> aSetValues(4 * pImpl->aSubstArr.size());
     115           0 :         PropertyValue* pSetValues = aSetValues.getArray();
     116           0 :         sal_Int32 nSetValue = 0;
     117             : 
     118           0 :         const OUString sReplaceFont(cReplaceFont);
     119           0 :         const OUString sSubstituteFont(cSubstituteFont);
     120           0 :         const OUString sAlways(cAlways);
     121           0 :         const OUString sOnScreenOnly(cOnScreenOnly);
     122             : 
     123           0 :         const uno::Type& rBoolType = ::getBooleanCppuType();
     124           0 :         for(size_t i = 0; i < pImpl->aSubstArr.size(); i++)
     125             :         {
     126           0 :             OUString sPrefix = sNode + "/_" + OUString::number(i) + "/";
     127             : 
     128           0 :             SubstitutionStruct& pSubst = pImpl->aSubstArr[i];
     129           0 :             pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sReplaceFont;
     130           0 :             pSetValues[nSetValue++].Value <<= pSubst.sFont;
     131           0 :             pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sSubstituteFont;
     132           0 :             pSetValues[nSetValue++].Value <<= pSubst.sReplaceBy;
     133           0 :             pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sAlways;
     134           0 :             pSetValues[nSetValue++].Value.setValue(&pSubst.bReplaceAlways, rBoolType);
     135           0 :             pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sOnScreenOnly;
     136           0 :             pSetValues[nSetValue++].Value.setValue(&pSubst.bReplaceOnScreenOnly, rBoolType);
     137           0 :         }
     138           0 :         ReplaceSetProperties(sNode, aSetValues);
     139           0 :     }
     140           0 : }
     141             : 
     142           0 : sal_Int32 SvtFontSubstConfig::SubstitutionCount() const
     143             : {
     144           0 :     return pImpl->aSubstArr.size();
     145             : }
     146             : 
     147           0 : void SvtFontSubstConfig::ClearSubstitutions()
     148             : {
     149           0 :     pImpl->aSubstArr.clear();
     150           0 : }
     151             : 
     152           0 : const SubstitutionStruct* SvtFontSubstConfig::GetSubstitution(sal_Int32 nPos)
     153             : {
     154           0 :     sal_Int32 nCount = static_cast<sal_Int32>(pImpl->aSubstArr.size());
     155             :     DBG_ASSERT(nPos >= 0 && nPos < nCount, "illegal array index");
     156           0 :     if(nPos >= 0 && nPos < nCount)
     157           0 :         return &pImpl->aSubstArr[nPos];
     158           0 :     return NULL;
     159             : }
     160             : 
     161           0 : void SvtFontSubstConfig::AddSubstitution(const SubstitutionStruct& rToAdd)
     162             : {
     163           0 :     pImpl->aSubstArr.push_back(new SubstitutionStruct(rToAdd));
     164           0 : }
     165             : 
     166           0 : void SvtFontSubstConfig::Apply()
     167             : {
     168           0 :     OutputDevice::BeginFontSubstitution();
     169             : 
     170             :     // remove old substitions
     171           0 :     sal_uInt16 nOldCount = OutputDevice::GetFontSubstituteCount();
     172             : 
     173           0 :     while (nOldCount)
     174           0 :         OutputDevice::RemoveFontSubstitute(--nOldCount);
     175             : 
     176             :     // read new substitutions
     177           0 :     sal_Int32 nCount = IsEnabled() ? SubstitutionCount() : 0;
     178             : 
     179           0 :     for (sal_Int32  i = 0; i < nCount; i++)
     180             :     {
     181           0 :         sal_uInt16 nFlags = 0;
     182           0 :         const SubstitutionStruct* pSubs = GetSubstitution(i);
     183           0 :         if(pSubs->bReplaceAlways)
     184           0 :             nFlags |= FONT_SUBSTITUTE_ALWAYS;
     185           0 :         if(pSubs->bReplaceOnScreenOnly)
     186           0 :             nFlags |= FONT_SUBSTITUTE_SCREENONLY;
     187           0 :         OutputDevice::AddFontSubstitute( pSubs->sFont, pSubs->sReplaceBy, nFlags );
     188             :     }
     189             : 
     190           0 :     OutputDevice::EndFontSubstitution();
     191           0 : }
     192             : 
     193             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10