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

Generated by: LCOV version 1.10