LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/style - lspachdl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 72 50.0 %
Date: 2012-12-27 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 <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 ::rtl::OUString;
      30             : using ::rtl::OUStringBuffer;
      31             : 
      32             : using namespace ::com::sun::star;
      33             : using ::xmloff::token::IsXMLToken;
      34             : using ::xmloff::token::XML_CASEMAP_NORMAL;
      35             : 
      36             : // this is a copy of defines in svx/inc/escpitem.hxx
      37             : #define DFLT_ESC_PROP    58
      38             : #define DFLT_ESC_AUTO_SUPER 101
      39             : #define DFLT_ESC_AUTO_SUB  -101
      40             : 
      41             : ///////////////////////////////////////////////////////////////////////////////
      42             : //
      43             : // class XMLEscapementPropHdl
      44             : //
      45             : 
      46         704 : XMLLineHeightHdl::~XMLLineHeightHdl()
      47             : {
      48             :     // nothing to do
      49         704 : }
      50             : 
      51          21 : sal_Bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
      52             : {
      53          21 :     style::LineSpacing aLSp;
      54          21 :     sal_Int32 nTemp = 0;
      55             : 
      56          21 :     if( -1 != rStrImpValue.indexOf( sal_Unicode( '%' ) ) )
      57             :     {
      58          21 :         aLSp.Mode = style::LineSpacingMode::PROP;
      59          21 :         if (!::sax::Converter::convertPercent( nTemp, rStrImpValue ))
      60           0 :             return sal_False;
      61          21 :         aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
      62             :     }
      63           0 :     else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL) )
      64             :     {
      65           0 :         aLSp.Mode = style::LineSpacingMode::PROP;
      66           0 :         aLSp.Height = 100;
      67             :     }
      68             :     else
      69             :     {
      70           0 :         aLSp.Mode = style::LineSpacingMode::FIX;
      71           0 :         if (!rUnitConverter.convertMeasureToCore(
      72           0 :                     nTemp, rStrImpValue, 0x0000, 0xffff))
      73           0 :             return sal_False;
      74           0 :         aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
      75             :     }
      76             : 
      77          21 :     rValue <<= aLSp;
      78          21 :     return sal_True;
      79             : }
      80             : 
      81           4 : sal_Bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
      82             : {
      83           4 :     OUStringBuffer aOut;
      84             : 
      85           4 :     style::LineSpacing aLSp;
      86           4 :     if(!(rValue >>= aLSp))
      87           0 :         return sal_False;
      88             : 
      89           4 :     if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX  != aLSp.Mode )
      90           0 :         return sal_False;
      91             : 
      92           4 :     if( style::LineSpacingMode::PROP == aLSp.Mode )
      93             :     {
      94           4 :         ::sax::Converter::convertPercent( aOut, aLSp.Height );
      95             :     }
      96             :     else
      97             :     {
      98           0 :         rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
      99             :     }
     100             : 
     101           4 :     rStrExpValue = aOut.makeStringAndClear();
     102           4 :     return !rStrExpValue.isEmpty();
     103             : }
     104             : 
     105             : ///////////////////////////////////////////////////////////////////////////////
     106             : //
     107             : // class XMLLineHeightAtLeastHdl
     108             : //
     109             : 
     110         704 : XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
     111             : {
     112             :     // nothing to do
     113         704 : }
     114             : 
     115           0 : sal_Bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     116             : {
     117           0 :     style::LineSpacing aLSp;
     118             : 
     119             :     sal_Int32 nTemp;
     120           0 :     aLSp.Mode = style::LineSpacingMode::MINIMUM;
     121           0 :     if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
     122           0 :         return sal_False;
     123           0 :     aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
     124             : 
     125           0 :     rValue <<= aLSp;
     126           0 :     return sal_True;
     127             : }
     128             : 
     129           4 : sal_Bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     130             : {
     131           4 :     OUStringBuffer aOut;
     132             : 
     133           4 :     style::LineSpacing aLSp;
     134           4 :     if(!(rValue >>= aLSp))
     135           0 :         return sal_False;
     136             : 
     137           4 :     if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
     138           4 :         return sal_False;
     139             : 
     140           0 :     rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
     141             : 
     142           0 :     rStrExpValue = aOut.makeStringAndClear();
     143           0 :     return !rStrExpValue.isEmpty();
     144             : }
     145             : 
     146             : ///////////////////////////////////////////////////////////////////////////////
     147             : //
     148             : // class XMLLineSpacingHdl
     149             : //
     150             : 
     151         704 : XMLLineSpacingHdl::~XMLLineSpacingHdl()
     152             : {
     153             :     // nothing to do
     154         704 : }
     155             : 
     156           0 : sal_Bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     157             : {
     158           0 :     style::LineSpacing aLSp;
     159             :     sal_Int32 nTemp;
     160             : 
     161           0 :     aLSp.Mode = style::LineSpacingMode::LEADING;
     162           0 :     if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
     163           0 :         return sal_False;
     164           0 :     aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
     165             : 
     166           0 :     rValue <<= aLSp;
     167           0 :     return sal_True;
     168             : }
     169             : 
     170           4 : sal_Bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     171             : {
     172           4 :     OUStringBuffer aOut;
     173             : 
     174           4 :     style::LineSpacing aLSp;
     175           4 :     if(!(rValue >>= aLSp))
     176           0 :         return sal_False;
     177             : 
     178           4 :     if( style::LineSpacingMode::LEADING != aLSp.Mode )
     179           4 :         return sal_False;
     180             : 
     181           0 :     rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
     182             : 
     183           0 :     rStrExpValue = aOut.makeStringAndClear();
     184           0 :     return !rStrExpValue.isEmpty();
     185             : }
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10