LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/style - shadwhdl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 19 72 26.4 %
Date: 2012-12-27 Functions: 3 4 75.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 "shadwhdl.hxx"
      21             : #include <com/sun/star/uno/Any.hxx>
      22             : #include <rtl/ustrbuf.hxx>
      23             : 
      24             : // --
      25             : #include <com/sun/star/table/ShadowFormat.hpp>
      26             : #include <tools/color.hxx>
      27             : #include <sax/tools/converter.hxx>
      28             : #include <xmloff/xmluconv.hxx>
      29             : #include <xmloff/xmltoken.hxx>
      30             : 
      31             : using ::rtl::OUString;
      32             : using ::rtl::OUStringBuffer;
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::xmloff::token;
      36             : 
      37             : ///////////////////////////////////////////////////////////////////////////////
      38             : //
      39             : // class XMLMeasurePropHdl
      40             : //
      41             : 
      42        1320 : XMLShadowPropHdl::~XMLShadowPropHdl()
      43             : {
      44             :     // nothing to do
      45        1320 : }
      46             : 
      47           7 : sal_Bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
      48             : {
      49           7 :     sal_Bool bRet = sal_False;
      50           7 :     table::ShadowFormat aShadow;
      51           7 :     aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
      52             : 
      53           7 :     sal_Bool bColorFound = sal_False;
      54           7 :     sal_Bool bOffsetFound = sal_False;
      55           7 :     SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
      56           7 :     Color aColor( 128,128, 128 );
      57           7 :     OUString aToken;
      58             : 
      59          14 :     while( aTokenEnum.getNextToken( aToken ) )
      60             :     {
      61           7 :         if( IsXMLToken( aToken, XML_NONE ) )
      62             :         {
      63           7 :             aShadow.Location = table::ShadowLocation_NONE;
      64           7 :             bRet = sal_True;
      65           7 :             break;
      66             :         }
      67           0 :         else if( !bColorFound && aToken.compareToAscii( "#", 1 ) == 0 )
      68             :         {
      69           0 :             sal_Int32 nColor(0);
      70           0 :             bRet = ::sax::Converter::convertColor( nColor, aToken );
      71           0 :             if( !bRet )
      72           0 :                 return sal_False;
      73             : 
      74           0 :             aColor.SetColor(nColor);
      75           0 :             bColorFound = sal_True;
      76             :         }
      77           0 :         else if( !bOffsetFound )
      78             :         {
      79           0 :             sal_Int32 nX = 0, nY = 0;
      80             : 
      81           0 :             bRet = rUnitConverter.convertMeasureToCore( nX, aToken );
      82           0 :             if( bRet && aTokenEnum.getNextToken( aToken ) )
      83           0 :                 bRet = rUnitConverter.convertMeasureToCore( nY, aToken );
      84             : 
      85           0 :             if( bRet )
      86             :             {
      87           0 :                 if( nX < 0 )
      88             :                 {
      89           0 :                     if( nY < 0 )
      90           0 :                         aShadow.Location = table::ShadowLocation_TOP_LEFT;
      91             :                     else
      92           0 :                         aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
      93             :                 }
      94             :                 else
      95             :                 {
      96           0 :                     if( nY < 0 )
      97           0 :                         aShadow.Location = table::ShadowLocation_TOP_RIGHT;
      98             :                     else
      99           0 :                         aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
     100             :                 }
     101             : 
     102           0 :                 if( nX < 0 ) nX *= -1;
     103           0 :                 if( nY < 0 ) nY *= -1;
     104             : 
     105             :                 aShadow.ShadowWidth = sal::static_int_cast< sal_Int16 >(
     106           0 :                     (nX + nY) >> 1);
     107             :             }
     108             :         }
     109             :     }
     110             : 
     111           7 :     if( bRet && ( bColorFound || bOffsetFound ) )
     112             :     {
     113           0 :         aShadow.IsTransparent = aColor.GetTransparency() > 0;
     114           0 :         aShadow.Color = aColor.GetColor();
     115           0 :         bRet = sal_True;
     116             :     }
     117             : 
     118           7 :     rValue <<= aShadow;
     119             : 
     120           7 :     return bRet;
     121             : }
     122             : 
     123           0 : sal_Bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     124             : {
     125           0 :     sal_Bool bRet = sal_False;
     126           0 :       OUStringBuffer aOut;
     127           0 :     table::ShadowFormat aShadow;
     128             : 
     129           0 :     if( rValue >>= aShadow )
     130             :     {
     131           0 :         sal_Int32 nX = 1, nY = 1;
     132             : 
     133           0 :         switch( aShadow.Location )
     134             :         {
     135             :             case table::ShadowLocation_TOP_LEFT:
     136           0 :                 nX = -1;
     137           0 :                 nY = -1;
     138           0 :                 break;
     139             :             case table::ShadowLocation_TOP_RIGHT:
     140           0 :                 nY = -1;
     141           0 :                 break;
     142             :             case table::ShadowLocation_BOTTOM_LEFT:
     143           0 :                 nX = -1;
     144           0 :                 break;
     145             :             case table::ShadowLocation_BOTTOM_RIGHT:
     146           0 :                 break;
     147             :             case table::ShadowLocation_NONE:
     148             :             default:
     149           0 :                 rStrExpValue = GetXMLToken(XML_NONE);
     150           0 :                 return sal_True;
     151             :         }
     152             : 
     153           0 :         nX *= aShadow.ShadowWidth;
     154           0 :         nY *= aShadow.ShadowWidth;
     155             : 
     156           0 :         ::sax::Converter::convertColor( aOut, aShadow.Color );
     157             : 
     158           0 :         aOut.append( sal_Unicode(' ') );
     159           0 :         rUnitConverter.convertMeasureToXML( aOut, nX );
     160           0 :         aOut.append( sal_Unicode(' ') );
     161           0 :         rUnitConverter.convertMeasureToXML( aOut, nY );
     162             : 
     163           0 :         rStrExpValue = aOut.makeStringAndClear();
     164             : 
     165           0 :         bRet = sal_True;
     166             :     }
     167             : 
     168           0 :     return bRet;
     169             : }
     170             : 
     171             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10