LCOV - code coverage report
Current view: top level - xmloff/source/style - XMLClipPropertyHandler.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 65 0.0 %
Date: 2014-04-14 Functions: 0 6 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 "XMLClipPropertyHandler.hxx"
      21             : #include <com/sun/star/uno/Any.hxx>
      22             : #include <rtl/ustrbuf.hxx>
      23             : #include <com/sun/star/text/GraphicCrop.hpp>
      24             : #include <xmloff/xmluconv.hxx>
      25             : #include <xmloff/xmltoken.hxx>
      26             : 
      27             : using namespace ::com::sun::star;
      28             : using namespace ::com::sun::star::uno;
      29             : using namespace ::com::sun::star::text;
      30             : using namespace ::xmloff::token;
      31             : 
      32             : 
      33             : // class XMLMeasurePropHdl
      34             : 
      35             : 
      36           0 : XMLClipPropertyHandler::XMLClipPropertyHandler( bool bODF11 ) :
      37           0 :     m_bODF11( bODF11 )
      38             : {
      39           0 : }
      40             : 
      41           0 : XMLClipPropertyHandler::~XMLClipPropertyHandler()
      42             : {
      43             :     // nothing to do
      44           0 : }
      45             : 
      46           0 : bool XMLClipPropertyHandler::equals(
      47             :         const Any& r1,
      48             :         const Any& r2 ) const
      49             : {
      50           0 :     GraphicCrop aCrop1, aCrop2;
      51           0 :     r1 >>= aCrop1;
      52           0 :     r2 >>= aCrop2;
      53             : 
      54           0 :     return aCrop1.Top == aCrop2.Top &&
      55           0 :            aCrop1.Bottom == aCrop2.Bottom &&
      56           0 :            aCrop1.Left == aCrop2.Left &&
      57           0 :            aCrop1.Right == aCrop2.Right;
      58             : }
      59             : 
      60           0 : bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
      61             : {
      62           0 :     bool bRet = false;
      63           0 :     sal_Int32 nLen = rStrImpValue.getLength();
      64           0 :     if( nLen > 6 &&
      65           0 :         rStrImpValue.startsWith( GetXMLToken(XML_RECT)) &&
      66           0 :         rStrImpValue[4] == '(' &&
      67           0 :         rStrImpValue[nLen-1] == ')' )
      68             :     {
      69           0 :         GraphicCrop aCrop;
      70           0 :         OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) );
      71             : 
      72           0 :         bool bHasComma = sTmp.indexOf( ',' ) != -1;
      73           0 :         SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' );
      74             : 
      75           0 :         sal_uInt16 nPos = 0;
      76           0 :         OUString aToken;
      77           0 :         while( aTokenEnum.getNextToken( aToken ) )
      78             :         {
      79           0 :             sal_Int32 nVal = 0;
      80           0 :             if( !IsXMLToken(aToken, XML_AUTO) &&
      81           0 :                 !rUnitConverter.convertMeasureToCore( nVal, aToken ) )
      82           0 :                 break;
      83             : 
      84           0 :             switch( nPos )
      85             :             {
      86           0 :             case 0: aCrop.Top = nVal;   break;
      87           0 :             case 1: aCrop.Right = nVal; break;
      88           0 :             case 2: aCrop.Bottom = nVal;    break;
      89           0 :             case 3: aCrop.Left = nVal;  break;
      90             :             }
      91           0 :             nPos++;
      92             :         }
      93             : 
      94           0 :         bRet = (4 == nPos );
      95           0 :         if( bRet )
      96           0 :             rValue <<= aCrop;
      97             :     }
      98             : 
      99           0 :     return bRet;
     100             : }
     101             : 
     102           0 : bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     103             : {
     104           0 :     bool bRet = false;
     105           0 :       OUStringBuffer aOut(30);
     106           0 :     GraphicCrop aCrop;
     107             : 
     108           0 :     if( rValue >>= aCrop )
     109             :     {
     110           0 :         aOut.append( GetXMLToken(XML_RECT) );
     111           0 :         aOut.append( '(' );
     112           0 :         rUnitConverter.convertMeasureToXML( aOut, aCrop.Top );
     113           0 :         if( !m_bODF11 )
     114           0 :             aOut.append( ',' );
     115           0 :         aOut.append( ' ' );
     116           0 :         rUnitConverter.convertMeasureToXML( aOut, aCrop.Right );
     117           0 :         if( !m_bODF11 )
     118           0 :             aOut.append( ',' );
     119           0 :         aOut.append( ' ' );
     120           0 :         rUnitConverter.convertMeasureToXML( aOut, aCrop.Bottom );
     121           0 :         if( !m_bODF11 )
     122           0 :             aOut.append( ',' );
     123           0 :         aOut.append( ' ' );
     124           0 :         rUnitConverter.convertMeasureToXML( aOut, aCrop.Left );
     125           0 :         aOut.append( ')' );
     126           0 :         rStrExpValue = aOut.makeStringAndClear();
     127             : 
     128           0 :         bRet = true;
     129             :     }
     130             : 
     131           0 :     return bRet;
     132             : }
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10