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

Generated by: LCOV version 1.10