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-2013 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 #include <stdio.h>
34 #include <vector>
35 #include <map>
36 #include <libwpd/libwpd.h>
37 #include <libwpd-stream/libwpd-stream.h>
38 
39 #include "MSPUBTypes.h"
40 
41 #ifdef _MSC_VER
42 
43 typedef unsigned char uint8_t;
44 typedef unsigned short uint16_t;
45 typedef unsigned uint32_t;
46 typedef signed char int8_t;
47 typedef short int16_t;
48 typedef int int32_t;
49 typedef unsigned __int64 uint64_t;
50 
51 #else
52 
53 #ifdef HAVE_CONFIG_H
54 
55 #include <config.h>
56 
57 #ifdef HAVE_STDINT_H
58 #include <stdint.h>
59 #endif
60 
61 #ifdef HAVE_INTTYPES_H
62 #include <inttypes.h>
63 #endif
64 
65 #else
66 
67 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
68 #include <stdint.h>
69 #include <inttypes.h>
70 
71 #endif
72 
73 #endif
74 
75 // debug message includes source file and line number
76 //#define VERBOSE_DEBUG 1
77 
78 // do nothing with debug messages in a release compile
79 #ifdef DEBUG
80 #ifdef VERBOSE_DEBUG
81 #define MSPUB_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
82 #define MSPUB_DEBUG(M) M
83 #else
84 #define MSPUB_DEBUG_MSG(M) printf M
85 #define MSPUB_DEBUG(M) M
86 #endif
87 #else
88 #define MSPUB_DEBUG_MSG(M)
89 #define MSPUB_DEBUG(M)
90 #endif
91 
92 namespace libmspub
93 {
94 const char *mimeByImgType(ImgType type);
95 const char *windowsCharsetNameByOriginalCharset(const char *name);
96 
97 uint8_t readU8(WPXInputStream *input);
98 uint16_t readU16(WPXInputStream *input);
99 uint32_t readU32(WPXInputStream *input);
100 uint64_t readU64(WPXInputStream *input);
101 int8_t readS8(WPXInputStream *input);
102 int16_t readS16(WPXInputStream *input);
103 int32_t readS32(WPXInputStream *input);
104 double readFixedPoint(WPXInputStream *input);
105 double toFixedPoint(int fp);
106 void readNBytes(WPXInputStream *input, unsigned long length, std::vector<unsigned char> &out);
107 
108 void appendCharacters(WPXString &text, std::vector<unsigned char> characters, const char *encoding);
109 
110 bool stillReading(WPXInputStream *input, unsigned long until);
111 
112 void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
113 void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
114 
115 unsigned correctModulo(int x, unsigned n);
116 double doubleModulo(double x, double y);
117 
118 template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
119 {
120  typename MapT::iterator i = map.find(key);
121  return i == map.end() ? NULL : &(i->second);
122 }
123 
124 template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
125 {
126  typename MapT::const_iterator i = map.find(key);
127  return i == map.end() ? NULL : &(i->second);
128 }
129 
130 template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
131 {
132  typename MapT::iterator i = map.find(key);
133  return i == map.end() ? NULL : i->second;
134 }
135 
137 {
138 };
139 
141 {
142 };
143 
144 WPXBinaryData inflateData(WPXBinaryData);
145 
146 } // namespace libmspub
147 
148 #endif // __LIBMSPUB_UTILS_H__
149 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.1.2