LCOV - code coverage report
Current view: top level - xmloff/source/style - chrhghdl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 39 52 75.0 %
Date: 2014-11-03 Functions: 10 12 83.3 %
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 <chrhghdl.hxx>
      21             : 
      22             : #include <rtl/ustrbuf.hxx>
      23             : 
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : 
      26             : #include <sax/tools/converter.hxx>
      27             : 
      28             : #include <xmloff/xmluconv.hxx>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : 
      32             : 
      33             : // class XMLEscapementPropHdl
      34             : 
      35             : 
      36       32144 : XMLCharHeightHdl::~XMLCharHeightHdl()
      37             : {
      38             :     // nothing to do
      39       32144 : }
      40             : 
      41       24212 : bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
      42             : {
      43       24212 :     if( rStrImpValue.indexOf( '%' ) == -1 )
      44             :     {
      45             :         double fSize;
      46             :         sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
      47       24120 :                 rStrImpValue, util::MeasureUnit::POINT );
      48       24120 :         if (::sax::Converter::convertDouble(fSize, rStrImpValue,
      49       24120 :                     eSrcUnit, util::MeasureUnit::POINT))
      50             :         {
      51       24120 :             fSize = ::std::max<double>(fSize, 1.0); // fdo#49876: 0pt is invalid
      52       24120 :             rValue <<= (float)fSize;
      53       24120 :             return true;
      54             :         }
      55             :     }
      56             : 
      57          92 :     return false;
      58             : }
      59             : 
      60       11720 : bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
      61             : {
      62       11720 :     OUStringBuffer aOut;
      63             : 
      64       11720 :     float fSize = 0;
      65       11720 :     if( rValue >>= fSize )
      66             :     {
      67       11720 :         fSize = ::std::max<float>(fSize, 1.0f); // fdo#49876: 0pt is invalid
      68             :         ::sax::Converter::convertDouble(aOut, (double)fSize, true,
      69       11720 :                 util::MeasureUnit::POINT, util::MeasureUnit::POINT);
      70       11720 :         aOut.append( 'p');
      71       11720 :         aOut.append( 't');
      72             :     }
      73             : 
      74       11720 :     rStrExpValue = aOut.makeStringAndClear();
      75       11720 :     return !rStrExpValue.isEmpty();
      76             : }
      77             : 
      78             : 
      79             : // class XMLEscapementHeightPropHdl
      80             : 
      81             : 
      82       31872 : XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
      83             : {
      84             :     // nothing to do
      85       31872 : }
      86             : 
      87       24212 : bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
      88             : {
      89       24212 :     if( rStrImpValue.indexOf( '%' ) != -1 )
      90             :     {
      91          92 :         sal_Int32 nPrc = 100;
      92          92 :         if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
      93             :         {
      94          92 :             rValue <<= (sal_Int16)nPrc;
      95          92 :             return true;
      96             :         }
      97             :     }
      98             : 
      99       24120 :     return false;
     100             : }
     101             : 
     102          18 : bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     103             : {
     104          18 :     OUStringBuffer aOut( rStrExpValue );
     105             : 
     106          18 :     sal_Int16 nValue = sal_Int16();
     107          18 :     if( rValue >>= nValue )
     108             :     {
     109          18 :         ::sax::Converter::convertPercent( aOut, nValue );
     110             :     }
     111             : 
     112          18 :     rStrExpValue = aOut.makeStringAndClear();
     113          18 :     return !rStrExpValue.isEmpty();
     114             : }
     115             : 
     116             : 
     117             : // class XMLEscapementPropHdl
     118             : 
     119             : 
     120       31872 : XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
     121             : {
     122             :     // nothing to do
     123       31872 : }
     124             : 
     125           0 : bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
     126             : {
     127           0 :     sal_Int32 nRel = 0;
     128             : 
     129           0 :     if (::sax::Converter::convertMeasure( nRel, rStrImpValue,
     130             :                 util::MeasureUnit::POINT ))
     131             :     {
     132           0 :         rValue <<= (float)nRel;
     133           0 :         return true;
     134             :     }
     135             : 
     136           0 :     return false;
     137             : }
     138             : 
     139           0 : bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     140             : {
     141           0 :     OUStringBuffer aOut;
     142             : 
     143           0 :     float nRel = 0;
     144           0 :     if( (rValue >>= nRel) && (nRel != 0) )
     145             :     {
     146             :         ::sax::Converter::convertMeasure( aOut, static_cast<sal_Int32>(nRel),
     147           0 :                 util::MeasureUnit::POINT, util::MeasureUnit::POINT );
     148           0 :         rStrExpValue = aOut.makeStringAndClear();
     149             :     }
     150             : 
     151           0 :     return !rStrExpValue.isEmpty();
     152             : }
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10