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 /* libmspub
00003  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2012 Brennan Vincent <brennanv@email.arizona.edu>
00017  * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
00018  *
00019  * All Rights Reserved.
00020  *
00021  * For minor contributions see the git repository.
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00025  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00026  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00027  * instead of those above.
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 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
00067 #include <stdint.h>
00068 #include <inttypes.h>
00069 
00070 #endif
00071 
00072 #endif
00073 
00074 // debug message includes source file and line number
00075 //#define VERBOSE_DEBUG 1
00076 
00077 // do nothing with debug messages in a release compile
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 } // namespace libmspub
00146 
00147 #endif // __LIBMSPUB_UTILS_H__
00148 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */