LCOV - code coverage report
Current view: top level - xmloff/source/style - chrhghdl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 39 52 75.0 %
Date: 2015-06-13 12:38:46 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       21180 : XMLCharHeightHdl::~XMLCharHeightHdl()
      37             : {
      38             :     // nothing to do
      39       21180 : }
      40             : 
      41       18584 : bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
      42             : {
      43       18584 :     if( rStrImpValue.indexOf( '%' ) == -1 )
      44             :     {
      45             :         double fSize;
      46             :         sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
      47       18222 :                 rStrImpValue, util::MeasureUnit::POINT );
      48       18222 :         if (::sax::Converter::convertDouble(fSize, rStrImpValue,
      49       18222 :                     eSrcUnit, util::MeasureUnit::POINT))
      50             :         {
      51       18222 :             fSize = ::std::max<double>(fSize, 1.0); // fdo#49876: 0pt is invalid
      52       18222 :             rValue <<= (float)fSize;
      53       18222 :             return true;
      54             :         }
      55             :     }
      56             : 
      57         362 :     return false;
      58             : }
      59             : 
      60        7538 : bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
      61             : {
      62        7538 :     OUStringBuffer aOut;
      63             : 
      64        7538 :     float fSize = 0;
      65        7538 :     if( rValue >>= fSize )
      66             :     {
      67        7538 :         fSize = ::std::max<float>(fSize, 1.0f); // fdo#49876: 0pt is invalid
      68             :         ::sax::Converter::convertDouble(aOut, (double)fSize, true,
      69        7538 :                 util::MeasureUnit::POINT, util::MeasureUnit::POINT);
      70        7538 :         aOut.append( 'p');
      71        7538 :         aOut.append( 't');
      72             :     }
      73             : 
      74        7538 :     rStrExpValue = aOut.makeStringAndClear();
      75        7538 :     return !rStrExpValue.isEmpty();
      76             : }
      77             : 
      78             : 
      79             : // class XMLEscapementHeightPropHdl
      80             : 
      81             : 
      82       20932 : XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
      83             : {
      84             :     // nothing to do
      85       20932 : }
      86             : 
      87       18584 : bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
      88             : {
      89       18584 :     if( rStrImpValue.indexOf( '%' ) != -1 )
      90             :     {
      91         362 :         sal_Int32 nPrc = 100;
      92         362 :         if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
      93             :         {
      94         362 :             rValue <<= (sal_Int16)nPrc;
      95         362 :             return true;
      96             :         }
      97             :     }
      98             : 
      99       18222 :     return false;
     100             : }
     101             : 
     102          83 : bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     103             : {
     104          83 :     OUStringBuffer aOut( rStrExpValue );
     105             : 
     106          83 :     sal_Int16 nValue = sal_Int16();
     107          83 :     if( rValue >>= nValue )
     108             :     {
     109          83 :         ::sax::Converter::convertPercent( aOut, nValue );
     110             :     }
     111             : 
     112          83 :     rStrExpValue = aOut.makeStringAndClear();
     113          83 :     return !rStrExpValue.isEmpty();
     114             : }
     115             : 
     116             : 
     117             : // class XMLEscapementPropHdl
     118             : 
     119             : 
     120       20932 : XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
     121             : {
     122             :     // nothing to do
     123       20932 : }
     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.11