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 /*
3  * This file is part of the libmspub project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef __LIBMSPUB_UTILS_H__
11 #define __LIBMSPUB_UTILS_H__
12 
13 #include <stdio.h>
14 #include <vector>
15 #include <map>
16 #include <librevenge/librevenge.h>
17 #include <librevenge-stream/librevenge-stream.h>
18 
19 #include "MSPUBTypes.h"
20 
21 #ifdef _MSC_VER
22 
23 typedef unsigned char uint8_t;
24 typedef unsigned short uint16_t;
25 typedef unsigned uint32_t;
26 typedef signed char int8_t;
27 typedef short int16_t;
28 typedef int int32_t;
29 typedef unsigned __int64 uint64_t;
30 
31 #else
32 
33 #ifdef HAVE_CONFIG_H
34 
35 #include <config.h>
36 
37 #ifdef HAVE_STDINT_H
38 #include <stdint.h>
39 #endif
40 
41 #ifdef HAVE_INTTYPES_H
42 #include <inttypes.h>
43 #endif
44 
45 #else
46 
47 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
48 #include <stdint.h>
49 #include <inttypes.h>
50 
51 #endif
52 
53 #endif
54 
55 // debug message includes source file and line number
56 //#define VERBOSE_DEBUG 1
57 
58 // do nothing with debug messages in a release compile
59 #ifdef DEBUG
60 #ifdef VERBOSE_DEBUG
61 #define MSPUB_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
62 #define MSPUB_DEBUG(M) M
63 #else
64 #define MSPUB_DEBUG_MSG(M) printf M
65 #define MSPUB_DEBUG(M) M
66 #endif
67 #else
68 #define MSPUB_DEBUG_MSG(M)
69 #define MSPUB_DEBUG(M)
70 #endif
71 
72 namespace libmspub
73 {
74 const char *mimeByImgType(ImgType type);
75 const char *windowsCharsetNameByOriginalCharset(const char *name);
76 
77 uint8_t readU8(librevenge::RVNGInputStream *input);
78 uint16_t readU16(librevenge::RVNGInputStream *input);
79 uint32_t readU32(librevenge::RVNGInputStream *input);
80 uint64_t readU64(librevenge::RVNGInputStream *input);
81 int8_t readS8(librevenge::RVNGInputStream *input);
82 int16_t readS16(librevenge::RVNGInputStream *input);
83 int32_t readS32(librevenge::RVNGInputStream *input);
84 double readFixedPoint(librevenge::RVNGInputStream *input);
85 double toFixedPoint(int fp);
86 void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector<unsigned char> &out);
87 
88 void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters, const char *encoding);
89 
90 bool stillReading(librevenge::RVNGInputStream *input, unsigned long until);
91 
92 void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
93 void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
94 
95 unsigned correctModulo(int x, unsigned n);
96 double doubleModulo(double x, double y);
97 
98 template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
99 {
100  typename MapT::iterator i = map.find(key);
101  return i == map.end() ? NULL : &(i->second);
102 }
103 
104 template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
105 {
106  typename MapT::const_iterator i = map.find(key);
107  return i == map.end() ? NULL : &(i->second);
108 }
109 
110 template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
111 {
112  typename MapT::iterator i = map.find(key);
113  return i == map.end() ? NULL : i->second;
114 }
115 
117 {
118 };
119 
121 {
122 };
123 
124 librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData);
125 
126 } // namespace libmspub
127 
128 #endif // __LIBMSPUB_UTILS_H__
129 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
unsigned correctModulo(int x, unsigned n)
Definition: libmspub_utils.cpp:142
bool stillReading(librevenge::RVNGInputStream *input, unsigned long until)
Definition: libmspub_utils.cpp:376
void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation)
Definition: libmspub_utils.cpp:87
Definition: libmspub_utils.h:116
const char * mimeByImgType(ImgType type)
Definition: libmspub_utils.cpp:63
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:283
MapT::mapped_type * getIfExists(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:98
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:307
const MapT::mapped_type * getIfExists_const(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:104
int32_t readS32(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:302
double readFixedPoint(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:123
void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal)
Definition: libmspub_utils.cpp:128
int8_t readS8(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:292
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:257
MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:110
void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector< unsigned char > &out)
Definition: libmspub_utils.cpp:320
ImgType
Definition: MSPUBTypes.h:179
librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData deflated)
Definition: libmspub_utils.cpp:158
double doubleModulo(double x, double y)
Definition: libmspub_utils.cpp:99
Definition: Arrow.h:13
const char * windowsCharsetNameByOriginalCharset(const char *name)
Definition: libmspub_utils.cpp:30
Definition: libmspub_utils.h:120
double toFixedPoint(int fp)
Definition: libmspub_utils.cpp:116
void appendCharacters(librevenge::RVNGString &text, const std::vector< unsigned char > characters, const char *encoding)
Definition: libmspub_utils.cpp:343
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:276
int16_t readS16(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:297

Generated for libmspub by doxygen 1.8.9.1