1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef OOX_XLS_BIFFINPUTSTREAM_HXX 29*cdf0e10cSrcweir #define OOX_XLS_BIFFINPUTSTREAM_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <vector> 32*cdf0e10cSrcweir #include "oox/helper/binaryinputstream.hxx" 33*cdf0e10cSrcweir #include "oox/xls/biffhelper.hxx" 34*cdf0e10cSrcweir #include "oox/xls/biffcodec.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir namespace rtl { class OUStringBuffer; } 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir namespace oox { 39*cdf0e10cSrcweir namespace xls { 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // ============================================================================ 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir namespace prv { 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir /** Buffers the contents of a raw record and encapsulates stream decoding. */ 46*cdf0e10cSrcweir class BiffInputRecordBuffer 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir public: 49*cdf0e10cSrcweir explicit BiffInputRecordBuffer( BinaryInputStream& rInStrm ); 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /** Returns the wrapped binary base stream. */ 52*cdf0e10cSrcweir inline const BinaryInputStream& getBaseStream() const { return mrInStrm; } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir /** Sets a decoder object and decrypts buffered record data. */ 55*cdf0e10cSrcweir void setDecoder( const BiffDecoderRef& rxDecoder ); 56*cdf0e10cSrcweir /** Returns the current decoder object. */ 57*cdf0e10cSrcweir inline BiffDecoderRef getDecoder() const { return mxDecoder; } 58*cdf0e10cSrcweir /** Enables/disables usage of current decoder. */ 59*cdf0e10cSrcweir void enableDecoder( bool bEnable ); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir /** Restarts the stream at the passed position. Buffer is invalid until the 62*cdf0e10cSrcweir next call of startRecord() or startNextRecord(). */ 63*cdf0e10cSrcweir void restartAt( sal_Int64 nPos ); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir /** Reads the record header at the passed position. */ 66*cdf0e10cSrcweir bool startRecord( sal_Int64 nHeaderPos ); 67*cdf0e10cSrcweir /** Reads the next record header from the stream. */ 68*cdf0e10cSrcweir bool startNextRecord(); 69*cdf0e10cSrcweir /** Returns the start position of the record header in the core stream. */ 70*cdf0e10cSrcweir sal_uInt16 getNextRecId(); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /** Returns the start position of the record header in the core stream. */ 73*cdf0e10cSrcweir inline sal_Int64 getRecHeaderPos() const { return mnHeaderPos; } 74*cdf0e10cSrcweir /** Returns the current record identifier. */ 75*cdf0e10cSrcweir inline sal_uInt16 getRecId() const { return mnRecId; } 76*cdf0e10cSrcweir /** Returns the current record size. */ 77*cdf0e10cSrcweir inline sal_uInt16 getRecSize() const { return mnRecSize; } 78*cdf0e10cSrcweir /** Returns the current read position in the current record body. */ 79*cdf0e10cSrcweir inline sal_uInt16 getRecPos() const { return mnRecPos; } 80*cdf0e10cSrcweir /** Returns the number of remaining bytes in the current record body. */ 81*cdf0e10cSrcweir inline sal_uInt16 getRecLeft() const { return mnRecSize - mnRecPos; } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** Reads nBytes bytes to the existing buffer opData. Must NOT overread the source buffer. */ 84*cdf0e10cSrcweir void read( void* opData, sal_uInt16 nBytes ); 85*cdf0e10cSrcweir /** Ignores nBytes bytes. Must NOT overread the buffer. */ 86*cdf0e10cSrcweir void skip( sal_uInt16 nBytes ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir private: 89*cdf0e10cSrcweir /** Updates data buffer from stream, if needed. */ 90*cdf0e10cSrcweir void updateBuffer(); 91*cdf0e10cSrcweir /** Updates decoded data from original data. */ 92*cdf0e10cSrcweir void updateDecoded(); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir private: 95*cdf0e10cSrcweir typedef ::std::vector< sal_uInt8 > DataBuffer; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir BinaryInputStream& mrInStrm; /// Core input stream. 98*cdf0e10cSrcweir DataBuffer maOriginalData; /// Original data read from stream. 99*cdf0e10cSrcweir DataBuffer maDecodedData; /// Decoded data. 100*cdf0e10cSrcweir DataBuffer* mpCurrentData; /// Points to data buffer currently in use. 101*cdf0e10cSrcweir BiffDecoderRef mxDecoder; /// Decoder object. 102*cdf0e10cSrcweir sal_Int64 mnHeaderPos; /// Stream start position of current record header. 103*cdf0e10cSrcweir sal_Int64 mnBodyPos; /// Stream start position of current record body. 104*cdf0e10cSrcweir sal_Int64 mnBufferBodyPos; /// Stream start position of buffered data. 105*cdf0e10cSrcweir sal_Int64 mnNextHeaderPos; /// Stream start position of next record header. 106*cdf0e10cSrcweir sal_uInt16 mnRecId; /// Current record identifier. 107*cdf0e10cSrcweir sal_uInt16 mnRecSize; /// Current record size. 108*cdf0e10cSrcweir sal_uInt16 mnRecPos; /// Current position in record body. 109*cdf0e10cSrcweir bool mbValidHeader; /// True = valid record header. 110*cdf0e10cSrcweir }; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir } // namespace prv 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // ============================================================================ 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir /** This class is used to read BIFF record streams. 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir An instance is constructed with a BinaryInputStream object. The passed 119*cdf0e10cSrcweir stream is reset to its start while constructing this stream. 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir To start reading a record call startNextRecord(). Now it is possible to 122*cdf0e10cSrcweir read all contents of the record using operator>>() or any of the read***() 123*cdf0e10cSrcweir functions. If some data exceeds the record size limit, the stream looks for 124*cdf0e10cSrcweir a following CONTINUE record and jumps automatically to it. It is NOT 125*cdf0e10cSrcweir allowed that an atomic data type is split into two records (e.g. 4 bytes of 126*cdf0e10cSrcweir a double in one record and the other 4 bytes in a following CONTINUE). 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir Trying to read over the record limits results in a stream error. The 129*cdf0e10cSrcweir isValid() function indicates that by returning false. From now on the data 130*cdf0e10cSrcweir returned by the read functions is undefined. The error state will be reset, 131*cdf0e10cSrcweir if the record is reset (with the function resetRecord()), or if the next 132*cdf0e10cSrcweir record is started. 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir To switch off the automatic lookup of CONTINUE records, use resetRecord() 135*cdf0e10cSrcweir with false parameter. This is useful e.g. on import of drawing layer data, 136*cdf0e10cSrcweir where sometimes solely CONTINUE records will occur. The automatic lookup 137*cdf0e10cSrcweir keeps switched off until the method resetRecord() is called with parameter 138*cdf0e10cSrcweir true. All other settings done on the stream (e.g. alternative CONTINUE 139*cdf0e10cSrcweir record identifier, enabled decryption, NUL substitution character) will be 140*cdf0e10cSrcweir reset to default values, if a new record is started. 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir The import stream supports decrypting the stream data. The contents of a 143*cdf0e10cSrcweir record (not the record header) will be encrypted by Excel if the file has 144*cdf0e10cSrcweir been stored with password protection. The functions setDecoder() and 145*cdf0e10cSrcweir enableDecoder() control the usage of the decryption algorithms. 146*cdf0e10cSrcweir setDecoder() sets a new decryption algorithm and initially enables it. 147*cdf0e10cSrcweir enableDecoder( false ) may be used to stop the usage of the decryption 148*cdf0e10cSrcweir temporarily (sometimes record contents are never encrypted, e.g. all BOF 149*cdf0e10cSrcweir records or the stream position in SHEET records). Decryption will be 150*cdf0e10cSrcweir reenabled automatically, if a new record is started with the function 151*cdf0e10cSrcweir startNextRecord(). 152*cdf0e10cSrcweir */ 153*cdf0e10cSrcweir class BiffInputStream : public BinaryInputStream 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir public: 156*cdf0e10cSrcweir /** Constructs the BIFF record stream using the passed binary stream. 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir @param rInStream 159*cdf0e10cSrcweir The base input stream. Must be seekable. Will be seeked to its 160*cdf0e10cSrcweir start position. 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir @param bContLookup Automatic CONTINUE lookup on/off. 163*cdf0e10cSrcweir */ 164*cdf0e10cSrcweir explicit BiffInputStream( 165*cdf0e10cSrcweir BinaryInputStream& rInStream, 166*cdf0e10cSrcweir bool bContLookup = true ); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // record control --------------------------------------------------------- 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir /** Sets stream pointer to the start of the next record content. 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir Ignores all CONTINUE records of the current record, if automatic 173*cdf0e10cSrcweir CONTINUE usage is switched on. 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir @return False = no record found (end of stream). 176*cdf0e10cSrcweir */ 177*cdf0e10cSrcweir bool startNextRecord(); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir /** Sets stream pointer to the start of the content of the specified record. 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir The handle of the current record can be received and stored using the 182*cdf0e10cSrcweir function getRecHandle() for later usage with this function. The record 183*cdf0e10cSrcweir handle is equivalent to the position of the underlying binary stream, 184*cdf0e10cSrcweir thus the function can be used to perform a hard seek to a specific 185*cdf0e10cSrcweir position, if it is sure that a record starts exactly at this position. 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir @return False = no record found (invalid handle passed). 188*cdf0e10cSrcweir */ 189*cdf0e10cSrcweir bool startRecordByHandle( sal_Int64 nRecHandle ); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir /** Sets stream pointer to begin of record content. 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir @param bContLookup 194*cdf0e10cSrcweir Automatic CONTINUE lookup on/off. In difference to other stream 195*cdf0e10cSrcweir settings, this setting is persistent until next call of this 196*cdf0e10cSrcweir function (because it is wanted to receive the next CONTINUE records 197*cdf0e10cSrcweir separately). 198*cdf0e10cSrcweir @param nAltContId 199*cdf0e10cSrcweir Sets an alternative record identifier for content continuation. 200*cdf0e10cSrcweir This value is reset automatically when a new record is started with 201*cdf0e10cSrcweir startNextRecord(). 202*cdf0e10cSrcweir */ 203*cdf0e10cSrcweir void resetRecord( 204*cdf0e10cSrcweir bool bContLookup, 205*cdf0e10cSrcweir sal_uInt16 nAltContId = BIFF_ID_UNKNOWN ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir /** Sets stream pointer before current record and invalidates stream. 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir The next call to startNextRecord() will start again the current record. 210*cdf0e10cSrcweir This can be used in situations where a loop or a function leaves on a 211*cdf0e10cSrcweir specific record, but the parent context expects to start this record by 212*cdf0e10cSrcweir itself. The stream is invalid as long as the first record has not been 213*cdf0e10cSrcweir started (it is not allowed to call any other stream operation then). 214*cdf0e10cSrcweir */ 215*cdf0e10cSrcweir void rewindRecord(); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir // decoder ---------------------------------------------------------------- 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir /** Sets a new decoder object. 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir Enables decryption of record contents for the rest of the stream. 222*cdf0e10cSrcweir */ 223*cdf0e10cSrcweir void setDecoder( const BiffDecoderRef& rxDecoder ); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir /** Enables/disables usage of current decoder. 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir Decryption is reenabled automatically, if a new record is started using 228*cdf0e10cSrcweir the function startNextRecord(). 229*cdf0e10cSrcweir */ 230*cdf0e10cSrcweir void enableDecoder( bool bEnable = true ); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir // stream/record state and info ------------------------------------------- 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir /** Returns the current record identifier. */ 235*cdf0e10cSrcweir inline sal_uInt16 getRecId() const { return mnRecId; } 236*cdf0e10cSrcweir /** Returns the record identifier of the following record. */ 237*cdf0e10cSrcweir sal_uInt16 getNextRecId(); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir /** Returns a unique handle for the current record that can be used with 240*cdf0e10cSrcweir the function startRecordByHandle(). */ 241*cdf0e10cSrcweir inline sal_Int64 getRecHandle() const { return mnRecHandle; } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir // BinaryStreamBase interface (seeking) ----------------------------------- 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir /** Returns the data size of the whole record without record headers. */ 246*cdf0e10cSrcweir virtual sal_Int64 size() const; 247*cdf0e10cSrcweir /** Returns the position inside of the whole record content. */ 248*cdf0e10cSrcweir virtual sal_Int64 tell() const; 249*cdf0e10cSrcweir /** Seeks in record content to the specified position. */ 250*cdf0e10cSrcweir virtual void seek( sal_Int64 nRecPos ); 251*cdf0e10cSrcweir /** Closes the input stream but not the wrapped stream. */ 252*cdf0e10cSrcweir virtual void close(); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir /** Returns the absolute position in the wrapped binary stream. */ 255*cdf0e10cSrcweir sal_Int64 tellBase() const; 256*cdf0e10cSrcweir /** Returns the total size of the wrapped binary stream. */ 257*cdf0e10cSrcweir sal_Int64 sizeBase() const; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir // BinaryInputStream interface (stream read access) ----------------------- 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir /** Reads nBytes bytes to the passed sequence. 262*cdf0e10cSrcweir @return Number of bytes really read. */ 263*cdf0e10cSrcweir virtual sal_Int32 readData( StreamDataSequence& orData, sal_Int32 nBytes, size_t nAtomSize = 1 ); 264*cdf0e10cSrcweir /** Reads nBytes bytes and copies them to the passed buffer opMem. 265*cdf0e10cSrcweir @return Number of bytes really read. */ 266*cdf0e10cSrcweir virtual sal_Int32 readMemory( void* opMem, sal_Int32 nBytes, size_t nAtomSize = 1 ); 267*cdf0e10cSrcweir /** Seeks forward inside the current record. */ 268*cdf0e10cSrcweir virtual void skip( sal_Int32 nBytes, size_t nAtomSize = 1 ); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir /** Stream operator for integral and floating-point types. */ 271*cdf0e10cSrcweir template< typename Type > 272*cdf0e10cSrcweir inline BiffInputStream& operator>>( Type& ornValue ) { readValue( ornValue ); return *this; } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir // byte strings ----------------------------------------------------------- 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir /** Reads 8/16 bit string length and character array, and returns the string. 277*cdf0e10cSrcweir @param b16BitLen 278*cdf0e10cSrcweir True = Read 16-bit string length field before the character array. 279*cdf0e10cSrcweir False = Read 8-bit string length field before the character array. 280*cdf0e10cSrcweir @param bAllowNulChars 281*cdf0e10cSrcweir True = NUL characters are inserted into the imported string. 282*cdf0e10cSrcweir False = NUL characters are replaced by question marks (default). 283*cdf0e10cSrcweir */ 284*cdf0e10cSrcweir ::rtl::OString readByteString( bool b16BitLen, bool bAllowNulChars = false ); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir /** Reads 8/16 bit string length and character array, and returns a Unicode string. 287*cdf0e10cSrcweir @param b16BitLen 288*cdf0e10cSrcweir True = Read 16-bit string length field before the character array. 289*cdf0e10cSrcweir False = Read 8-bit string length field before the character array. 290*cdf0e10cSrcweir @param eTextEnc The text encoding used to create the Unicode string. 291*cdf0e10cSrcweir @param bAllowNulChars 292*cdf0e10cSrcweir True = NUL characters are inserted into the imported string. 293*cdf0e10cSrcweir False = NUL characters are replaced by question marks (default). 294*cdf0e10cSrcweir */ 295*cdf0e10cSrcweir ::rtl::OUString readByteStringUC( bool b16BitLen, rtl_TextEncoding eTextEnc, bool bAllowNulChars = false ); 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir /** Ignores 8/16 bit string length and character array. 298*cdf0e10cSrcweir @param b16BitLen 299*cdf0e10cSrcweir True = Read 16-bit string length field before the character array. 300*cdf0e10cSrcweir False = Read 8-bit string length field before the character array. 301*cdf0e10cSrcweir */ 302*cdf0e10cSrcweir void skipByteString( bool b16BitLen ); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir // Unicode strings -------------------------------------------------------- 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir /** Reads nChars characters of a BIFF8 string, and returns the string. 307*cdf0e10cSrcweir @param nChars Number of characters to read from the stream. 308*cdf0e10cSrcweir @param b16BitChars 309*cdf0e10cSrcweir True = The character array contains 16-bit characters. 310*cdf0e10cSrcweir False = The character array contains truncated 8-bit characters. 311*cdf0e10cSrcweir @param bAllowNulChars 312*cdf0e10cSrcweir True = NUL characters are inserted into the imported string. 313*cdf0e10cSrcweir False = NUL characters are replaced by question marks (default). 314*cdf0e10cSrcweir */ 315*cdf0e10cSrcweir ::rtl::OUString readUniStringChars( sal_uInt16 nChars, bool b16BitChars, bool bAllowNulChars = false ); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir /** Reads 8-bit flags, extended header, nChar characters, extended data of 318*cdf0e10cSrcweir a BIFF8 string, and returns the string. 319*cdf0e10cSrcweir @param nChars Number of characters to read from the stream. 320*cdf0e10cSrcweir @param bAllowNulChars 321*cdf0e10cSrcweir True = NUL characters are inserted into the imported string. 322*cdf0e10cSrcweir False = NUL characters are replaced by question marks (default). 323*cdf0e10cSrcweir */ 324*cdf0e10cSrcweir ::rtl::OUString readUniStringBody( sal_uInt16 nChars, bool bAllowNulChars = false ); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir /** Reads 16-bit character count, 8-bit flags, extended header, character 327*cdf0e10cSrcweir array, extended data of a BIFF8 string, and returns the string. 328*cdf0e10cSrcweir @param bAllowNulChars 329*cdf0e10cSrcweir True = NUL characters are inserted into the imported string. 330*cdf0e10cSrcweir False = NUL characters are replaced by question marks (default). 331*cdf0e10cSrcweir */ 332*cdf0e10cSrcweir ::rtl::OUString readUniString( bool bAllowNulChars = false ); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir /** Ignores nChars characters of a BIFF8 string. 335*cdf0e10cSrcweir @param nChars Number of characters to skip in the stream. 336*cdf0e10cSrcweir @param b16BitChars 337*cdf0e10cSrcweir True = The character array contains 16-bit characters. 338*cdf0e10cSrcweir False = The character array contains truncated 8-bit characters. 339*cdf0e10cSrcweir */ 340*cdf0e10cSrcweir void skipUniStringChars( sal_uInt16 nChars, bool b16BitChars ); 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir /** Ignores 8-bit flags, extended header, nChar characters, extended data 343*cdf0e10cSrcweir of a BIFF8 string. 344*cdf0e10cSrcweir @param nChars Number of characters to skip in the stream. 345*cdf0e10cSrcweir */ 346*cdf0e10cSrcweir void skipUniStringBody( sal_uInt16 nChars ); 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir /** Ignores 16-bit character count, 8-bit flags, extended header, character 349*cdf0e10cSrcweir array, extended data of a BIFF8 string. 350*cdf0e10cSrcweir */ 351*cdf0e10cSrcweir void skipUniString(); 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir // ------------------------------------------------------------------------ 354*cdf0e10cSrcweir private: 355*cdf0e10cSrcweir /** Initializes all members after base stream has been seeked to new record. */ 356*cdf0e10cSrcweir void setupRecord(); 357*cdf0e10cSrcweir /** Restarts the current record from the beginning. */ 358*cdf0e10cSrcweir void restartRecord( bool bInvalidateRecSize ); 359*cdf0e10cSrcweir /** Sets stream pointer before specified record and invalidates stream. */ 360*cdf0e10cSrcweir void rewindToRecord( sal_Int64 nRecHandle ); 361*cdf0e10cSrcweir /** Returns true, if stream was able to start a valid record. */ 362*cdf0e10cSrcweir inline bool isInRecord() const { return mnRecHandle >= 0; } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir /** Returns true, if the passed ID is real or alternative continuation record ID. */ 365*cdf0e10cSrcweir bool isContinueId( sal_uInt16 nRecId ) const; 366*cdf0e10cSrcweir /** Goes to start of the next CONTINUE record. 367*cdf0e10cSrcweir @descr Stream must be located at the end of a raw record, and handling 368*cdf0e10cSrcweir of CONTINUE records must be enabled. 369*cdf0e10cSrcweir @return True if next CONTINUE record has been found and initialized. */ 370*cdf0e10cSrcweir bool jumpToNextContinue(); 371*cdf0e10cSrcweir /** Goes to start of the next CONTINUE record while reading strings. 372*cdf0e10cSrcweir @descr Stream must be located at the end of a raw record. If reading 373*cdf0e10cSrcweir has been started in a CONTINUE record, jumps to an existing following 374*cdf0e10cSrcweir CONTINUE record, even if handling of CONTINUE records is disabled (this 375*cdf0e10cSrcweir is a special handling for TXO string data). Reads additional Unicode 376*cdf0e10cSrcweir flag byte at start of the new raw record and sets or resets rb16BitChars. 377*cdf0e10cSrcweir @return True if next CONTINUE record has been found and initialized. */ 378*cdf0e10cSrcweir bool jumpToNextStringContinue( bool& rb16BitChars ); 379*cdf0e10cSrcweir /** Calculates the complete length of the current record including CONTINUE 380*cdf0e10cSrcweir records, stores the length in mnComplRecSize. */ 381*cdf0e10cSrcweir void calcRecordLength(); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir /** Returns the maximum size of raw data possible to read in one block. */ 384*cdf0e10cSrcweir sal_uInt16 getMaxRawReadSize( sal_Int32 nBytes, size_t nAtomSize ) const; 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir /** Reads the BIFF8 Unicode string header fields. */ 387*cdf0e10cSrcweir void readUniStringHeader( bool& orb16BitChars, sal_Int32& ornAddSize ); 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir private: 390*cdf0e10cSrcweir prv::BiffInputRecordBuffer maRecBuffer; /// Raw record data buffer. 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir sal_Int64 mnRecHandle; /// Handle of current record. 393*cdf0e10cSrcweir sal_uInt16 mnRecId; /// Identifier of current record (not the CONTINUE ID). 394*cdf0e10cSrcweir sal_uInt16 mnAltContId; /// Alternative identifier for content continuation records. 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir sal_Int64 mnCurrRecSize; /// Helper for record size and position. 397*cdf0e10cSrcweir sal_Int64 mnComplRecSize; /// Size of complete record data (with CONTINUEs). 398*cdf0e10cSrcweir bool mbHasComplRec; /// True = mnComplRecSize is valid. 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir bool mbCont; /// True = automatic CONTINUE lookup enabled. 401*cdf0e10cSrcweir }; 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir // ============================================================================ 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir class BiffInputStreamPos 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir public: 408*cdf0e10cSrcweir explicit BiffInputStreamPos( BiffInputStream& rStrm ); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir bool restorePosition(); 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir inline BiffInputStream& getStream() { return mrStrm; } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir private: 415*cdf0e10cSrcweir BiffInputStream& mrStrm; 416*cdf0e10cSrcweir sal_Int64 mnRecHandle; 417*cdf0e10cSrcweir sal_Int64 mnRecPos; 418*cdf0e10cSrcweir }; 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir // ============================================================================ 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir /** Stores the current position of the passed stream on construction and 423*cdf0e10cSrcweir restores it automatically on destruction. */ 424*cdf0e10cSrcweir class BiffInputStreamPosGuard : private BiffInputStreamPos 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir public: 427*cdf0e10cSrcweir explicit BiffInputStreamPosGuard( BiffInputStream& rStrm ); 428*cdf0e10cSrcweir ~BiffInputStreamPosGuard(); 429*cdf0e10cSrcweir }; 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir // ============================================================================ 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir } // namespace xls 434*cdf0e10cSrcweir } // namespace oox 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir #endif 437