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 INCLUDED_LIBMSPUB_UTILS_H
11 #define INCLUDED_LIBMSPUB_UTILS_H
12 
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16 
17 #include <cmath>
18 #include <map>
19 #include <vector>
20 
21 #include <boost/cstdint.hpp>
22 
23 #include <librevenge/librevenge.h>
24 
25 #include <librevenge-stream/librevenge-stream.h>
26 
27 #include "MSPUBTypes.h"
28 
29 #ifndef M_PI
30 #define M_PI 3.14159265358979323846
31 #endif
32 
33 #if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
34 # define MSPUB_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((__format__(__printf__, fmt, arg)))
35 #else
36 # define MSPUB_ATTRIBUTE_PRINTF(fmt, arg)
37 #endif
38 
39 #if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH)
40 # define MSPUB_FALLTHROUGH [[clang::fallthrough]]
41 #elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH)
42 # define MSPUB_FALLTHROUGH __attribute__((fallthrough))
43 #else
44 # define MSPUB_FALLTHROUGH ((void) 0)
45 #endif
46 
47 // do nothing with debug messages in a release compile
48 #ifdef DEBUG
49 namespace libmspub
50 {
51 void debugPrint(const char *format, ...) MSPUB_ATTRIBUTE_PRINTF(1, 2);
52 }
53 #define MSPUB_DEBUG_MSG(M) libmspub::debugPrint M
54 #define MSPUB_DEBUG(M) M
55 #else
56 #define MSPUB_DEBUG_MSG(M)
57 #define MSPUB_DEBUG(M)
58 #endif
59 
60 namespace libmspub
61 {
62 const char *mimeByImgType(ImgType type);
63 const char *windowsCharsetNameByOriginalCharset(const char *name);
64 
65 uint8_t readU8(librevenge::RVNGInputStream *input);
66 uint16_t readU16(librevenge::RVNGInputStream *input);
67 uint32_t readU32(librevenge::RVNGInputStream *input);
68 uint64_t readU64(librevenge::RVNGInputStream *input);
69 int8_t readS8(librevenge::RVNGInputStream *input);
70 int16_t readS16(librevenge::RVNGInputStream *input);
71 int32_t readS32(librevenge::RVNGInputStream *input);
72 double readFixedPoint(librevenge::RVNGInputStream *input);
73 double toFixedPoint(int fp);
74 void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector<unsigned char> &out);
75 
76 unsigned long getLength(librevenge::RVNGInputStream *input);
77 
78 void appendCharacters(librevenge::RVNGString &text, const std::vector<unsigned char> &characters, const char *encoding);
79 
80 bool stillReading(librevenge::RVNGInputStream *input, unsigned long until);
81 
82 void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
83 void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
84 
85 unsigned correctModulo(int x, unsigned n);
86 double doubleModulo(double x, double y);
87 
88 template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
89 {
90  auto i = map.find(key);
91  return i == map.end() ? nullptr : &(i->second);
92 }
93 
94 template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
95 {
96  auto i = map.find(key);
97  return i == map.end() ? nullptr : &(i->second);
98 }
99 
100 template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
101 {
102  typename MapT::iterator i = map.find(key);
103  return i == map.end() ? NULL : i->second;
104 }
105 
107 {
108 };
109 
111 {
112 };
113 
114 librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData);
115 
116 } // namespace libmspub
117 
118 #endif // INCLUDED_LIBMSPUB_UTILS_H
119 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
unsigned correctModulo(int x, unsigned n)
Definition: libmspub_utils.cpp:151
bool stillReading(librevenge::RVNGInputStream *input, unsigned long until)
Definition: libmspub_utils.cpp:416
void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation)
Definition: libmspub_utils.cpp:96
Definition: libmspub_utils.h:106
const char * mimeByImgType(ImgType type)
Definition: libmspub_utils.cpp:72
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:292
void appendCharacters(librevenge::RVNGString &text, const std::vector< unsigned char > &characters, const char *encoding)
Definition: libmspub_utils.cpp:383
MapT::mapped_type * getIfExists(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:88
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:316
const MapT::mapped_type * getIfExists_const(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:94
int32_t readS32(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:311
double readFixedPoint(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:132
void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal)
Definition: libmspub_utils.cpp:137
unsigned long getLength(librevenge::RVNGInputStream *const input)
Definition: libmspub_utils.cpp:349
int8_t readS8(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:301
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:266
MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:100
void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector< unsigned char > &out)
Definition: libmspub_utils.cpp:329
ImgType
Definition: MSPUBTypes.h:213
librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData deflated)
Definition: libmspub_utils.cpp:167
double doubleModulo(double x, double y)
Definition: libmspub_utils.cpp:108
Definition: Arrow.h:13
const char * windowsCharsetNameByOriginalCharset(const char *name)
Definition: libmspub_utils.cpp:39
Definition: libmspub_utils.h:110
double toFixedPoint(int fp)
Definition: libmspub_utils.cpp:125
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:285
int16_t readS16(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:306
#define MSPUB_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libmspub_utils.h:36

Generated for libmspub by doxygen 1.8.14