libmspub_utils.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libmspub project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef __LIBMSPUB_UTILS_H__
00011 #define __LIBMSPUB_UTILS_H__
00012 
00013 #include <stdio.h>
00014 #include <vector>
00015 #include <map>
00016 #include <librevenge/librevenge.h>
00017 #include <librevenge-stream/librevenge-stream.h>
00018 
00019 #include "MSPUBTypes.h"
00020 
00021 #ifdef _MSC_VER
00022 
00023 typedef unsigned char uint8_t;
00024 typedef unsigned short uint16_t;
00025 typedef unsigned uint32_t;
00026 typedef signed char int8_t;
00027 typedef short int16_t;
00028 typedef int int32_t;
00029 typedef unsigned __int64 uint64_t;
00030 
00031 #else
00032 
00033 #ifdef HAVE_CONFIG_H
00034 
00035 #include <config.h>
00036 
00037 #ifdef HAVE_STDINT_H
00038 #include <stdint.h>
00039 #endif
00040 
00041 #ifdef HAVE_INTTYPES_H
00042 #include <inttypes.h>
00043 #endif
00044 
00045 #else
00046 
00047 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
00048 #include <stdint.h>
00049 #include <inttypes.h>
00050 
00051 #endif
00052 
00053 #endif
00054 
00055 // debug message includes source file and line number
00056 //#define VERBOSE_DEBUG 1
00057 
00058 // do nothing with debug messages in a release compile
00059 #ifdef DEBUG
00060 #ifdef VERBOSE_DEBUG
00061 #define MSPUB_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
00062 #define MSPUB_DEBUG(M) M
00063 #else
00064 #define MSPUB_DEBUG_MSG(M) printf M
00065 #define MSPUB_DEBUG(M) M
00066 #endif
00067 #else
00068 #define MSPUB_DEBUG_MSG(M)
00069 #define MSPUB_DEBUG(M)
00070 #endif
00071 
00072 namespace libmspub
00073 {
00074 const char *mimeByImgType(ImgType type);
00075 const char *windowsCharsetNameByOriginalCharset(const char *name);
00076 
00077 uint8_t readU8(librevenge::RVNGInputStream *input);
00078 uint16_t readU16(librevenge::RVNGInputStream *input);
00079 uint32_t readU32(librevenge::RVNGInputStream *input);
00080 uint64_t readU64(librevenge::RVNGInputStream *input);
00081 int8_t readS8(librevenge::RVNGInputStream *input);
00082 int16_t readS16(librevenge::RVNGInputStream *input);
00083 int32_t readS32(librevenge::RVNGInputStream *input);
00084 double readFixedPoint(librevenge::RVNGInputStream *input);
00085 double toFixedPoint(int fp);
00086 void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector<unsigned char> &out);
00087 
00088 void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters, const char *encoding);
00089 
00090 bool stillReading(librevenge::RVNGInputStream *input, unsigned long until);
00091 
00092 void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
00093 void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
00094 
00095 unsigned correctModulo(int x, unsigned n);
00096 double doubleModulo(double x, double y);
00097 
00098 template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
00099 {
00100   typename MapT::iterator i = map.find(key);
00101   return i == map.end() ? NULL : &(i->second);
00102 }
00103 
00104 template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
00105 {
00106   typename MapT::const_iterator i = map.find(key);
00107   return i == map.end() ? NULL : &(i->second);
00108 }
00109 
00110 template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
00111 {
00112   typename MapT::iterator i = map.find(key);
00113   return i == map.end() ? NULL : i->second;
00114 }
00115 
00116 class EndOfStreamException
00117 {
00118 };
00119 
00120 class GenericException
00121 {
00122 };
00123 
00124 librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData);
00125 
00126 } // namespace libmspub
00127 
00128 #endif // __LIBMSPUB_UTILS_H__
00129 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */