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

Generated for libmspub by doxygen 1.8.14