fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / oox / biffhelper.cxx
blobebbf631430048bcb8e4f896d1c6ff61841b6b970
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "biffhelper.hxx"
22 #include <rtl/math.hxx>
23 #include <rtl/tencinfo.h>
24 #include <osl/diagnose.h>
25 #include "biffinputstream.hxx"
26 #include "worksheethelper.hxx"
27 #include <oox/helper/binaryoutputstream.hxx>
29 namespace oox {
30 namespace xls {
32 namespace {
34 const sal_Int32 BIFF_RK_100FLAG = 0x00000001;
35 const sal_Int32 BIFF_RK_INTFLAG = 0x00000002;
36 const sal_Int32 BIFF_RK_VALUEMASK = 0xFFFFFFFC;
38 union DecodedDouble
40 double mfValue;
41 sal_math_Double maStruct;
43 inline explicit DecodedDouble() {}
44 inline explicit DecodedDouble( double fValue ) : mfValue( fValue ) {}
47 } // namespace
49 // conversion -----------------------------------------------------------------
51 /*static*/ double BiffHelper::calcDoubleFromRk( sal_Int32 nRkValue )
53 DecodedDouble aDecDbl( 0.0 );
54 if( getFlag( nRkValue, BIFF_RK_INTFLAG ) )
56 sal_Int32 nTemp = nRkValue >> 2;
57 setFlag< sal_Int32 >( nTemp, 0xE0000000, nRkValue < 0 );
58 aDecDbl.mfValue = nTemp;
60 else
62 aDecDbl.maStruct.w32_parts.msw = static_cast< sal_uInt32 >( nRkValue & BIFF_RK_VALUEMASK );
65 if( getFlag( nRkValue, BIFF_RK_100FLAG ) )
66 aDecDbl.mfValue /= 100.0;
68 return aDecDbl.mfValue;
71 /*static*/ double BiffHelper::calcDoubleFromError( sal_uInt8 nErrorCode )
73 sal_uInt16 nApiError = 0x7FFF;
74 switch( nErrorCode )
76 case BIFF_ERR_NULL: nApiError = 521; break;
77 case BIFF_ERR_DIV0: nApiError = 532; break;
78 case BIFF_ERR_VALUE: nApiError = 519; break;
79 case BIFF_ERR_REF: nApiError = 524; break;
80 case BIFF_ERR_NAME: nApiError = 525; break;
81 case BIFF_ERR_NUM: nApiError = 503; break;
82 case BIFF_ERR_NA: nApiError = 0x7FFF; break;
83 default: OSL_FAIL( "BiffHelper::calcDoubleFromError - unknown error code" );
85 DecodedDouble aDecDbl;
86 ::rtl::math::setNan( &aDecDbl.mfValue );
87 aDecDbl.maStruct.nan_parts.fraction_lo = nApiError;
88 return aDecDbl.mfValue;
91 // BIFF12 import --------------------------------------------------------------
93 /*static*/ OUString BiffHelper::readString( SequenceInputStream& rStrm, bool b32BitLen, bool bAllowNulChars )
95 OUString aString;
96 if( !rStrm.isEof() )
98 sal_Int32 nCharCount = b32BitLen ? rStrm.readValue< sal_Int32 >() : rStrm.readValue< sal_Int16 >();
99 // string length -1 is often used to indicate a missing string
100 OSL_ENSURE( !rStrm.isEof() && (nCharCount >= -1), "BiffHelper::readString - invalid string length" );
101 if( !rStrm.isEof() && (nCharCount > 0) )
103 // SequenceInputStream always supports getRemaining()
104 nCharCount = ::std::min( nCharCount, static_cast< sal_Int32 >( rStrm.getRemaining() / 2 ) );
105 aString = rStrm.readUnicodeArray( nCharCount, bAllowNulChars );
108 return aString;
111 // BIFF2-BIFF8 import ---------------------------------------------------------
113 /*static*/ bool BiffHelper::isBofRecord( BiffInputStream& rStrm )
115 return
116 (rStrm.getRecId() == BIFF2_ID_BOF) ||
117 (rStrm.getRecId() == BIFF3_ID_BOF) ||
118 (rStrm.getRecId() == BIFF4_ID_BOF) ||
119 (rStrm.getRecId() == BIFF5_ID_BOF);
122 /*static*/ bool BiffHelper::skipRecordBlock( BiffInputStream& rStrm, sal_uInt16 nEndRecId )
124 sal_uInt16 nStartRecId = rStrm.getRecId();
125 while( rStrm.startNextRecord() && (rStrm.getRecId() != nEndRecId) )
126 if( rStrm.getRecId() == nStartRecId )
127 skipRecordBlock( rStrm, nEndRecId );
128 return !rStrm.isEof() && (rStrm.getRecId() == nEndRecId);
131 } // namespace xls
132 } // namespace oox
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */