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

Generated by: LCOV version 1.11