libwpd_internal.h Source File documentation

libwpd_internal.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwpd
3 * Version: MPL 2.0 / LGPLv2.1+
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 * Major Contributor(s):
10 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
11 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
12 *
13 * For minor contributions see the git repository.
14 *
15 * Alternatively, the contents of this file may be used under the terms
16 * of the GNU Lesser General Public License Version 2.1 or later
17 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
18 * applicable instead of those above.
19 *
20 * For further information visit http://libwpd.sourceforge.net
21 */
22
23 /* "This product is not manufactured, approved, or supported by
24 * Corel Corporation or Corel Corporation Limited."
25 */
26
27 #ifndef LIBWPD_INTERNAL_H
28 #define LIBWPD_INTERNAL_H
29
30 #include <librevenge/librevenge.h>
31 #include <librevenge-stream/librevenge-stream.h>
32 #include "WPXEncryption.h"
33
34 /* Various functions/defines that need not/should not be exported externally */
35
36 #if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
37 #define WPD_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
38 #else
39 #define WPD_ATTRIBUTE_PRINTF(fmt, arg)
40 #endif
41
42 #ifdef DEBUG
43 namespace libwpd
44 {
45 void debugPrint(const char *format, ...) WPD_ATTRIBUTE_PRINTF(1, 2);
46 }
47
48 #define WPD_DEBUG_MSG(M) libwpd::debugPrint M
49 #else
50 #define WPD_DEBUG_MSG(M)
51 #endif
52
53 #define WPD_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
54
55 namespace libwpd
56 {
57 struct WPXDummyDeleter
58 {
59 void operator()(void *) {}
60 };
61 }
62
63 // add more of these as needed for byteswapping
64 // (the 8-bit functions are just there to make things consistent)
65 unsigned char readU8(librevenge::RVNGInputStream *input, WPXEncryption *encryption);
66 unsigned short readU16(librevenge::RVNGInputStream *input, WPXEncryption *encryption, bool bigendian=false);
67 signed short readS16(librevenge::RVNGInputStream *input, WPXEncryption *encryption, bool bigendian=false);
68 unsigned readU32(librevenge::RVNGInputStream *input, WPXEncryption *encryption, bool bigendian=false);
69
70 librevenge::RVNGString readPascalString(librevenge::RVNGInputStream *input, WPXEncryption *encryption);
71 librevenge::RVNGString readCString(librevenge::RVNGInputStream *input, WPXEncryption *encryption);
72
73 void appendUCS4(librevenge::RVNGString &str, unsigned ucs4);
74
75 // Various helper structures for the libwpd parser..
76
77 int extendedCharacterWP6ToUCS4(unsigned char character, unsigned char characterSet,
78 const unsigned **chars);
79
80 int extendedCharacterWP5ToUCS4(unsigned char character, unsigned char characterSet,
81 const unsigned **chars);
82
83 int appleWorldScriptToUCS4(unsigned short character, const unsigned **chars);
84
85 int extendedCharacterWP42ToUCS4(unsigned char character, const unsigned **chars);
86
87 unsigned short fixedPointToWPUs(const unsigned fixedPointNumber);
88 double fixedPointToDouble(const unsigned fixedPointNumber);
89 double wpuToFontPointSize(const unsigned short wpuNumber);
90
91 enum WPXFileType { WP6_DOCUMENT, WP5_DOCUMENT, WP42_DOCUMENT, OTHER };
92 enum WPXNumberingType { ARABIC, LOWERCASE, UPPERCASE, LOWERCASE_ROMAN, UPPERCASE_ROMAN };
93 enum WPXNoteType { FOOTNOTE, ENDNOTE };
94 enum WPXHeaderFooterType { HEADER, FOOTER };
95 enum WPXHeaderFooterInternalType { HEADER_A, HEADER_B, FOOTER_A, FOOTER_B, DUMMY };
96 enum WPXHeaderFooterOccurrence { ODD, EVEN, ALL, NEVER };
97 enum WPXPageNumberPosition { PAGENUMBER_POSITION_NONE = 0, PAGENUMBER_POSITION_TOP_LEFT, PAGENUMBER_POSITION_TOP_CENTER,
98 PAGENUMBER_POSITION_TOP_RIGHT, PAGENUMBER_POSITION_TOP_LEFT_AND_RIGHT,
99 PAGENUMBER_POSITION_BOTTOM_LEFT, PAGENUMBER_POSITION_BOTTOM_CENTER,
100 PAGENUMBER_POSITION_BOTTOM_RIGHT, PAGENUMBER_POSITION_BOTTOM_LEFT_AND_RIGHT,
101 PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT,
102 PAGENUMBER_POSITION_BOTTOM_INSIDE_LEFT_AND_RIGHT
103 };
104
105 enum WPXFormOrientation { PORTRAIT, LANDSCAPE };
106 enum WPXTabAlignment { LEFT, RIGHT, CENTER, DECIMAL, BAR };
107 enum WPXVerticalAlignment { TOP, MIDDLE, BOTTOM, FULL };
108
109 enum WPXTextColumnType { NEWSPAPER, NEWSPAPER_VERTICAL_BALANCE, PARALLEL, PARALLEL_PROTECT };
110
111 enum WPXSubDocumentType { WPX_SUBDOCUMENT_NONE, WPX_SUBDOCUMENT_HEADER_FOOTER, WPX_SUBDOCUMENT_NOTE, WPX_SUBDOCUMENT_TEXT_BOX, WPX_SUBDOCUMENT_COMMENT_ANNOTATION };
112
113 // ATTRIBUTE bits
114 #define WPX_EXTRA_LARGE_BIT 1
115 #define WPX_VERY_LARGE_BIT 2
116 #define WPX_LARGE_BIT 4
117 #define WPX_SMALL_PRINT_BIT 8
118 #define WPX_FINE_PRINT_BIT 16
119 #define WPX_SUPERSCRIPT_BIT 32
120 #define WPX_SUBSCRIPT_BIT 64
121 #define WPX_OUTLINE_BIT 128
122 #define WPX_ITALICS_BIT 256
123 #define WPX_SHADOW_BIT 512
124 #define WPX_REDLINE_BIT 1024
125 #define WPX_DOUBLE_UNDERLINE_BIT 2048
126 #define WPX_BOLD_BIT 4096
127 #define WPX_STRIKEOUT_BIT 8192
128 #define WPX_UNDERLINE_BIT 16384
129 #define WPX_SMALL_CAPS_BIT 32768
130 #define WPX_BLINK_BIT 65536
131 #define WPX_REVERSEVIDEO_BIT 131072
132
133 // JUSTIFICATION bits.
134 #define WPX_PARAGRAPH_JUSTIFICATION_LEFT 0x00
135 #define WPX_PARAGRAPH_JUSTIFICATION_FULL 0x01
136 #define WPX_PARAGRAPH_JUSTIFICATION_CENTER 0x02
137 #define WPX_PARAGRAPH_JUSTIFICATION_RIGHT 0x03
138 #define WPX_PARAGRAPH_JUSTIFICATION_FULL_ALL_LINES 0x04
139 #define WPX_PARAGRAPH_JUSTIFICATION_DECIMAL_ALIGNED 0x05
140
141 // TABLE POSITION bits.
142 #define WPX_TABLE_POSITION_ALIGN_WITH_LEFT_MARGIN 0x00
143 #define WPX_TABLE_POSITION_ALIGN_WITH_RIGHT_MARGIN 0x01
144 #define WPX_TABLE_POSITION_CENTER_BETWEEN_MARGINS 0x02
145 #define WPX_TABLE_POSITION_FULL 0x03
146 #define WPX_TABLE_POSITION_ABSOLUTE_FROM_LEFT_MARGIN 0x04
147
148 // TABLE CELL BORDER bits
149 const unsigned char WPX_TABLE_CELL_LEFT_BORDER_OFF = 0x01;
150 const unsigned char WPX_TABLE_CELL_RIGHT_BORDER_OFF = 0x02;
151 const unsigned char WPX_TABLE_CELL_TOP_BORDER_OFF = 0x04;
152 const unsigned char WPX_TABLE_CELL_BOTTOM_BORDER_OFF = 0x08;
153
154 // BREAK bits
155 #define WPX_PAGE_BREAK 0x00
156 #define WPX_SOFT_PAGE_BREAK 0x01
157 #define WPX_COLUMN_BREAK 0x02
158
159 // Generic bits
160 #define WPX_LEFT 0x00
161 #define WPX_RIGHT 0x01
162 #define WPX_CENTER 0x02
163 #define WPX_TOP 0x03
164 #define WPX_BOTTOM 0x04
165
166 struct RGBSColor
167 {
168 RGBSColor(unsigned char r, unsigned char g, unsigned char b, unsigned char s);
169 RGBSColor(unsigned short red, unsigned short green, unsigned short blue); // Construct
170 // RBBSColor from double precision RGB color used by WP3.x for Mac
171 RGBSColor(); // initializes all values to 0
172 unsigned char m_r;
173 unsigned char m_g;
174 unsigned char m_b;
175 unsigned char m_s;
176 };
177
178 struct WPXColumnDefinition
179 {
180 WPXColumnDefinition(); // initializes all values to 0
181 double m_width;
182 double m_leftGutter;
183 double m_rightGutter;
184 };
185
186 struct WPXColumnProperties
187 {
188 WPXColumnProperties();
189 unsigned m_attributes;
190 unsigned char m_alignment;
191 };
192
193 struct WPXTabStop
194 {
195 WPXTabStop();
196 double m_position;
197 WPXTabAlignment m_alignment;
198 unsigned m_leaderCharacter;
199 unsigned char m_leaderNumSpaces;
200 };
201
202 // Various exceptions: libwpd does not propagate exceptions externally..
203
204 class VersionException
205 {
206 };
207
208 class FileException
209 {
210 };
211
212 class ParseException
213 {
214 };
215
216 class GenericException
217 {
218 };
219
220 class UnsupportedEncryptionException
221 {
222 };
223
224 class SupportedEncryptionException
225 {
226 };
227
228 class WrongPasswordException
229 {
230 };
231
232 // Various usefull, but cheesey functions
233
234 int _extractNumericValueFromRoman(const char romanChar);
235 int _extractDisplayReferenceNumberFromBuf(const librevenge::RVNGString &buf, const WPXNumberingType listType);
236 WPXNumberingType _extractWPXNumberingTypeFromBuf(const librevenge::RVNGString &buf, const WPXNumberingType putativeWPXNumberingType);
237 librevenge::RVNGString _numberingTypeToString(WPXNumberingType t);
238 extern const unsigned macRomanCharacterMap[];
239 librevenge::RVNGString doubleToString(const double value);
240
241 #endif /* LIBWPD_INTERNAL_H */
242 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPXNumberingType
WPXNumberingType
Definition: libwpd_internal.h:92
DUMMY
Definition: libwpd_internal.h:95
RGBSColor::m_g
unsigned char m_g
Definition: libwpd_internal.h:173
WPXTabStop::m_alignment
WPXTabAlignment m_alignment
Definition: libwpd_internal.h:197
PARALLEL_PROTECT
Definition: libwpd_internal.h:109
readU8
unsigned char readU8(librevenge::RVNGInputStream *input, WPXEncryption *encryption)
Definition: libwpd_internal.cpp:106
OTHER
Definition: libwpd_internal.h:91
PAGENUMBER_POSITION_TOP_RIGHT
Definition: libwpd_internal.h:98
WPXTabStop
Definition: libwpd_internal.h:193
PAGENUMBER_POSITION_NONE
Definition: libwpd_internal.h:97
PAGENUMBER_POSITION_BOTTOM_RIGHT
Definition: libwpd_internal.h:100
WPXColumnDefinition::m_width
double m_width
Definition: libwpd_internal.h:181
WPXEncryption.h
WPXHeaderFooterInternalType
WPXHeaderFooterInternalType
Definition: libwpd_internal.h:95
RGBSColor::m_r
unsigned char m_r
Definition: libwpd_internal.h:172
readU16
unsigned short readU16(librevenge::RVNGInputStream *input, WPXEncryption *encryption, bool bigendian=false)
Definition: libwpd_internal.cpp:119
extendedCharacterWP5ToUCS4
int extendedCharacterWP5ToUCS4(unsigned char character, unsigned char characterSet, const unsigned **chars)
Definition: libwpd_internal.cpp:1018
WPXColumnProperties::WPXColumnProperties
WPXColumnProperties()
Definition: libwpd_internal.cpp:1223
NEVER
Definition: libwpd_internal.h:96
FOOTER_A
Definition: libwpd_internal.h:95
readCString
librevenge::RVNGString readCString(librevenge::RVNGInputStream *input, WPXEncryption *encryption)
Definition: libwpd_internal.cpp:184
WPXTextColumnType
WPXTextColumnType
Definition: libwpd_internal.h:109
WPX_TABLE_CELL_BOTTOM_BORDER_OFF
const unsigned char WPX_TABLE_CELL_BOTTOM_BORDER_OFF
Definition: libwpd_internal.h:152
NEWSPAPER_VERTICAL_BALANCE
Definition: libwpd_internal.h:109
WPD_ATTRIBUTE_PRINTF
#define WPD_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libwpd_internal.h:39
ENDNOTE
Definition: libwpd_internal.h:93
WPXHeaderFooterOccurrence
WPXHeaderFooterOccurrence
Definition: libwpd_internal.h:96
_numberingTypeToString
librevenge::RVNGString _numberingTypeToString(WPXNumberingType t)
Definition: libwpd_internal.cpp:1323
HEADER
Definition: libwpd_internal.h:94
SupportedEncryptionException
Definition: libwpd_internal.h:224
PAGENUMBER_POSITION_BOTTOM_INSIDE_LEFT_AND_RIGHT
Definition: libwpd_internal.h:102
RIGHT
Definition: libwpd_internal.h:106
WPXFileType
WPXFileType
Definition: libwpd_internal.h:91
appleWorldScriptToUCS4
int appleWorldScriptToUCS4(unsigned short character, const unsigned **chars)
Definition: libwpd_internal.cpp:1409
WPXSubDocumentType
WPXSubDocumentType
Definition: libwpd_internal.h:111
wpuToFontPointSize
double wpuToFontPointSize(const unsigned short wpuNumber)
Definition: libwpd_internal.cpp:1179
PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT
Definition: libwpd_internal.h:101
WP6_DOCUMENT
Definition: libwpd_internal.h:91
WPXTabAlignment
WPXTabAlignment
Definition: libwpd_internal.h:106
HEADER_B
Definition: libwpd_internal.h:95
WPX_SUBDOCUMENT_NOTE
Definition: libwpd_internal.h:111
fixedPointToWPUs
unsigned short fixedPointToWPUs(const unsigned fixedPointNumber)
Definition: libwpd_internal.cpp:1164
WPXColumnDefinition::WPXColumnDefinition
WPXColumnDefinition()
Definition: libwpd_internal.cpp:1216
_extractNumericValueFromRoman
int _extractNumericValueFromRoman(const char romanChar)
Definition: libwpd_internal.cpp:1230
RGBSColor::m_s
unsigned char m_s
Definition: libwpd_internal.h:175
WrongPasswordException
Definition: libwpd_internal.h:228
ALL
Definition: libwpd_internal.h:96
LOWERCASE_ROMAN
Definition: libwpd_internal.h:92
PAGENUMBER_POSITION_BOTTOM_CENTER
Definition: libwpd_internal.h:99
LOWERCASE
Definition: libwpd_internal.h:92
PORTRAIT
Definition: libwpd_internal.h:105
readS16
signed short readS16(librevenge::RVNGInputStream *input, WPXEncryption *encryption, bool bigendian=false)
Definition: libwpd_internal.cpp:134
FileException
Definition: libwpd_internal.h:208
LEFT
Definition: libwpd_internal.h:106
WPXColumnProperties::m_attributes
unsigned m_attributes
Definition: libwpd_internal.h:189
extendedCharacterWP6ToUCS4
int extendedCharacterWP6ToUCS4(unsigned char character, unsigned char characterSet, const unsigned **chars)
Definition: libwpd_internal.cpp:660
WPX_SUBDOCUMENT_HEADER_FOOTER
Definition: libwpd_internal.h:111
EVEN
Definition: libwpd_internal.h:96
ARABIC
Definition: libwpd_internal.h:92
ParseException
Definition: libwpd_internal.h:212
UPPERCASE
Definition: libwpd_internal.h:92
UnsupportedEncryptionException
Definition: libwpd_internal.h:220
WPXTabStop::m_leaderCharacter
unsigned m_leaderCharacter
Definition: libwpd_internal.h:198
LANDSCAPE
Definition: libwpd_internal.h:105
BOTTOM
Definition: libwpd_internal.h:107
_extractDisplayReferenceNumberFromBuf
int _extractDisplayReferenceNumberFromBuf(const librevenge::RVNGString &buf, const WPXNumberingType listType)
Definition: libwpd_internal.cpp:1257
doubleToString
librevenge::RVNGString doubleToString(const double value)
Definition: libwpd_internal.cpp:1385
WPXColumnProperties
Definition: libwpd_internal.h:186
WPXFormOrientation
WPXFormOrientation
Definition: libwpd_internal.h:105
PAGENUMBER_POSITION_TOP_LEFT_AND_RIGHT
Definition: libwpd_internal.h:98
PAGENUMBER_POSITION_TOP_CENTER
Definition: libwpd_internal.h:97
MIDDLE
Definition: libwpd_internal.h:107
macRomanCharacterMap
const unsigned macRomanCharacterMap[]
Definition: libwpd_internal.cpp:1353
UPPERCASE_ROMAN
Definition: libwpd_internal.h:92
libwpd::WPXDummyDeleter
Definition: libwpd_internal.h:57
RGBSColor::RGBSColor
RGBSColor()
Definition: libwpd_internal.cpp:1192
libwpd::WPXDummyDeleter::operator()
void operator()(void *)
Definition: libwpd_internal.h:59
NEWSPAPER
Definition: libwpd_internal.h:109
WPX_TABLE_CELL_TOP_BORDER_OFF
const unsigned char WPX_TABLE_CELL_TOP_BORDER_OFF
Definition: libwpd_internal.h:151
fixedPointToDouble
double fixedPointToDouble(const unsigned fixedPointNumber)
Definition: libwpd_internal.cpp:1172
WPXVerticalAlignment
WPXVerticalAlignment
Definition: libwpd_internal.h:107
BAR
Definition: libwpd_internal.h:106
WPXColumnDefinition
Definition: libwpd_internal.h:178
WPXColumnDefinition::m_leftGutter
double m_leftGutter
Definition: libwpd_internal.h:182
PAGENUMBER_POSITION_BOTTOM_LEFT_AND_RIGHT
Definition: libwpd_internal.h:100
RGBSColor::m_b
unsigned char m_b
Definition: libwpd_internal.h:174
WPXColumnDefinition::m_rightGutter
double m_rightGutter
Definition: libwpd_internal.h:183
DECIMAL
Definition: libwpd_internal.h:106
WPX_SUBDOCUMENT_TEXT_BOX
Definition: libwpd_internal.h:111
WPXTabStop::m_leaderNumSpaces
unsigned char m_leaderNumSpaces
Definition: libwpd_internal.h:199
CENTER
Definition: libwpd_internal.h:106
WPXEncryption
Definition: WPXEncryption.h:35
PAGENUMBER_POSITION_BOTTOM_LEFT
Definition: libwpd_internal.h:99
WPXColumnProperties::m_alignment
unsigned char m_alignment
Definition: libwpd_internal.h:190
RGBSColor
Definition: libwpd_internal.h:166
WPXTabStop::WPXTabStop
WPXTabStop()
Definition: libwpd_internal.cpp:1208
ODD
Definition: libwpd_internal.h:96
GenericException
Definition: libwpd_internal.h:216
WP42_DOCUMENT
Definition: libwpd_internal.h:91
WPXPageNumberPosition
WPXPageNumberPosition
Definition: libwpd_internal.h:97
WP5_DOCUMENT
Definition: libwpd_internal.h:91
PAGENUMBER_POSITION_TOP_LEFT
Definition: libwpd_internal.h:97
appendUCS4
void appendUCS4(librevenge::RVNGString &str, unsigned ucs4)
Definition: libwpd_internal.cpp:154
WPXTabStop::m_position
double m_position
Definition: libwpd_internal.h:196
libwpd
Definition: libwpd_internal.h:55
readU32
unsigned readU32(librevenge::RVNGInputStream *input, WPXEncryption *encryption, bool bigendian=false)
Definition: libwpd_internal.cpp:139
TOP
Definition: libwpd_internal.h:107
WPX_TABLE_CELL_RIGHT_BORDER_OFF
const unsigned char WPX_TABLE_CELL_RIGHT_BORDER_OFF
Definition: libwpd_internal.h:150
FOOTNOTE
Definition: libwpd_internal.h:93
VersionException
Definition: libwpd_internal.h:204
HEADER_A
Definition: libwpd_internal.h:95
WPX_TABLE_CELL_LEFT_BORDER_OFF
const unsigned char WPX_TABLE_CELL_LEFT_BORDER_OFF
Definition: libwpd_internal.h:149
WPXHeaderFooterType
WPXHeaderFooterType
Definition: libwpd_internal.h:94
readPascalString
librevenge::RVNGString readPascalString(librevenge::RVNGInputStream *input, WPXEncryption *encryption)
Definition: libwpd_internal.cpp:163
PARALLEL
Definition: libwpd_internal.h:109
extendedCharacterWP42ToUCS4
int extendedCharacterWP42ToUCS4(unsigned char character, const unsigned **chars)
Definition: libwpd_internal.cpp:1151
FOOTER_B
Definition: libwpd_internal.h:95
_extractWPXNumberingTypeFromBuf
WPXNumberingType _extractWPXNumberingTypeFromBuf(const librevenge::RVNGString &buf, const WPXNumberingType putativeWPXNumberingType)
Definition: libwpd_internal.cpp:1303
FULL
Definition: libwpd_internal.h:107
WPX_SUBDOCUMENT_COMMENT_ANNOTATION
Definition: libwpd_internal.h:111
WPXNoteType
WPXNoteType
Definition: libwpd_internal.h:93
FOOTER
Definition: libwpd_internal.h:94
WPX_SUBDOCUMENT_NONE
Definition: libwpd_internal.h:111