LibreOffice Module oox (master)  1
axbinaryreader.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_OOX_OLE_AXBINARYREADER_HXX
21 #define INCLUDED_OOX_OLE_AXBINARYREADER_HXX
22 
23 #include <cstddef>
24 #include <utility>
25 #include <vector>
26 
29 #include <oox/helper/refvector.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
32 
33 namespace oox::ole { struct AxFontData; }
34 
35 namespace oox::ole {
36 
37 
47 {
48 public:
49  explicit AxAlignedInputStream( BinaryInputStream& rInStrm );
50 
53  virtual sal_Int64 size() const override;
56  virtual sal_Int64 tell() const override;
59  virtual void seek( sal_Int64 nPos ) override;
61  virtual void close() override;
62 
65  virtual sal_Int32 readData( StreamDataSequence& orData, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
68  virtual sal_Int32 readMemory( void* opMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
70  virtual void skip( sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
71 
74  void align( size_t nSize );
75 
77  template< typename Type >
78  [[nodiscard]]
79  Type readAligned() { align( sizeof( Type ) ); return readValue< Type >(); }
81  template< typename Type >
82  void skipAligned() { align( sizeof( Type ) ); skip( sizeof( Type ) ); }
83 
84 private:
86  sal_Int64 mnStrmPos;
87  sal_Int64 mnStrmSize;
88 };
89 
90 
92 typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
93 
95 typedef ::std::vector< OUString > AxArrayString;
96 
97 
101 {
102 public:
103  explicit AxBinaryPropertyReader( BinaryInputStream& rInStrm, bool b64BitPropFlags = false );
104 
107  template< typename StreamType, typename DataType >
108  void readIntProperty( DataType& ornValue )
109  { if( startNextProperty() ) ornValue = maInStrm.readAligned< StreamType >(); }
112  void readBoolProperty( bool& orbValue, bool bReverse = false );
115  void readPairProperty( AxPairData& orPairData );
118  void readStringProperty( OUString& orValue );
121  void readArrayStringProperty( std::vector< OUString >& rStrings );
124  void readGuidProperty( OUString& orGuid );
127  void readFontProperty( AxFontData& orFontData );
130  void readPictureProperty( StreamDataSequence& orPicData );
131 
134  template< typename StreamType >
135  void skipIntProperty() { if( startNextProperty() ) maInStrm.skipAligned< StreamType >(); }
154 
156  bool finalizeImport();
157 
158 private:
159  bool ensureValid( bool bCondition = true );
160  bool startNextProperty();
161 
162 private:
165  {
166  virtual ~ComplexProperty();
167  virtual bool readProperty( AxAlignedInputStream& rInStrm ) = 0;
168  };
169 
171  struct PairProperty final : public ComplexProperty
172  {
173  AxPairData& mrPairData;
174 
175  explicit PairProperty( AxPairData& rPairData ) :
176  mrPairData( rPairData ) {}
177  virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
178  };
179 
181  struct StringProperty final : public ComplexProperty
182  {
183  OUString& mrValue;
184  sal_uInt32 mnSize;
185 
186  explicit StringProperty( OUString& rValue, sal_uInt32 nSize ) :
187  mrValue( rValue ), mnSize( nSize ) {}
188  virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
189  };
190 
192  struct ArrayStringProperty final : public ComplexProperty
193  {
194  AxArrayString& mrArray;
195  sal_uInt32 mnSize;
196  explicit ArrayStringProperty( AxArrayString& rArray, sal_uInt32 nSize ) :
197  mrArray( rArray ), mnSize( nSize ) {}
198  virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
199  };
200 
202  struct GuidProperty final : public ComplexProperty
203  {
204  OUString& mrGuid;
205 
206  explicit GuidProperty( OUString& rGuid ) :
207  mrGuid( rGuid ) {}
208  virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
209  };
210 
212  struct FontProperty final : public ComplexProperty
213  {
215 
216  explicit FontProperty( AxFontData& rFontData ) :
217  mrFontData( rFontData ) {}
218  virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
219  };
220 
222  struct PictureProperty final : public ComplexProperty
223  {
225 
226  explicit PictureProperty( StreamDataSequence& rPicData ) :
227  mrPicData( rPicData ) {}
228  virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
229  };
230 
232 
233 private:
235  ComplexPropVector maLargeProps;
236  ComplexPropVector maStreamProps;
238  OUString maDummyString;
239  AxArrayString maDummyArrayString;
240  sal_Int64 mnPropFlags;
241  sal_Int64 mnNextProp;
242  sal_Int64 mnPropsEnd;
243  bool mbValid;
244 };
245 
246 
247 } // namespace oox::ole
248 
249 #endif
250 
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
void readPairProperty(AxPairData &orPairData)
Reads the next pair property from the stream, if the respective flag in the property mask is set...
void readFontProperty(AxFontData &orFontData)
Reads the next font property from the stream, if the respective flag in the property mask is set...
OUString maDummyString
Dummy string for unsupported properties.
StringProperty(OUString &rValue, sal_uInt32 nSize)
bool mbValid
True = stream still valid.
sal_Int64 mnPropFlags
Flags specifying existing properties.
virtual sal_Int64 size() const override
Returns the size of the data this stream represents, if the wrapped stream supports the size() operat...
void readArrayStringProperty(std::vector< OUString > &rStrings)
Reads ArrayString, an array of fmString ( compressed or uncompressed ) is read from the stream and in...
void skipAligned()
Aligns the stream according to the passed type and skips the size of the type.
sal_Int64 mnNextProp
Next property to read.
::std::pair< sal_Int32, sal_Int32 > AxPairData
A pair of integer values as a property.
A wrapper for a binary input stream that supports aligned read operations.
void skipStringProperty()
Skips the next string property in the stream, if the respective flag in the property mask is set...
virtual sal_Int64 tell() const override
Return the current relative stream position (relative to position of the wrapped stream at constructi...
All entries of a font property.
Definition: axfontdata.hxx:53
sal_Int64 mnStrmSize
Size of the wrapped stream data.
ComplexPropVector maLargeProps
Stores info for all used large properties.
Stream property for a picture or mouse icon.
::std::vector< OUString > AxArrayString
An array of string values as a property.
StreamDataSequence maDummyPicData
Dummy picture for unsupported properties.
void skipBoolProperty()
Skips the next boolean property value in the stream, if the respective flag in the property mask is s...
sal_Int64 mnStrmPos
Tracks relative position in the stream.
Complex property for a 32-bit value pair, e.g.
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
void skipIntProperty()
Skips the next integer property value in the stream, if the respective flag in the property mask is s...
void readIntProperty(DataType &ornValue)
Reads the next integer property value from the stream, if the respective flag in the property mask is...
Type readAligned()
Aligns the stream according to the passed type and reads a value.
Interface for binary input stream classes.
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
Import helper to read simple and complex ActiveX form control properties from a binary input stream...
css::uno::Sequence< sal_Int8 > StreamDataSequence
Stream property for a font structure.
Base class for complex properties such as string, point, size, GUID, picture.
Complex property for an array of strings.
virtual void seek(sal_Int64 nPos) override
Seeks the stream to the passed relative position, if it is behind the current position.
ArrayStringProperty(AxArrayString &rArray, sal_uInt32 nSize)
RefVector< ComplexProperty > ComplexPropVector
Complex property for a GUID value.
virtual bool readProperty(AxAlignedInputStream &rInStrm)=0
void skipGuidProperty()
Skips the next GUID property in the stream, if the respective flag in the property mask is set...
BinaryInputStream * mpInStrm
The wrapped input stream.
void readStringProperty(OUString &orValue)
Reads the next string property from the stream, if the respective flag in the property mask is set...
void readPictureProperty(StreamDataSequence &orPicData)
Reads the next picture property from the stream, if the respective flag in the property mask is set...
Complex property for a string value.
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
virtual sal_Int32 readMemory(void *opMem, sal_Int32 nBytes, size_t nAtomSize=1) override
Reads nBytes bytes to the (existing) buffer opMem.
AxAlignedInputStream maInStrm
The input stream to read from.
void skipArrayStringProperty()
Skips the next ArrayString property in the stream, if the respective flag in the property mask is set...
SQLSMALLINT DataType
void align(size_t nSize)
Aligns the stream to a multiple of the passed size (relative to the position of the wrapped stream at...
void skipUndefinedProperty()
Has to be called for undefined properties.
AxArrayString maDummyArrayString
Dummy strings for unsupported ArrayString properties.
virtual sal_Int32 readData(StreamDataSequence &orData, sal_Int32 nBytes, size_t nAtomSize=1) override
Reads nBytes bytes to the passed sequence.
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
void skipPictureProperty()
Skips the next picture property in the stream, if the respective flag in the property mask is set...
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
virtual void close() override
Closes the input stream but not the wrapped stream.
void readGuidProperty(OUString &orGuid)
Reads the next GUID property from the stream, if the respective flag in the property mask is set...
virtual void skip(sal_Int32 nBytes, size_t nAtomSize=1) override
Seeks the stream forward by the passed number of bytes.
ComplexPropVector maStreamProps
Stores info for all used stream data properties.
AxAlignedInputStream(BinaryInputStream &rInStrm)
bool ensureValid(bool bCondition=true)
bool finalizeImport()
Final processing, reads contents of all complex properties.
sal_Int64 mnPropsEnd
End position of simple/large properties.
void readBoolProperty(bool &orbValue, bool bReverse=false)
Reads the next boolean property value from the stream, if the respective flag in the property mask is...
sal_uInt16 nPos
AxBinaryPropertyReader(BinaryInputStream &rInStrm, bool b64BitPropFlags=false)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo