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
48namespace libmspub
49{
50void 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
59namespace libmspub
60{
61const char *mimeByImgType(ImgType type);
62const char *windowsCharsetNameByOriginalCharset(const char *name);
63
64uint8_t readU8(librevenge::RVNGInputStream *input);
65uint16_t readU16(librevenge::RVNGInputStream *input);
66uint32_t readU32(librevenge::RVNGInputStream *input);
67uint64_t readU64(librevenge::RVNGInputStream *input);
68int8_t readS8(librevenge::RVNGInputStream *input);
69int16_t readS16(librevenge::RVNGInputStream *input);
70int32_t readS32(librevenge::RVNGInputStream *input);
71double readFixedPoint(librevenge::RVNGInputStream *input);
72double toFixedPoint(int fp);
73void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector<unsigned char> &out);
74
75unsigned long getLength(librevenge::RVNGInputStream *input);
76
77void appendCharacters(librevenge::RVNGString &text, const std::vector<unsigned char> &characters, const char *encoding);
78
79bool stillReading(librevenge::RVNGInputStream *input, unsigned long until);
80
81void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
82void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
83
84unsigned correctModulo(int x, unsigned n);
85double doubleModulo(double x, double y);
86
87template <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
93template <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
99template <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
113librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData);
114
115} // namespace libmspub
116
117#endif // INCLUDED_LIBMSPUB_UTILS_H
118/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition libmspub_utils.h:106
Definition libmspub_utils.h:110
#define MSPUB_ATTRIBUTE_PRINTF(fmt, arg)
Definition libmspub_utils.h:35
Definition Arrow.h:14
int16_t readS16(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:306
unsigned long getLength(librevenge::RVNGInputStream *const input)
Definition libmspub_utils.cpp:349
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:285
unsigned correctModulo(int x, unsigned n)
Definition libmspub_utils.cpp:151
double readFixedPoint(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:132
MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
Definition libmspub_utils.h:99
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:266
int32_t readS32(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:311
int8_t readS8(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:301
librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData deflated)
Definition libmspub_utils.cpp:167
const MapT::mapped_type * getIfExists_const(MapT &map, const typename MapT::key_type &key)
Definition libmspub_utils.h:93
void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation)
Definition libmspub_utils.cpp:96
const char * mimeByImgType(ImgType type)
Definition libmspub_utils.cpp:72
double toFixedPoint(int fp)
Definition libmspub_utils.cpp:125
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:316
double doubleModulo(double x, double y)
Definition libmspub_utils.cpp:108
void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal)
Definition libmspub_utils.cpp:137
void appendCharacters(librevenge::RVNGString &text, const std::vector< unsigned char > &characters, const char *encoding)
Definition libmspub_utils.cpp:383
const char * windowsCharsetNameByOriginalCharset(const char *name)
Definition libmspub_utils.cpp:39
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:292
void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector< unsigned char > &out)
Definition libmspub_utils.cpp:329
MapT::mapped_type * getIfExists(MapT &map, const typename MapT::key_type &key)
Definition libmspub_utils.h:87
bool stillReading(librevenge::RVNGInputStream *input, unsigned long until)
Definition libmspub_utils.cpp:416
ImgType
Definition MSPUBTypes.h:214

Generated for libmspub by doxygen 1.14.0