libmspub_utils.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* libmspub
3  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License or as specified alternatively below. You may obtain a copy of
8  * the License at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * Major Contributor(s):
16  * Copyright (C) 2012 Brennan Vincent <brennanv@email.arizona.edu>
17  * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
18  *
19  * All Rights Reserved.
20  *
21  * For minor contributions see the git repository.
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
25  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
26  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
27  * instead of those above.
28  */
29 
30 #ifndef __LIBMSPUB_UTILS_H__
31 #define __LIBMSPUB_UTILS_H__
32 
33 const double PI = 3.1415926;
34 
35 #include <stdio.h>
36 #include <cmath>
37 #include <vector>
38 #include <map>
39 #include <boost/ptr_container/ptr_map.hpp>
40 #include <libwpd/libwpd.h>
41 #include <libwpd-stream/libwpd-stream.h>
42 
43 #include "MSPUBTypes.h"
44 
45 #ifdef _MSC_VER
46 
47 typedef unsigned char uint8_t;
48 typedef unsigned short uint16_t;
49 typedef unsigned uint32_t;
50 typedef int int32_t;
51 typedef unsigned __int64 uint64_t;
52 
53 #else
54 
55 #ifdef HAVE_CONFIG_H
56 
57 #include <config.h>
58 
59 #ifdef HAVE_STDINT_H
60 #include <stdint.h>
61 #endif
62 
63 #ifdef HAVE_INTTYPES_H
64 #include <inttypes.h>
65 #endif
66 
67 #else
68 
69 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
70 #include <stdint.h>
71 #include <inttypes.h>
72 
73 #endif
74 
75 #endif
76 
77 // debug message includes source file and line number
78 //#define VERBOSE_DEBUG 1
79 
80 // do nothing with debug messages in a release compile
81 #ifdef DEBUG
82 #ifdef VERBOSE_DEBUG
83 #define MSPUB_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
84 #define MSPUB_DEBUG(M) M
85 #else
86 #define MSPUB_DEBUG_MSG(M) printf M
87 #define MSPUB_DEBUG(M) M
88 #endif
89 #else
90 #define MSPUB_DEBUG_MSG(M)
91 #define MSPUB_DEBUG(M)
92 #endif
93 
94 namespace libmspub
95 {
96 const char *mimeByImgType(ImgType type);
97 
98 uint16_t readU16(const unsigned char *input, unsigned offset);
99 uint32_t readU32(const unsigned char *input, unsigned offset);
100 
101 uint8_t readU8(WPXInputStream *input);
102 uint16_t readU16(WPXInputStream *input);
103 uint32_t readU32(WPXInputStream *input);
104 uint64_t readU64(WPXInputStream *input);
105 int32_t readS32(WPXInputStream *input);
106 double readFixedPoint(WPXInputStream *input);
107 double toFixedPoint(int fp);
108 void readNBytes(WPXInputStream *input, unsigned long length, std::vector<unsigned char> &out);
109 
110 void appendCharacters(WPXString &text, std::vector<unsigned char> characters);
111 
112 bool stillReading(WPXInputStream *input, unsigned long until);
113 
114 void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
115 void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
116 
117 unsigned correctModulo(int x, unsigned n);
118 double doubleModulo(double x, double y);
119 
120 template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
121 {
122  typename MapT::iterator i = map.find(key);
123  return i == map.end() ? NULL : &(i->second);
124 }
125 
126 template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
127 {
128  typename MapT::const_iterator i = map.find(key);
129  return i == map.end() ? NULL : &(i->second);
130 }
131 
132 template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
133 {
134  typename MapT::iterator i = map.find(key);
135  return i == map.end() ? NULL : i->second;
136 }
137 
139 {
140 };
141 
143 {
144 };
145 
146 WPXBinaryData inflateData(WPXBinaryData);
147 
148 } // namespace libmspub
149 
150 #endif // __LIBMSPUB_UTILS_H__
151 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.1.2