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

Generated by: LCOV version 1.10