LCOV - code coverage report
Current view: top level - sc/source/filter/oox - biffhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 46 2.2 %
Date: 2012-08-25 Functions: 2 9 22.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 56 3.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "biffhelper.hxx"
      30                 :            : 
      31                 :            : #include <rtl/math.hxx>
      32                 :            : #include <rtl/tencinfo.h>
      33                 :            : #include "biffinputstream.hxx"
      34                 :            : #include "worksheethelper.hxx"
      35                 :            : #include "oox/helper/binaryoutputstream.hxx"
      36                 :            : 
      37                 :            : namespace oox {
      38                 :            : namespace xls {
      39                 :            : 
      40                 :            : // ============================================================================
      41                 :            : 
      42                 :            : using ::rtl::OUString;
      43                 :            : using ::rtl::OUStringBuffer;
      44                 :            : 
      45                 :            : // ============================================================================
      46                 :            : 
      47                 :            : namespace {
      48                 :            : 
      49                 :            : const sal_Int32 BIFF_RK_100FLAG             = 0x00000001;
      50                 :            : const sal_Int32 BIFF_RK_INTFLAG             = 0x00000002;
      51                 :            : const sal_Int32 BIFF_RK_VALUEMASK           = 0xFFFFFFFC;
      52                 :            : 
      53                 :            : const sal_Int32 BITMAPFILEHEADER_SIZE       = 14;
      54                 :            : const sal_Int32 BITMAPCOREHEADER_SIZE       = 12;
      55                 :            : const sal_Int32 BITMAPINFOHEADER_SIZE       = 40;
      56                 :            : 
      57                 :            : const sal_uInt16 BIFF_IMGDATA_WMF           = 2;
      58                 :            : const sal_uInt16 BIFF_IMGDATA_DIB           = 9;
      59                 :            : const sal_uInt16 BIFF_IMGDATA_NATIVE        = 14;
      60                 :            : 
      61                 :            : // ----------------------------------------------------------------------------
      62                 :            : 
      63                 :            : union DecodedDouble
      64                 :            : {
      65                 :            :     double              mfValue;
      66                 :            :     sal_math_Double     maStruct;
      67                 :            : 
      68                 :          0 :     inline explicit     DecodedDouble() {}
      69                 :          0 :     inline explicit     DecodedDouble( double fValue ) : mfValue( fValue ) {}
      70                 :            : };
      71                 :            : 
      72                 :            : } // namespace
      73                 :            : 
      74                 :            : // ============================================================================
      75                 :            : 
      76                 :            : // conversion -----------------------------------------------------------------
      77                 :            : 
      78                 :          0 : /*static*/ double BiffHelper::calcDoubleFromRk( sal_Int32 nRkValue )
      79                 :            : {
      80                 :          0 :     DecodedDouble aDecDbl( 0.0 );
      81         [ #  # ]:          0 :     if( getFlag( nRkValue, BIFF_RK_INTFLAG ) )
      82                 :            :     {
      83                 :          0 :         sal_Int32 nTemp = nRkValue >> 2;
      84                 :          0 :         setFlag< sal_Int32 >( nTemp, 0xE0000000, nRkValue < 0 );
      85                 :          0 :         aDecDbl.mfValue = nTemp;
      86                 :            :     }
      87                 :            :     else
      88                 :            :     {
      89                 :          0 :         aDecDbl.maStruct.w32_parts.msw = static_cast< sal_uInt32 >( nRkValue & BIFF_RK_VALUEMASK );
      90                 :            :     }
      91                 :            : 
      92         [ #  # ]:          0 :     if( getFlag( nRkValue, BIFF_RK_100FLAG ) )
      93                 :          0 :         aDecDbl.mfValue /= 100.0;
      94                 :            : 
      95                 :          0 :     return aDecDbl.mfValue;
      96                 :            : }
      97                 :            : 
      98                 :          0 : /*static*/ double BiffHelper::calcDoubleFromError( sal_uInt8 nErrorCode )
      99                 :            : {
     100                 :          0 :     sal_uInt16 nApiError = 0x7FFF;
     101   [ #  #  #  #  :          0 :     switch( nErrorCode )
             #  #  #  # ]
     102                 :            :     {
     103                 :          0 :         case BIFF_ERR_NULL:     nApiError = 521;    break;
     104                 :          0 :         case BIFF_ERR_DIV0:     nApiError = 532;    break;
     105                 :          0 :         case BIFF_ERR_VALUE:    nApiError = 519;    break;
     106                 :          0 :         case BIFF_ERR_REF:      nApiError = 524;    break;
     107                 :          0 :         case BIFF_ERR_NAME:     nApiError = 525;    break;
     108                 :          0 :         case BIFF_ERR_NUM:      nApiError = 503;    break;
     109                 :          0 :         case BIFF_ERR_NA:       nApiError = 0x7FFF; break;
     110                 :            :         default:    OSL_FAIL( "BiffHelper::calcDoubleFromError - unknown error code" );
     111                 :            :     }
     112                 :          0 :     DecodedDouble aDecDbl;
     113                 :          0 :     ::rtl::math::setNan( &aDecDbl.mfValue );
     114                 :          0 :     aDecDbl.maStruct.nan_parts.fraction_lo = nApiError;
     115                 :          0 :     return aDecDbl.mfValue;
     116                 :            : }
     117                 :            : 
     118                 :            : // BIFF12 import --------------------------------------------------------------
     119                 :            : 
     120                 :          0 : /*static*/ OUString BiffHelper::readString( SequenceInputStream& rStrm, bool b32BitLen, bool bAllowNulChars )
     121                 :            : {
     122                 :          0 :     OUString aString;
     123         [ #  # ]:          0 :     if( !rStrm.isEof() )
     124                 :            :     {
     125 [ #  # ][ #  # ]:          0 :         sal_Int32 nCharCount = b32BitLen ? rStrm.readValue< sal_Int32 >() : rStrm.readValue< sal_Int16 >();
                 [ #  # ]
     126                 :            :         // string length -1 is often used to indicate a missing string
     127                 :            :         OSL_ENSURE( !rStrm.isEof() && (nCharCount >= -1), "BiffHelper::readString - invalid string length" );
     128 [ #  # ][ #  # ]:          0 :         if( !rStrm.isEof() && (nCharCount > 0) )
                 [ #  # ]
     129                 :            :         {
     130                 :            :             // SequenceInputStream always supports getRemaining()
     131 [ #  # ][ #  # ]:          0 :             nCharCount = ::std::min( nCharCount, static_cast< sal_Int32 >( rStrm.getRemaining() / 2 ) );
     132         [ #  # ]:          0 :             aString = rStrm.readUnicodeArray( nCharCount, bAllowNulChars );
     133                 :            :         }
     134                 :            :     }
     135                 :          0 :     return aString;
     136                 :            : }
     137                 :            : 
     138                 :            : // BIFF2-BIFF8 import ---------------------------------------------------------
     139                 :            : 
     140                 :          0 : /*static*/ bool BiffHelper::isBofRecord( BiffInputStream& rStrm )
     141                 :            : {
     142                 :            :     return
     143                 :          0 :         (rStrm.getRecId() == BIFF2_ID_BOF) ||
     144                 :          0 :         (rStrm.getRecId() == BIFF3_ID_BOF) ||
     145                 :          0 :         (rStrm.getRecId() == BIFF4_ID_BOF) ||
     146 [ #  # ][ #  #  :          0 :         (rStrm.getRecId() == BIFF5_ID_BOF);
             #  #  #  # ]
     147                 :            : }
     148                 :            : 
     149                 :          0 : /*static*/ bool BiffHelper::skipRecordBlock( BiffInputStream& rStrm, sal_uInt16 nEndRecId )
     150                 :            : {
     151                 :          0 :     sal_uInt16 nStartRecId = rStrm.getRecId();
     152 [ #  # ][ #  # ]:          0 :     while( rStrm.startNextRecord() && (rStrm.getRecId() != nEndRecId) )
                 [ #  # ]
     153         [ #  # ]:          0 :         if( rStrm.getRecId() == nStartRecId )
     154                 :          0 :             skipRecordBlock( rStrm, nEndRecId );
     155 [ #  # ][ #  # ]:          0 :     return !rStrm.isEof() && (rStrm.getRecId() == nEndRecId);
     156                 :            : }
     157                 :            : 
     158                 :            : } // namespace xls
     159 [ +  - ][ +  - ]:         24 : } // namespace oox
     160                 :            : 
     161                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10