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
23typedef unsigned char uint8_t;
24typedef unsigned short uint16_t;
25typedef unsigned uint32_t;
26typedef signed char int8_t;
27typedef short int16_t;
28typedef int int32_t;
29typedef 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
72namespace libmspub
73{
74const char *mimeByImgType(ImgType type);
75const char *windowsCharsetNameByOriginalCharset(const char *name);
76
77uint8_t readU8(librevenge::RVNGInputStream *input);
78uint16_t readU16(librevenge::RVNGInputStream *input);
79uint32_t readU32(librevenge::RVNGInputStream *input);
80uint64_t readU64(librevenge::RVNGInputStream *input);
81int8_t readS8(librevenge::RVNGInputStream *input);
82int16_t readS16(librevenge::RVNGInputStream *input);
83int32_t readS32(librevenge::RVNGInputStream *input);
84double readFixedPoint(librevenge::RVNGInputStream *input);
85double toFixedPoint(int fp);
86void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector<unsigned char> &out);
87
88void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters, const char *encoding);
89
90bool stillReading(librevenge::RVNGInputStream *input, unsigned long until);
91
92void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
93void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
94
95unsigned correctModulo(int x, unsigned n);
96double doubleModulo(double x, double y);
97
98template <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
104template <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
110template <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
124librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData);
125
126} // namespace libmspub
127
128#endif // __LIBMSPUB_UTILS_H__
129/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition: libmspub_utils.h:117
Definition: libmspub_utils.h:121
Definition: Arrow.h:14
int16_t readS16(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:297
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:276
unsigned correctModulo(int x, unsigned n)
Definition: libmspub_utils.cpp:142
double readFixedPoint(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:123
MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:110
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:257
void appendCharacters(librevenge::RVNGString &text, const std::vector< unsigned char > characters, const char *encoding)
Definition: libmspub_utils.cpp:343
int32_t readS32(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:302
int8_t readS8(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:292
librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData deflated)
Definition: libmspub_utils.cpp:158
const MapT::mapped_type * getIfExists_const(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:104
void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation)
Definition: libmspub_utils.cpp:87
const char * mimeByImgType(ImgType type)
Definition: libmspub_utils.cpp:63
double toFixedPoint(int fp)
Definition: libmspub_utils.cpp:116
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:307
double doubleModulo(double x, double y)
Definition: libmspub_utils.cpp:99
void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal)
Definition: libmspub_utils.cpp:128
const char * windowsCharsetNameByOriginalCharset(const char *name)
Definition: libmspub_utils.cpp:30
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition: libmspub_utils.cpp:283
void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector< unsigned char > &out)
Definition: libmspub_utils.cpp:320
MapT::mapped_type * getIfExists(MapT &map, const typename MapT::key_type &key)
Definition: libmspub_utils.h:98
bool stillReading(librevenge::RVNGInputStream *input, unsigned long until)
Definition: libmspub_utils.cpp:376
ImgType
Definition: MSPUBTypes.h:180

Generated for libmspub by doxygen 1.9.3