Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* libmspub
3 : * Version: MPL 1.1 / GPLv2+ / LGPLv2+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2012 Brennan Vincent <brennanv@email.arizona.edu>
17 : * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
18 : *
19 : * All Rights Reserved.
20 : *
21 : * For minor contributions see the git repository.
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
25 : * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
26 : * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
27 : * instead of those above.
28 : */
29 :
30 : #ifndef __LIBMSPUB_UTILS_H__
31 : #define __LIBMSPUB_UTILS_H__
32 :
33 : #include <stdio.h>
34 : #include <vector>
35 : #include <map>
36 : #include <boost/ptr_container/ptr_map.hpp>
37 : #include <libwpd/libwpd.h>
38 : #include <libwpd-stream/libwpd-stream.h>
39 :
40 : #include "MSPUBTypes.h"
41 :
42 : #ifdef _MSC_VER
43 :
44 : typedef unsigned char uint8_t;
45 : typedef unsigned short uint16_t;
46 : #ifndef BOOST_CSTDINT_HPP
47 : typedef unsigned uint32_t;
48 : #endif
49 : typedef signed char int8_t;
50 : typedef short int16_t;
51 : typedef int int32_t;
52 : typedef unsigned __int64 uint64_t;
53 :
54 : #else
55 :
56 : #ifdef HAVE_CONFIG_H
57 :
58 : #include <config.h>
59 :
60 : #ifdef HAVE_STDINT_H
61 : #include <stdint.h>
62 : #endif
63 :
64 : #ifdef HAVE_INTTYPES_H
65 : #include <inttypes.h>
66 : #endif
67 :
68 : #else
69 :
70 : // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
71 : #include <stdint.h>
72 : #include <inttypes.h>
73 :
74 : #endif
75 :
76 : #endif
77 :
78 : // debug message includes source file and line number
79 : //#define VERBOSE_DEBUG 1
80 :
81 : // do nothing with debug messages in a release compile
82 : #ifdef DEBUG
83 : #ifdef VERBOSE_DEBUG
84 : #define MSPUB_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
85 : #define MSPUB_DEBUG(M) M
86 : #else
87 : #define MSPUB_DEBUG_MSG(M) printf M
88 : #define MSPUB_DEBUG(M) M
89 : #endif
90 : #else
91 : #define MSPUB_DEBUG_MSG(M)
92 : #define MSPUB_DEBUG(M)
93 : #endif
94 :
95 : namespace libmspub
96 : {
97 : enum Encoding
98 : {
99 : UTF_16,
100 : WIN_1252
101 : };
102 : const char *mimeByImgType(ImgType type);
103 :
104 : uint16_t readU16(const unsigned char *input, unsigned offset);
105 : uint32_t readU32(const unsigned char *input, unsigned offset);
106 :
107 : uint8_t readU8(WPXInputStream *input);
108 : uint16_t readU16(WPXInputStream *input);
109 : uint32_t readU32(WPXInputStream *input);
110 : uint64_t readU64(WPXInputStream *input);
111 : int8_t readS8(WPXInputStream *input);
112 : int16_t readS16(WPXInputStream *input);
113 : int32_t readS32(WPXInputStream *input);
114 : double readFixedPoint(WPXInputStream *input);
115 : double toFixedPoint(int fp);
116 : void readNBytes(WPXInputStream *input, unsigned long length, std::vector<unsigned char> &out);
117 :
118 : void appendCharacters(WPXString &text, std::vector<unsigned char> characters, Encoding encoding);
119 :
120 : bool stillReading(WPXInputStream *input, unsigned long until);
121 :
122 : void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
123 : void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
124 :
125 : unsigned correctModulo(int x, unsigned n);
126 : double doubleModulo(double x, double y);
127 :
128 0 : template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
129 : {
130 0 : typename MapT::iterator i = map.find(key);
131 0 : return i == map.end() ? NULL : &(i->second);
132 : }
133 :
134 0 : template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
135 : {
136 0 : typename MapT::const_iterator i = map.find(key);
137 0 : return i == map.end() ? NULL : &(i->second);
138 : }
139 :
140 : template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
141 : {
142 : typename MapT::iterator i = map.find(key);
143 : return i == map.end() ? NULL : i->second;
144 : }
145 :
146 : class EndOfStreamException
147 : {
148 : };
149 :
150 : class GenericException
151 : {
152 : };
153 :
154 : WPXBinaryData inflateData(WPXBinaryData);
155 :
156 : } // namespace libmspub
157 :
158 : #endif // __LIBMSPUB_UTILS_H__
159 : /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|