LCOV - code coverage report
Current view: top level - xmloff/source/draw - propimp0.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 33 98 33.7 %
Date: 2014-04-11 Functions: 9 18 50.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 <rtl/ustrbuf.hxx>
      21             : #include "propimp0.hxx"
      22             : #include <com/sun/star/drawing/LineDash.hpp>
      23             : #include <com/sun/star/util/Duration.hpp>
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : 
      26             : #include <sax/tools/converter.hxx>
      27             : 
      28             : #include <xmloff/xmluconv.hxx>
      29             : #include <xmloff/xmlimp.hxx>
      30             : 
      31             : #include <tools/time.hxx>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35             : // implementation of graphic property Stroke
      36             : 
      37             : // implementation of presentation page property Change
      38             : 
      39             : // implementation of an effect duration property handler
      40             : 
      41        1446 : XMLDurationPropertyHdl::~XMLDurationPropertyHdl()
      42             : {
      43        1446 : }
      44             : 
      45           0 : bool XMLDurationPropertyHdl::importXML(
      46             :     const OUString& rStrImpValue,
      47             :     ::com::sun::star::uno::Any& rValue,
      48             :     const SvXMLUnitConverter& ) const
      49             : {
      50           0 :     util::Duration aDuration;
      51           0 :     ::sax::Converter::convertDuration(aDuration,  rStrImpValue);
      52             : 
      53           0 :     const double fSeconds = ((aDuration.Days * 24 + aDuration.Hours) * 60
      54           0 :                              + aDuration.Minutes) * 60 + aDuration.Seconds + aDuration.NanoSeconds / static_cast<double>(::Time::nanoSecPerSec);
      55           0 :     rValue <<= fSeconds;
      56             : 
      57           0 :     return true;
      58             : }
      59             : 
      60           0 : bool XMLDurationPropertyHdl::exportXML(
      61             :     OUString& rStrExpValue,
      62             :     const ::com::sun::star::uno::Any& rValue,
      63             :     const SvXMLUnitConverter& ) const
      64             : {
      65           0 :     double nVal = 0;
      66             : 
      67           0 :     if(rValue >>= nVal)
      68             :     {
      69           0 :         util::Duration aDuration;
      70           0 :         aDuration.Seconds = static_cast<sal_uInt16>(nVal);
      71           0 :         aDuration.NanoSeconds = static_cast<sal_uInt32>((nVal - aDuration.Seconds) * ::Time::nanoSecPerSec);
      72             : 
      73           0 :         OUStringBuffer aOut;
      74           0 :         ::sax::Converter::convertDuration(aOut, aDuration);
      75           0 :         rStrExpValue = aOut.makeStringAndClear();
      76           0 :         return true;
      77             :     }
      78             : 
      79           0 :     return false;
      80             : }
      81             : 
      82             : // implementation of an opacity property handler
      83             : 
      84        2070 : XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport* pImport )
      85        2070 : : mpImport( pImport )
      86             : {
      87        2070 : }
      88             : 
      89        4126 : XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
      90             : {
      91        4126 : }
      92             : 
      93           6 : bool XMLOpacityPropertyHdl::importXML(
      94             :     const OUString& rStrImpValue,
      95             :     ::com::sun::star::uno::Any& rValue,
      96             :     const SvXMLUnitConverter& ) const
      97             : {
      98           6 :     bool bRet = false;
      99           6 :     sal_Int32 nValue = 0;
     100             : 
     101           6 :     if( rStrImpValue.indexOf( '%' ) != -1 )
     102             :     {
     103           6 :         if (::sax::Converter::convertPercent( nValue, rStrImpValue ))
     104           6 :             bRet = true;
     105             :     }
     106             :     else
     107             :     {
     108           0 :         nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 );
     109           0 :         bRet = true;
     110             :     }
     111             : 
     112           6 :     if( bRet )
     113             :     {
     114             :         // check ranges
     115           6 :         if( nValue < 0 )
     116           0 :             nValue = 0;
     117           6 :         if( nValue > 100 )
     118           0 :             nValue = 100;
     119             : 
     120             :         // convert xml opacity to api transparency
     121           6 :         nValue = 100 - nValue;
     122             : 
     123             :         // #i42959#
     124           6 :         if( mpImport )
     125             :         {
     126             :             sal_Int32 nUPD, nBuild;
     127           6 :             if( mpImport->getBuildIds( nUPD, nBuild ) )
     128             :             {
     129             :                 // correct import of documents written prior to StarOffice 8/OOO 2.0 final
     130           0 :                 if( (nUPD == 680) && (nBuild < 8951) )
     131           0 :                     nValue = 100 - nValue;
     132             :             }
     133             :         }
     134             : 
     135           6 :         rValue <<= sal_uInt16(nValue);
     136             :     }
     137             : 
     138           6 :     return bRet;
     139             : }
     140             : 
     141           1 : bool XMLOpacityPropertyHdl::exportXML(
     142             :     OUString& rStrExpValue,
     143             :     const ::com::sun::star::uno::Any& rValue,
     144             :     const SvXMLUnitConverter& ) const
     145             : {
     146           1 :     bool bRet = false;
     147           1 :     sal_uInt16 nVal = sal_uInt16();
     148             : 
     149           1 :     if( rValue >>= nVal )
     150             :     {
     151           1 :         OUStringBuffer aOut;
     152             : 
     153           1 :         nVal = 100 - nVal;
     154           1 :         ::sax::Converter::convertPercent( aOut, nVal );
     155           1 :         rStrExpValue = aOut.makeStringAndClear();
     156           1 :         bRet = true;
     157             :     }
     158             : 
     159           1 :     return bRet;
     160             : }
     161             : 
     162             : // implementation of an text animation step amount
     163             : 
     164        4126 : XMLTextAnimationStepPropertyHdl::~XMLTextAnimationStepPropertyHdl()
     165             : {
     166        4126 : }
     167             : 
     168           0 : bool XMLTextAnimationStepPropertyHdl::importXML(
     169             :     const OUString& rStrImpValue,
     170             :     ::com::sun::star::uno::Any& rValue,
     171             :     const SvXMLUnitConverter& rUnitConverter ) const
     172             : {
     173           0 :     bool bRet = false;
     174           0 :     sal_Int32 nValue = 0;
     175             : 
     176           0 :     const OUString aPX( "px" );
     177           0 :     sal_Int32 nPos = rStrImpValue.indexOf( aPX );
     178           0 :     if( nPos != -1 )
     179             :     {
     180           0 :         if (::sax::Converter::convertNumber(nValue, rStrImpValue.copy(0, nPos)))
     181             :         {
     182           0 :             rValue <<= sal_Int16( -nValue );
     183           0 :             bRet = true;
     184             :         }
     185             :     }
     186             :     else
     187             :     {
     188           0 :         if (rUnitConverter.convertMeasureToCore( nValue, rStrImpValue ))
     189             :         {
     190           0 :             rValue <<= sal_Int16( nValue );
     191           0 :             bRet = true;
     192             :         }
     193             :     }
     194             : 
     195           0 :     return bRet;
     196             : }
     197             : 
     198           0 : bool XMLTextAnimationStepPropertyHdl::exportXML(
     199             :     OUString& rStrExpValue,
     200             :     const ::com::sun::star::uno::Any& rValue,
     201             :     const SvXMLUnitConverter& rUnitConverter ) const
     202             : {
     203           0 :     bool bRet = false;
     204           0 :     sal_Int16 nVal = sal_Int16();
     205             : 
     206           0 :     if( rValue >>= nVal )
     207             :     {
     208           0 :         OUStringBuffer aOut;
     209             : 
     210           0 :         if( nVal < 0 )
     211             :         {
     212           0 :             const OUString aPX( "px" );
     213           0 :             ::sax::Converter::convertNumber( aOut, (sal_Int32)-nVal );
     214           0 :             aOut.append( aPX );
     215             :         }
     216             :         else
     217             :         {
     218           0 :             rUnitConverter.convertMeasureToXML( aOut, nVal );
     219             :         }
     220             : 
     221           0 :         rStrExpValue = aOut.makeStringAndClear();
     222           0 :         bRet = true;
     223             :     }
     224             : 
     225           0 :     return bRet;
     226             : }
     227             : 
     228             : #include "sdxmlexp_impl.hxx"
     229             : 
     230           0 : XMLDateTimeFormatHdl::XMLDateTimeFormatHdl( SvXMLExport* pExport )
     231           0 : : mpExport( pExport )
     232             : {
     233           0 : }
     234             : 
     235           0 : XMLDateTimeFormatHdl::~XMLDateTimeFormatHdl()
     236             : {
     237           0 : }
     238             : 
     239           0 : bool XMLDateTimeFormatHdl::importXML( const OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
     240             : {
     241           0 :     rValue <<= rStrImpValue;
     242           0 :     return true;
     243             : }
     244             : 
     245           0 : bool XMLDateTimeFormatHdl::exportXML( OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
     246             : {
     247           0 :     sal_Int32 nNumberFormat = 0;
     248           0 :     if( mpExport && (rValue >>= nNumberFormat) )
     249             :     {
     250           0 :         mpExport->addDataStyle( nNumberFormat );
     251           0 :         rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
     252           0 :         return true;
     253             :     }
     254             : 
     255           0 :     return false;
     256             : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10