LCOV - code coverage report
Current view: top level - xmloff/source/style - fonthdl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 121 0.0 %
Date: 2014-04-14 Functions: 0 17 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 <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           0 : 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           0 :     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           0 : XMLFontFamilyNamePropHdl::~XMLFontFamilyNamePropHdl()
      59             : {
      60             :     // Nothing to do
      61           0 : }
      62             : 
      63           0 : bool XMLFontFamilyNamePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
      64             : {
      65           0 :     bool bRet = false;
      66           0 :     OUStringBuffer sValue;
      67           0 :     sal_Int32 nPos = 0;
      68             : 
      69           0 :     do
      70             :     {
      71           0 :         sal_Int32 nFirst = nPos;
      72           0 :         nPos = ::sax::Converter::indexOfComma( rStrImpValue, nPos );
      73           0 :         sal_Int32 nLast = (-1 == nPos ? rStrImpValue.getLength() - 1 : nPos - 1);
      74             : 
      75             :         // skip trailing blanks
      76           0 :         while( nLast > nFirst && ' ' == rStrImpValue[nLast] )
      77           0 :             nLast--;
      78             : 
      79             :         // skip leading blanks
      80           0 :         while(nFirst <= nLast && ' ' == rStrImpValue[nFirst])
      81           0 :             nFirst++;
      82             : 
      83             :         // remove quotes
      84           0 :         sal_Unicode c = nFirst > nLast ? 0 : rStrImpValue[nFirst];
      85           0 :         if( nFirst < nLast && ('\'' == c || '\"' == c) && rStrImpValue[nLast] == c )
      86             :         {
      87           0 :             nFirst++;
      88           0 :             nLast--;
      89             :         }
      90             : 
      91           0 :         if( nFirst <= nLast )
      92             :         {
      93           0 :             if( !sValue.isEmpty() )
      94           0 :                 sValue.append(';');
      95             : 
      96           0 :             sValue.append(rStrImpValue.copy( nFirst, nLast-nFirst+1));
      97             :         }
      98             : 
      99           0 :         if( -1 != nPos )
     100           0 :             nPos++;
     101             :     }
     102             :     while( -1 != nPos );
     103             : 
     104           0 :     if (!sValue.isEmpty())
     105             :     {
     106           0 :         rValue <<= sValue.makeStringAndClear();
     107           0 :         bRet = true;
     108             :     }
     109             : 
     110           0 :     return bRet;
     111             : }
     112             : 
     113           0 : bool XMLFontFamilyNamePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     114             : {
     115           0 :     bool bRet = false;
     116           0 :     OUString aStrFamilyName;
     117             : 
     118           0 :     if( rValue >>= aStrFamilyName )
     119             :     {
     120           0 :         OUStringBuffer sValue( aStrFamilyName.getLength() + 2L );
     121           0 :         sal_Int32 nPos = 0;
     122           0 :         do
     123             :         {
     124           0 :             sal_Int32 nFirst = nPos;
     125           0 :             nPos = aStrFamilyName.indexOf( ';', nPos );
     126           0 :             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           0 :             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           0 :             if( 0L == nLast )
     137           0 :                 continue;
     138             : 
     139             :             // nFirst and nLast now denote the first and last character of
     140             :             // one font name.
     141           0 :             nLast--;
     142             : 
     143             :             // skip trailing blanks
     144           0 :             while(  nLast > nFirst && ' ' == aStrFamilyName[nLast] )
     145           0 :                 nLast--;
     146             : 
     147             :             // skip leading blanks
     148           0 :             while( nFirst <= nLast && ' ' == aStrFamilyName[nFirst] )
     149           0 :                 nFirst++;
     150             : 
     151           0 :             if( nFirst <= nLast )
     152             :             {
     153           0 :                 if( !sValue.isEmpty() )
     154             :                 {
     155           0 :                     sValue.append( ',' );
     156           0 :                     sValue.append( ' ' );
     157             :                 }
     158           0 :                 sal_Int32 nLen = nLast-nFirst+1;
     159           0 :                 OUString sFamily( aStrFamilyName.copy( nFirst, nLen ) );
     160           0 :                 bool bQuote = false;
     161           0 :                 for( sal_Int32 i=0; i < nLen; i++ )
     162             :                 {
     163           0 :                     sal_Unicode c = sFamily[i];
     164           0 :                     if( ' ' == c || ',' == c )
     165             :                     {
     166           0 :                         bQuote = true;
     167           0 :                         break;
     168             :                     }
     169             :                 }
     170           0 :                 if( bQuote )
     171           0 :                     sValue.append( '\'' );
     172           0 :                 sValue.append( sFamily );
     173           0 :                 if( bQuote )
     174           0 :                     sValue.append( '\'' );
     175             :             }
     176             :         }
     177             :         while( -1L != nPos );
     178             : 
     179           0 :         rStrExpValue = sValue.makeStringAndClear();
     180             : 
     181           0 :         bRet = true;
     182             :     }
     183             : 
     184           0 :     return bRet;
     185             : }
     186             : 
     187             : // class XMLFontFamilyPropHdl
     188             : 
     189           0 : XMLFontFamilyPropHdl::~XMLFontFamilyPropHdl()
     190             : {
     191             :     // Nothing to do
     192           0 : }
     193             : 
     194           0 : bool XMLFontFamilyPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
     195             : {
     196             :     sal_uInt16 eNewFamily;
     197           0 :     bool bRet = SvXMLUnitConverter::convertEnum( eNewFamily, rStrImpValue, lcl_getFontFamilyGenericMapping() );
     198           0 :     if( bRet )
     199           0 :         rValue <<= (sal_Int16)eNewFamily;
     200             : 
     201           0 :     return bRet;
     202             : }
     203             : 
     204           0 : bool XMLFontFamilyPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     205             : {
     206           0 :     bool bRet = false;
     207           0 :     OUStringBuffer aOut;
     208             : 
     209           0 :     sal_Int16 nFamily = sal_Int16();
     210           0 :     if( rValue >>= nFamily )
     211             :     {
     212           0 :         FontFamily eFamily = (FontFamily)nFamily;
     213           0 :         if( eFamily != FAMILY_DONTKNOW )
     214           0 :             bRet = SvXMLUnitConverter::convertEnum( aOut, eFamily, lcl_getFontFamilyGenericMapping() );
     215             :     }
     216             : 
     217           0 :     rStrExpValue = aOut.makeStringAndClear();
     218             : 
     219           0 :     return bRet;
     220             : }
     221             : 
     222             : // class XMLFontEncodingPropHdl
     223             : 
     224           0 : XMLFontEncodingPropHdl::~XMLFontEncodingPropHdl()
     225             : {
     226             :     // Nothing to do
     227           0 : }
     228             : 
     229           0 : bool XMLFontEncodingPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
     230             : {
     231           0 :     bool bRet = true;
     232             : 
     233           0 :     if( IsXMLToken( rStrImpValue, XML_X_SYMBOL ) )
     234           0 :         rValue <<= (sal_Int16) RTL_TEXTENCODING_SYMBOL;
     235             : 
     236           0 :     return bRet;
     237             : }
     238             : 
     239           0 : bool XMLFontEncodingPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     240             : {
     241           0 :     bool bRet = false;
     242           0 :     OUStringBuffer aOut;
     243           0 :     sal_Int16 nSet = sal_Int16();
     244             : 
     245           0 :     if( rValue >>= nSet )
     246             :     {
     247           0 :         if( (rtl_TextEncoding)nSet == RTL_TEXTENCODING_SYMBOL )
     248             :         {
     249           0 :             aOut.append( GetXMLToken(XML_X_SYMBOL) );
     250           0 :             rStrExpValue = aOut.makeStringAndClear();
     251           0 :             bRet = true;
     252             :         }
     253             :     }
     254             : 
     255           0 :     return bRet;
     256             : }
     257             : 
     258             : // class XMLFontPitchPropHdl
     259             : 
     260           0 : XMLFontPitchPropHdl::~XMLFontPitchPropHdl()
     261             : {
     262             :     // Nothing to do
     263           0 : }
     264             : 
     265           0 : bool XMLFontPitchPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
     266             : {
     267             :     sal_uInt16 eNewPitch;
     268           0 :     bool bRet = SvXMLUnitConverter::convertEnum( eNewPitch, rStrImpValue, aFontPitchMapping );
     269           0 :     if( bRet )
     270           0 :         rValue <<= (sal_Int16)eNewPitch;
     271             : 
     272           0 :     return bRet;
     273             : }
     274             : 
     275           0 : bool XMLFontPitchPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     276             : {
     277           0 :     bool bRet = false;
     278           0 :     sal_Int16 nPitch = sal_Int16();
     279           0 :     OUStringBuffer aOut;
     280             : 
     281           0 :     FontPitch ePitch = PITCH_DONTKNOW;
     282           0 :     if( rValue >>= nPitch )
     283           0 :         ePitch =  (FontPitch)nPitch;
     284             : 
     285           0 :     if( PITCH_DONTKNOW != ePitch )
     286             :     {
     287           0 :         bRet = SvXMLUnitConverter::convertEnum( aOut, ePitch, aFontPitchMapping, XML_FIXED );
     288           0 :         rStrExpValue = aOut.makeStringAndClear();
     289             :     }
     290             : 
     291           0 :     return bRet;
     292             : }
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10