Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __LIBMSPUB_UTILS_H__
00031 #define __LIBMSPUB_UTILS_H__
00032
00033 #include <stdio.h>
00034 #include <vector>
00035 #include <map>
00036 #include <boost/ptr_container/ptr_map.hpp>
00037 #include <libwpd/libwpd.h>
00038 #include <libwpd-stream/libwpd-stream.h>
00039
00040 #include "MSPUBTypes.h"
00041
00042 #ifdef _MSC_VER
00043
00044 typedef unsigned char uint8_t;
00045 typedef unsigned short uint16_t;
00046 typedef unsigned uint32_t;
00047 typedef int int32_t;
00048 typedef unsigned __int64 uint64_t;
00049
00050 #else
00051
00052 #ifdef HAVE_CONFIG_H
00053
00054 #include <config.h>
00055
00056 #ifdef HAVE_STDINT_H
00057 #include <stdint.h>
00058 #endif
00059
00060 #ifdef HAVE_INTTYPES_H
00061 #include <inttypes.h>
00062 #endif
00063
00064 #else
00065
00066
00067 #include <stdint.h>
00068 #include <inttypes.h>
00069
00070 #endif
00071
00072 #endif
00073
00074
00075
00076
00077
00078 #ifdef DEBUG
00079 #ifdef VERBOSE_DEBUG
00080 #define MSPUB_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
00081 #define MSPUB_DEBUG(M) M
00082 #else
00083 #define MSPUB_DEBUG_MSG(M) printf M
00084 #define MSPUB_DEBUG(M) M
00085 #endif
00086 #else
00087 #define MSPUB_DEBUG_MSG(M)
00088 #define MSPUB_DEBUG(M)
00089 #endif
00090
00091 namespace libmspub
00092 {
00093 const char *mimeByImgType(ImgType type);
00094
00095 uint16_t readU16(const unsigned char *input, unsigned offset);
00096 uint32_t readU32(const unsigned char *input, unsigned offset);
00097
00098 uint8_t readU8(WPXInputStream *input);
00099 uint16_t readU16(WPXInputStream *input);
00100 uint32_t readU32(WPXInputStream *input);
00101 uint64_t readU64(WPXInputStream *input);
00102 int32_t readS32(WPXInputStream *input);
00103 double readFixedPoint(WPXInputStream *input);
00104 double toFixedPoint(int fp);
00105 void readNBytes(WPXInputStream *input, unsigned long length, std::vector<unsigned char> &out);
00106
00107 void appendCharacters(WPXString &text, std::vector<unsigned char> characters);
00108
00109 bool stillReading(WPXInputStream *input, unsigned long until);
00110
00111 void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
00112 void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
00113
00114 unsigned correctModulo(int x, unsigned n);
00115 double doubleModulo(double x, double y);
00116
00117 template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
00118 {
00119 typename MapT::iterator i = map.find(key);
00120 return i == map.end() ? NULL : &(i->second);
00121 }
00122
00123 template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
00124 {
00125 typename MapT::const_iterator i = map.find(key);
00126 return i == map.end() ? NULL : &(i->second);
00127 }
00128
00129 template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
00130 {
00131 typename MapT::iterator i = map.find(key);
00132 return i == map.end() ? NULL : i->second;
00133 }
00134
00135 class EndOfStreamException
00136 {
00137 };
00138
00139 class GenericException
00140 {
00141 };
00142
00143 WPXBinaryData inflateData(WPXBinaryData);
00144
00145 }
00146
00147 #endif // __LIBMSPUB_UTILS_H__
00148