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-2013 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 <libwpd/libwpd.h>
00037 #include <libwpd-stream/libwpd-stream.h>
00038 
00039 #include "MSPUBTypes.h"
00040 
00041 #ifdef _MSC_VER
00042 
00043 typedef unsigned char uint8_t;
00044 typedef unsigned short uint16_t;
00045 typedef unsigned uint32_t;
00046 typedef signed char int8_t;
00047 typedef short int16_t;
00048 typedef int int32_t;
00049 typedef unsigned __int64 uint64_t;
00050 
00051 #else
00052 
00053 #ifdef HAVE_CONFIG_H
00054 
00055 #include <config.h>
00056 
00057 #ifdef HAVE_STDINT_H
00058 #include <stdint.h>
00059 #endif
00060 
00061 #ifdef HAVE_INTTYPES_H
00062 #include <inttypes.h>
00063 #endif
00064 
00065 #else
00066 
00067 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
00068 #include <stdint.h>
00069 #include <inttypes.h>
00070 
00071 #endif
00072 
00073 #endif
00074 
00075 // debug message includes source file and line number
00076 //#define VERBOSE_DEBUG 1
00077 
00078 // do nothing with debug messages in a release compile
00079 #ifdef DEBUG
00080 #ifdef VERBOSE_DEBUG
00081 #define MSPUB_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
00082 #define MSPUB_DEBUG(M) M
00083 #else
00084 #define MSPUB_DEBUG_MSG(M) printf M
00085 #define MSPUB_DEBUG(M) M
00086 #endif
00087 #else
00088 #define MSPUB_DEBUG_MSG(M)
00089 #define MSPUB_DEBUG(M)
00090 #endif
00091 
00092 namespace libmspub
00093 {
00094 const char *mimeByImgType(ImgType type);
00095 const char *windowsCharsetNameByOriginalCharset(const char *name);
00096 
00097 uint8_t readU8(WPXInputStream *input);
00098 uint16_t readU16(WPXInputStream *input);
00099 uint32_t readU32(WPXInputStream *input);
00100 uint64_t readU64(WPXInputStream *input);
00101 int8_t readS8(WPXInputStream *input);
00102 int16_t readS16(WPXInputStream *input);
00103 int32_t readS32(WPXInputStream *input);
00104 double readFixedPoint(WPXInputStream *input);
00105 double toFixedPoint(int fp);
00106 void readNBytes(WPXInputStream *input, unsigned long length, std::vector<unsigned char> &out);
00107 
00108 void appendCharacters(WPXString &text, std::vector<unsigned char> characters, const char *encoding);
00109 
00110 bool stillReading(WPXInputStream *input, unsigned long until);
00111 
00112 void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
00113 void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
00114 
00115 unsigned correctModulo(int x, unsigned n);
00116 double doubleModulo(double x, double y);
00117 
00118 template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
00119 {
00120   typename MapT::iterator i = map.find(key);
00121   return i == map.end() ? NULL : &(i->second);
00122 }
00123 
00124 template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
00125 {
00126   typename MapT::const_iterator i = map.find(key);
00127   return i == map.end() ? NULL : &(i->second);
00128 }
00129 
00130 template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
00131 {
00132   typename MapT::iterator i = map.find(key);
00133   return i == map.end() ? NULL : i->second;
00134 }
00135 
00136 class EndOfStreamException
00137 {
00138 };
00139 
00140 class GenericException
00141 {
00142 };
00143 
00144 WPXBinaryData inflateData(WPXBinaryData);
00145 
00146 } // namespace libmspub
00147 
00148 #endif // __LIBMSPUB_UTILS_H__
00149 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */