LCOV - code coverage report
Current view: top level - xmloff/source/style - lspachdl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 53 72 73.6 %
Date: 2014-11-03 Functions: 11 12 91.7 %
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 <lspachdl.hxx>
      21             : #include <xmloff/xmltoken.hxx>
      22             : #include <xmloff/xmluconv.hxx>
      23             : #include <sax/tools/converter.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #include <com/sun/star/style/LineSpacing.hpp>
      27             : #include <com/sun/star/style/LineSpacingMode.hpp>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : using ::xmloff::token::IsXMLToken;
      31             : using ::xmloff::token::XML_CASEMAP_NORMAL;
      32             : 
      33             : 
      34             : // class XMLEscapementPropHdl
      35             : 
      36             : 
      37       23184 : XMLLineHeightHdl::~XMLLineHeightHdl()
      38             : {
      39             :     // nothing to do
      40       23184 : }
      41             : 
      42        1224 : bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
      43             : {
      44        1224 :     style::LineSpacing aLSp;
      45        1224 :     sal_Int32 nTemp = 0;
      46             : 
      47        1224 :     if( -1 != rStrImpValue.indexOf( '%' ) )
      48             :     {
      49        1016 :         aLSp.Mode = style::LineSpacingMode::PROP;
      50        1016 :         if (!::sax::Converter::convertPercent( nTemp, rStrImpValue ))
      51           0 :             return false;
      52        1016 :         aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
      53             :     }
      54         208 :     else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL) )
      55             :     {
      56           0 :         aLSp.Mode = style::LineSpacingMode::PROP;
      57           0 :         aLSp.Height = 100;
      58             :     }
      59             :     else
      60             :     {
      61         208 :         aLSp.Mode = style::LineSpacingMode::FIX;
      62         208 :         if (!rUnitConverter.convertMeasureToCore(
      63         208 :                     nTemp, rStrImpValue, 0x0000, 0xffff))
      64           0 :             return false;
      65         208 :         aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
      66             :     }
      67             : 
      68        1224 :     rValue <<= aLSp;
      69        1224 :     return true;
      70             : }
      71             : 
      72         172 : bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
      73             : {
      74         172 :     OUStringBuffer aOut;
      75             : 
      76         172 :     style::LineSpacing aLSp;
      77         172 :     if(!(rValue >>= aLSp))
      78           0 :         return false;
      79             : 
      80         172 :     if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX  != aLSp.Mode )
      81           6 :         return false;
      82             : 
      83         166 :     if( style::LineSpacingMode::PROP == aLSp.Mode )
      84             :     {
      85         146 :         ::sax::Converter::convertPercent( aOut, aLSp.Height );
      86             :     }
      87             :     else
      88             :     {
      89          20 :         rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
      90             :     }
      91             : 
      92         166 :     rStrExpValue = aOut.makeStringAndClear();
      93         166 :     return !rStrExpValue.isEmpty();
      94             : }
      95             : 
      96             : 
      97             : // class XMLLineHeightAtLeastHdl
      98             : 
      99             : 
     100       23184 : XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
     101             : {
     102             :     // nothing to do
     103       23184 : }
     104             : 
     105         164 : bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     106             : {
     107         164 :     style::LineSpacing aLSp;
     108             : 
     109             :     sal_Int32 nTemp;
     110         164 :     aLSp.Mode = style::LineSpacingMode::MINIMUM;
     111         164 :     if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
     112           0 :         return false;
     113         164 :     aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
     114             : 
     115         164 :     rValue <<= aLSp;
     116         164 :     return true;
     117             : }
     118             : 
     119         172 : bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     120             : {
     121         172 :     OUStringBuffer aOut;
     122             : 
     123         172 :     style::LineSpacing aLSp;
     124         172 :     if(!(rValue >>= aLSp))
     125           0 :         return false;
     126             : 
     127         172 :     if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
     128         166 :         return false;
     129             : 
     130           6 :     rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
     131             : 
     132           6 :     rStrExpValue = aOut.makeStringAndClear();
     133           6 :     return !rStrExpValue.isEmpty();
     134             : }
     135             : 
     136             : 
     137             : // class XMLLineSpacingHdl
     138             : 
     139             : 
     140       23184 : XMLLineSpacingHdl::~XMLLineSpacingHdl()
     141             : {
     142             :     // nothing to do
     143       23184 : }
     144             : 
     145           0 : bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     146             : {
     147           0 :     style::LineSpacing aLSp;
     148             :     sal_Int32 nTemp;
     149             : 
     150           0 :     aLSp.Mode = style::LineSpacingMode::LEADING;
     151           0 :     if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
     152           0 :         return false;
     153           0 :     aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
     154             : 
     155           0 :     rValue <<= aLSp;
     156           0 :     return true;
     157             : }
     158             : 
     159         172 : bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     160             : {
     161         172 :     OUStringBuffer aOut;
     162             : 
     163         172 :     style::LineSpacing aLSp;
     164         172 :     if(!(rValue >>= aLSp))
     165           0 :         return false;
     166             : 
     167         172 :     if( style::LineSpacingMode::LEADING != aLSp.Mode )
     168         172 :         return false;
     169             : 
     170           0 :     rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
     171             : 
     172           0 :     rStrExpValue = aOut.makeStringAndClear();
     173           0 :     return !rStrExpValue.isEmpty();
     174             : }
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10