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
105 class EndOfStreamException
106 {
107 };
108
109 class GenericException
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: */
libmspub::correctModulo
unsigned correctModulo(int x, unsigned n)
Definition: libmspub_utils.cpp:151
libmspub::stillReading
bool stillReading(librevenge::RVNGInputStream *input, unsigned long until)
Definition: libmspub_utils.cpp:416
libmspub::rotateCounter
void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation)
Definition: libmspub_utils.cpp:96
libmspub::EndOfStreamException
Definition: libmspub_utils.h:105
libmspub::mimeByImgType
const char * mimeByImgType(ImgType type)
Definition: libmspub_utils.cpp:72
libmspub::readU32
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:292
libmspub::appendCharacters
void appendCharacters(librevenge::RVNGString &text, const std::vector< unsigned char > &characters, const char *encoding)
Definition: libmspub_utils.cpp:383
libmspub::getIfExists
MapT::mapped_type * getIfExists(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:87
libmspub::readU64
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:316
libmspub::getIfExists_const
const MapT::mapped_type * getIfExists_const(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:93
libmspub::readS32
int32_t readS32(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:311
libmspub::readFixedPoint
double readFixedPoint(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:132
libmspub::flipIfNecessary
void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal)
Definition: libmspub_utils.cpp:137
libmspub::getLength
unsigned long getLength(librevenge::RVNGInputStream *const input)
Definition: libmspub_utils.cpp:349
libmspub::readS8
int8_t readS8(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:301
libmspub::readU8
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:266
libmspub::ptr_getIfExists
MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:99
libmspub::readNBytes
void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector< unsigned char > &out)
Definition: libmspub_utils.cpp:329
libmspub::ImgType
ImgType
Definition: MSPUBTypes.h:213
libmspub::inflateData
librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData deflated)
Definition: libmspub_utils.cpp:167
libmspub::doubleModulo
double doubleModulo(double x, double y)
Definition: libmspub_utils.cpp:108
libmspub
Definition: Arrow.h:13
libmspub::windowsCharsetNameByOriginalCharset
const char * windowsCharsetNameByOriginalCharset(const char *name)
Definition: libmspub_utils.cpp:39
libmspub::GenericException
Definition: libmspub_utils.h:109
libmspub::toFixedPoint
double toFixedPoint(int fp)
Definition: libmspub_utils.cpp:125
MSPUBTypes.h
libmspub::readU16
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:285
libmspub::readS16
int16_t readS16(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:306
MSPUB_ATTRIBUTE_PRINTF
#define MSPUB_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libmspub_utils.h:35