LCOV - code coverage report
Current view: top level - xmloff/source/style - fonthdl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 115 121 95.0 %
Date: 2014-11-03 Functions: 17 17 100.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 <fonthdl.hxx>
      21             : 
      22             : #include <sax/tools/converter.hxx>
      23             : 
      24             : #include <xmloff/xmltoken.hxx>
      25             : #include <xmloff/xmluconv.hxx>
      26             : #include <rtl/ustrbuf.hxx>
      27             : #include <com/sun/star/uno/Any.hxx>
      28             : #include <tools/fontenum.hxx>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : using namespace ::xmloff::token;
      32             : 
      33        9488 : static const SvXMLEnumMapEntry* lcl_getFontFamilyGenericMapping()
      34             : {
      35             :     static SvXMLEnumMapEntry const aFontFamilyGenericMapping[] =
      36             :     {
      37             :         { XML_DECORATIVE,       FAMILY_DECORATIVE },
      38             : 
      39             :         { XML_MODERN,           FAMILY_MODERN   },
      40             :         { XML_ROMAN,            FAMILY_ROMAN    },
      41             :         { XML_SCRIPT,           FAMILY_SCRIPT   },
      42             :         { XML_SWISS,            FAMILY_SWISS    },
      43             :         { XML_SYSTEM,           FAMILY_SYSTEM   },
      44             :         { XML_TOKEN_INVALID,    0               }
      45             :     };
      46        9488 :     return aFontFamilyGenericMapping;
      47             : }
      48             : 
      49             : static SvXMLEnumMapEntry const aFontPitchMapping[] =
      50             : {
      51             :     { XML_FIXED,            PITCH_FIXED     },
      52             :     { XML_VARIABLE,         PITCH_VARIABLE  },
      53             :     { XML_TOKEN_INVALID,    0               }
      54             : };
      55             : 
      56             : // class XMLFontFamilyNamePropHdl
      57             : 
      58       37942 : XMLFontFamilyNamePropHdl::~XMLFontFamilyNamePropHdl()
      59             : {
      60             :     // Nothing to do
      61       37942 : }
      62             : 
      63       12154 : bool XMLFontFamilyNamePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
      64             : {
      65       12154 :     bool bRet = false;
      66       12154 :     OUStringBuffer sValue;
      67       12154 :     sal_Int32 nPos = 0;
      68             : 
      69       12448 :     do
      70             :     {
      71       12448 :         sal_Int32 nFirst = nPos;
      72       12448 :         nPos = ::sax::Converter::indexOfComma( rStrImpValue, nPos );
      73       12448 :         sal_Int32 nLast = (-1 == nPos ? rStrImpValue.getLength() - 1 : nPos - 1);
      74             : 
      75             :         // skip trailing blanks
      76       24896 :         while( nLast > nFirst && ' ' == rStrImpValue[nLast] )
      77           0 :             nLast--;
      78             : 
      79             :         // skip leading blanks
      80       25190 :         while(nFirst <= nLast && ' ' == rStrImpValue[nFirst])
      81         294 :             nFirst++;
      82             : 
      83             :         // remove quotes
      84       12448 :         sal_Unicode c = nFirst > nLast ? 0 : rStrImpValue[nFirst];
      85       12448 :         if( nFirst < nLast && ('\'' == c || '\"' == c) && rStrImpValue[nLast] == c )
      86             :         {
      87        6076 :             nFirst++;
      88        6076 :             nLast--;
      89             :         }
      90             : 
      91       12448 :         if( nFirst <= nLast )
      92             :         {
      93       12396 :             if( !sValue.isEmpty() )
      94         294 :                 sValue.append(';');
      95             : 
      96       12396 :             sValue.append(rStrImpValue.copy( nFirst, nLast-nFirst+1));
      97             :         }
      98             : 
      99       12448 :         if( -1 != nPos )
     100         294 :             nPos++;
     101             :     }
     102             :     while( -1 != nPos );
     103             : 
     104       12154 :     if (!sValue.isEmpty())
     105             :     {
     106       12102 :         rValue <<= sValue.makeStringAndClear();
     107       12102 :         bRet = true;
     108             :     }
     109             : 
     110       12154 :     return bRet;
     111             : }
     112             : 
     113        5286 : bool XMLFontFamilyNamePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     114             : {
     115        5286 :     bool bRet = false;
     116        5286 :     OUString aStrFamilyName;
     117             : 
     118        5286 :     if( rValue >>= aStrFamilyName )
     119             :     {
     120        5286 :         OUStringBuffer sValue( aStrFamilyName.getLength() + 2L );
     121        5286 :         sal_Int32 nPos = 0;
     122        5286 :         do
     123             :         {
     124        5286 :             sal_Int32 nFirst = nPos;
     125        5286 :             nPos = aStrFamilyName.indexOf( ';', nPos );
     126        5286 :             sal_Int32 nLast = (-1 == nPos ? aStrFamilyName.getLength() : nPos);
     127             : 
     128             :             // Set position to the character behind the ';', so we won't
     129             :             // forget this.
     130        5286 :             if( -1L != nPos )
     131           0 :                 nPos++;
     132             : 
     133             :             // If the property value was empty, we stop now.
     134             :             // If there is a ';' at the first position, the empty name
     135             :             // at the start will be removed.
     136        5286 :             if( 0L == nLast )
     137          10 :                 continue;
     138             : 
     139             :             // nFirst and nLast now denote the first and last character of
     140             :             // one font name.
     141        5276 :             nLast--;
     142             : 
     143             :             // skip trailing blanks
     144       10552 :             while(  nLast > nFirst && ' ' == aStrFamilyName[nLast] )
     145           0 :                 nLast--;
     146             : 
     147             :             // skip leading blanks
     148       10552 :             while( nFirst <= nLast && ' ' == aStrFamilyName[nFirst] )
     149           0 :                 nFirst++;
     150             : 
     151        5276 :             if( nFirst <= nLast )
     152             :             {
     153        5276 :                 if( !sValue.isEmpty() )
     154             :                 {
     155           0 :                     sValue.append( ',' );
     156           0 :                     sValue.append( ' ' );
     157             :                 }
     158        5276 :                 sal_Int32 nLen = nLast-nFirst+1;
     159        5276 :                 OUString sFamily( aStrFamilyName.copy( nFirst, nLen ) );
     160        5276 :                 bool bQuote = false;
     161       43672 :                 for( sal_Int32 i=0; i < nLen; i++ )
     162             :                 {
     163       39798 :                     sal_Unicode c = sFamily[i];
     164       39798 :                     if( ' ' == c || ',' == c )
     165             :                     {
     166        1402 :                         bQuote = true;
     167        1402 :                         break;
     168             :                     }
     169             :                 }
     170        5276 :                 if( bQuote )
     171        1402 :                     sValue.append( '\'' );
     172        5276 :                 sValue.append( sFamily );
     173        5276 :                 if( bQuote )
     174        1402 :                     sValue.append( '\'' );
     175             :             }
     176             :         }
     177             :         while( -1L != nPos );
     178             : 
     179        5286 :         rStrExpValue = sValue.makeStringAndClear();
     180             : 
     181        5286 :         bRet = true;
     182             :     }
     183             : 
     184        5286 :     return bRet;
     185             : }
     186             : 
     187             : // class XMLFontFamilyPropHdl
     188             : 
     189       38990 : XMLFontFamilyPropHdl::~XMLFontFamilyPropHdl()
     190             : {
     191             :     // Nothing to do
     192       38990 : }
     193             : 
     194        7668 : bool XMLFontFamilyPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
     195             : {
     196             :     sal_uInt16 eNewFamily;
     197        7668 :     bool bRet = SvXMLUnitConverter::convertEnum( eNewFamily, rStrImpValue, lcl_getFontFamilyGenericMapping() );
     198        7668 :     if( bRet )
     199        7668 :         rValue <<= (sal_Int16)eNewFamily;
     200             : 
     201        7668 :     return bRet;
     202             : }
     203             : 
     204        5286 : bool XMLFontFamilyPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     205             : {
     206        5286 :     bool bRet = false;
     207        5286 :     OUStringBuffer aOut;
     208             : 
     209        5286 :     sal_Int16 nFamily = sal_Int16();
     210        5286 :     if( rValue >>= nFamily )
     211             :     {
     212        5286 :         FontFamily eFamily = (FontFamily)nFamily;
     213        5286 :         if( eFamily != FAMILY_DONTKNOW )
     214        1820 :             bRet = SvXMLUnitConverter::convertEnum( aOut, eFamily, lcl_getFontFamilyGenericMapping() );
     215             :     }
     216             : 
     217        5286 :     rStrExpValue = aOut.makeStringAndClear();
     218             : 
     219        5286 :     return bRet;
     220             : }
     221             : 
     222             : // class XMLFontEncodingPropHdl
     223             : 
     224       38990 : XMLFontEncodingPropHdl::~XMLFontEncodingPropHdl()
     225             : {
     226             :     // Nothing to do
     227       38990 : }
     228             : 
     229         450 : bool XMLFontEncodingPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
     230             : {
     231         450 :     bool bRet = true;
     232             : 
     233         450 :     if( IsXMLToken( rStrImpValue, XML_X_SYMBOL ) )
     234         450 :         rValue <<= (sal_Int16) RTL_TEXTENCODING_SYMBOL;
     235             : 
     236         450 :     return bRet;
     237             : }
     238             : 
     239        2520 : bool XMLFontEncodingPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     240             : {
     241        2520 :     bool bRet = false;
     242        2520 :     OUStringBuffer aOut;
     243        2520 :     sal_Int16 nSet = sal_Int16();
     244             : 
     245        2520 :     if( rValue >>= nSet )
     246             :     {
     247        2520 :         if( (rtl_TextEncoding)nSet == RTL_TEXTENCODING_SYMBOL )
     248             :         {
     249          20 :             aOut.append( GetXMLToken(XML_X_SYMBOL) );
     250          20 :             rStrExpValue = aOut.makeStringAndClear();
     251          20 :             bRet = true;
     252             :         }
     253             :     }
     254             : 
     255        2520 :     return bRet;
     256             : }
     257             : 
     258             : // class XMLFontPitchPropHdl
     259             : 
     260       38990 : XMLFontPitchPropHdl::~XMLFontPitchPropHdl()
     261             : {
     262             :     // Nothing to do
     263       38990 : }
     264             : 
     265        7286 : bool XMLFontPitchPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
     266             : {
     267             :     sal_uInt16 eNewPitch;
     268        7286 :     bool bRet = SvXMLUnitConverter::convertEnum( eNewPitch, rStrImpValue, aFontPitchMapping );
     269        7286 :     if( bRet )
     270        7286 :         rValue <<= (sal_Int16)eNewPitch;
     271             : 
     272        7286 :     return bRet;
     273             : }
     274             : 
     275        5286 : bool XMLFontPitchPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     276             : {
     277        5286 :     bool bRet = false;
     278        5286 :     sal_Int16 nPitch = sal_Int16();
     279        5286 :     OUStringBuffer aOut;
     280             : 
     281        5286 :     FontPitch ePitch = PITCH_DONTKNOW;
     282        5286 :     if( rValue >>= nPitch )
     283        5286 :         ePitch =  (FontPitch)nPitch;
     284             : 
     285        5286 :     if( PITCH_DONTKNOW != ePitch )
     286             :     {
     287        1664 :         bRet = SvXMLUnitConverter::convertEnum( aOut, ePitch, aFontPitchMapping, XML_FIXED );
     288        1664 :         rStrExpValue = aOut.makeStringAndClear();
     289             :     }
     290             : 
     291        5286 :     return bRet;
     292             : }
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10