LCOV - code coverage report
Current view: top level - xmloff/source/style - XMLClipPropertyHandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 65 67 97.0 %
Date: 2015-06-13 12:38:46 Functions: 6 6 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 "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       16202 : XMLClipPropertyHandler::XMLClipPropertyHandler( bool bODF11 ) :
      37       16202 :     m_bODF11( bODF11 )
      38             : {
      39       16202 : }
      40             : 
      41       32384 : XMLClipPropertyHandler::~XMLClipPropertyHandler()
      42             : {
      43             :     // nothing to do
      44       32384 : }
      45             : 
      46           9 : bool XMLClipPropertyHandler::equals(
      47             :         const Any& r1,
      48             :         const Any& r2 ) const
      49             : {
      50           9 :     GraphicCrop aCrop1, aCrop2;
      51           9 :     r1 >>= aCrop1;
      52           9 :     r2 >>= aCrop2;
      53             : 
      54          18 :     return aCrop1.Top == aCrop2.Top &&
      55          18 :            aCrop1.Bottom == aCrop2.Bottom &&
      56          27 :            aCrop1.Left == aCrop2.Left &&
      57          18 :            aCrop1.Right == aCrop2.Right;
      58             : }
      59             : 
      60         112 : bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
      61             : {
      62         112 :     bool bRet = false;
      63         112 :     sal_Int32 nLen = rStrImpValue.getLength();
      64         224 :     if( nLen > 6 &&
      65         224 :         rStrImpValue.startsWith( GetXMLToken(XML_RECT)) &&
      66         336 :         rStrImpValue[4] == '(' &&
      67         112 :         rStrImpValue[nLen-1] == ')' )
      68             :     {
      69         112 :         GraphicCrop aCrop;
      70         112 :         OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) );
      71             : 
      72         112 :         bool bHasComma = sTmp.indexOf( ',' ) != -1;
      73         112 :         SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' );
      74             : 
      75         112 :         sal_uInt16 nPos = 0;
      76         224 :         OUString aToken;
      77         672 :         while( aTokenEnum.getNextToken( aToken ) )
      78             :         {
      79         448 :             sal_Int32 nVal = 0;
      80         896 :             if( !IsXMLToken(aToken, XML_AUTO) &&
      81         448 :                 !rUnitConverter.convertMeasureToCore( nVal, aToken ) )
      82           0 :                 break;
      83             : 
      84             :             // fdo#80009 such nonsense could be written via WW8 import fdo#77454
      85         448 :             if (abs(nVal) > 400000)
      86             :             {
      87             :                 SAL_INFO("xmloff.style", "ignoring excessive clip " << aToken);
      88           0 :                 nVal = 0;
      89             :             }
      90             : 
      91         448 :             switch( nPos )
      92             :             {
      93         112 :             case 0: aCrop.Top = nVal;   break;
      94         112 :             case 1: aCrop.Right = nVal; break;
      95         112 :             case 2: aCrop.Bottom = nVal;    break;
      96         112 :             case 3: aCrop.Left = nVal;  break;
      97             :             }
      98         448 :             nPos++;
      99             :         }
     100             : 
     101         112 :         bRet = (4 == nPos );
     102         112 :         if( bRet )
     103         224 :             rValue <<= aCrop;
     104             :     }
     105             : 
     106         112 :     return bRet;
     107             : }
     108             : 
     109          16 : bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     110             : {
     111          16 :     bool bRet = false;
     112          16 :       OUStringBuffer aOut(30);
     113          16 :     GraphicCrop aCrop;
     114             : 
     115          16 :     if( rValue >>= aCrop )
     116             :     {
     117          16 :         aOut.append( GetXMLToken(XML_RECT) );
     118          16 :         aOut.append( '(' );
     119          16 :         rUnitConverter.convertMeasureToXML( aOut, aCrop.Top );
     120          16 :         if( !m_bODF11 )
     121          16 :             aOut.append( ',' );
     122          16 :         aOut.append( ' ' );
     123          16 :         rUnitConverter.convertMeasureToXML( aOut, aCrop.Right );
     124          16 :         if( !m_bODF11 )
     125          16 :             aOut.append( ',' );
     126          16 :         aOut.append( ' ' );
     127          16 :         rUnitConverter.convertMeasureToXML( aOut, aCrop.Bottom );
     128          16 :         if( !m_bODF11 )
     129          16 :             aOut.append( ',' );
     130          16 :         aOut.append( ' ' );
     131          16 :         rUnitConverter.convertMeasureToXML( aOut, aCrop.Left );
     132          16 :         aOut.append( ')' );
     133          16 :         rStrExpValue = aOut.makeStringAndClear();
     134             : 
     135          16 :         bRet = true;
     136             :     }
     137             : 
     138          16 :     return bRet;
     139             : }
     140             : 
     141             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11