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

Generated by: LCOV version 1.10