LCOV - code coverage report
Current view: top level - xmloff/source/style - escphdl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 49 56 87.5 %
Date: 2014-04-11 Functions: 8 8 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 <escphdl.hxx>
      21             : 
      22             : #include <sax/tools/converter.hxx>
      23             : #include <xmloff/xmltoken.hxx>
      24             : #include <xmloff/xmluconv.hxx>
      25             : #include <rtl/ustrbuf.hxx>
      26             : #include <com/sun/star/uno/Any.hxx>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::xmloff::token;
      30             : 
      31             : // this is a copy of defines in svx/inc/escpitem.hxx
      32             : #define DFLT_ESC_PROP    58
      33             : #define DFLT_ESC_AUTO_SUPER 101
      34             : #define DFLT_ESC_AUTO_SUB  -101
      35             : 
      36             : 
      37             : // class XMLEscapementPropHdl
      38             : 
      39             : 
      40       11262 : XMLEscapementPropHdl::~XMLEscapementPropHdl()
      41             : {
      42             :     // nothing to do
      43       11262 : }
      44             : 
      45         406 : bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
      46             : {
      47             :     sal_Int16 nVal;
      48             : 
      49         406 :     SvXMLTokenEnumerator aTokens( rStrImpValue );
      50             : 
      51         406 :     OUString aToken;
      52         406 :     if( ! aTokens.getNextToken( aToken ) )
      53           0 :         return false;
      54             : 
      55         406 :     if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) )
      56             :     {
      57           2 :         nVal = DFLT_ESC_AUTO_SUB;
      58             :     }
      59         404 :     else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) )
      60             :     {
      61          14 :         nVal = DFLT_ESC_AUTO_SUPER;
      62             :     }
      63             :     else
      64             :     {
      65             :         sal_Int32 nNewEsc;
      66         390 :         if (!::sax::Converter::convertPercent( nNewEsc, aToken ))
      67           0 :             return false;
      68             : 
      69         390 :         nVal = (sal_Int16) nNewEsc;
      70             :     }
      71             : 
      72         406 :     rValue <<= nVal;
      73         406 :     return true;
      74             : }
      75             : 
      76         818 : bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
      77             : {
      78         818 :     sal_Int32 nValue = 0;
      79         818 :     OUStringBuffer aOut;
      80             : 
      81         818 :     if( rValue >>= nValue )
      82             :     {
      83         818 :         if( nValue == DFLT_ESC_AUTO_SUPER )
      84             :         {
      85           1 :             aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) );
      86             :         }
      87         817 :         else if( nValue == DFLT_ESC_AUTO_SUB )
      88             :         {
      89           0 :             aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) );
      90             :         }
      91             :         else
      92             :         {
      93         817 :             ::sax::Converter::convertPercent( aOut, nValue );
      94             :         }
      95             :     }
      96             : 
      97         818 :     rStrExpValue = aOut.makeStringAndClear();
      98         818 :     return true;
      99             : }
     100             : 
     101             : 
     102             : // class XMLEscapementHeightPropHdl
     103             : 
     104             : 
     105       11262 : XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
     106             : {
     107             :     // nothing to do
     108       11262 : }
     109             : 
     110         406 : bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
     111             : {
     112         406 :     if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
     113           0 :         return false;
     114             : 
     115         406 :     SvXMLTokenEnumerator aTokens( rStrImpValue );
     116             : 
     117         406 :     OUString aToken;
     118         406 :     if( ! aTokens.getNextToken( aToken ) )
     119           0 :         return false;
     120             : 
     121             :     sal_Int8 nProp;
     122         406 :     if( aTokens.getNextToken( aToken ) )
     123             :     {
     124             :         sal_Int32 nNewProp;
     125         382 :         if (!::sax::Converter::convertPercent( nNewProp, aToken ))
     126           0 :             return false;
     127         382 :         nProp = (sal_Int8)nNewProp;
     128             :     }
     129             :     else
     130             :     {
     131          24 :         sal_Int32 nEscapementPosition=0;
     132          48 :         if (::sax::Converter::convertPercent( nEscapementPosition, aToken )
     133          24 :             && (nEscapementPosition == 0))
     134             :         {
     135          24 :             nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
     136             :         }
     137             :         else
     138           0 :             nProp = (sal_Int8) DFLT_ESC_PROP;
     139             :     }
     140             : 
     141         406 :     rValue <<= nProp;
     142         406 :     return true;
     143             : }
     144             : 
     145         818 : bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     146             : {
     147         818 :     OUStringBuffer aOut( rStrExpValue );
     148             : 
     149         818 :     sal_Int32 nValue = 0;
     150         818 :     if( rValue >>= nValue )
     151             :     {
     152         818 :         if( !rStrExpValue.isEmpty() )
     153         818 :             aOut.append( ' ');
     154             : 
     155         818 :         ::sax::Converter::convertPercent( aOut, nValue );
     156             :     }
     157             : 
     158         818 :     rStrExpValue = aOut.makeStringAndClear();
     159         818 :     return !rStrExpValue.isEmpty();
     160             : }
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10