- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 <stdio.h>
31 #include <string>
32 #include <algorithm>
33 #include <librevenge/librevenge.h>
34 #include <librevenge-stream/librevenge-stream.h>
35 #include <libwpd/libwpd.h>
36 #include "WPXEncryption.h"
37
38 /* Various functions/defines that need not/should not be exported externally */
39
40 #ifdef _MSC_VER
41 #include <minmax.h>
42 #define LIBWPD_MIN min
43 #define LIBWPD_MAX max
44 #else
45 #define LIBWPD_MIN std::min
46 #define LIBWPD_MAX std::max
47 #endif
48
49 #define WPD_CHECK_FILE_ERROR(v) if (v==EOF) { WPD_DEBUG_MSG(("X_CheckFileError: %d\n", __LINE__)); throw FileException(); }
50 #define WPD_CHECK_FILE_SEEK_ERROR(v) if (v) { WPD_DEBUG_MSG(("X_CheckFileSeekError: %d\n", __LINE__)); throw FileException(); }
51 #define WPD_CHECK_FILE_READ_ERROR(v,num_elements) if (v != num_elements) { WPD_DEBUG_MSG(("X_CheckFileReadElementError: %d\n", __LINE__)); throw FileException(); }
52
53 #define DELETEP(m) if (m) { delete m; m = 0; }
54
55 #ifdef DEBUG
56 #define WPD_DEBUG_MSG(M) printf M
57 #else
58 #define WPD_DEBUG_MSG(M)
59 #endif
60
61 #define WPD_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
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 typedef struct _RGBSColor RGBSColor;
167 struct _RGBSColor
168 {
169 _RGBSColor(unsigned char r, unsigned char g, unsigned char b, unsigned char s);
170 _RGBSColor(unsigned short red, unsigned short green, unsigned short blue); // Construct
171 // RBBSColor from double precision RGB color used by WP3.x for Mac
172 _RGBSColor(); // initializes all values to 0
173 unsigned char m_r;
174 unsigned char m_g;
175 unsigned char m_b;
176 unsigned char m_s;
177 };
178
179 typedef struct _WPXColumnDefinition WPXColumnDefinition;
180 struct _WPXColumnDefinition
181 {
182 _WPXColumnDefinition(); // initializes all values to 0
183 double m_width;
184 double m_leftGutter;
185 double m_rightGutter;
186 };
187
188 typedef struct _WPXColumnProperties WPXColumnProperties;
189 struct _WPXColumnProperties
190 {
191 _WPXColumnProperties();
192 unsigned m_attributes;
193 unsigned char m_alignment;
194 };
195
196 typedef struct _WPXTabStop WPXTabStop;
197 struct _WPXTabStop
198 {
199 _WPXTabStop();
200 double m_position;
201 WPXTabAlignment m_alignment;
202 unsigned m_leaderCharacter;
203 unsigned char m_leaderNumSpaces;
204 };
205
206 // Various exceptions: libwpd does not propagate exceptions externally..
207
208 class VersionException
209 {
210 };
211
212 class FileException
213 {
214 };
215
216 class ParseException
217 {
218 };
219
220 class GenericException
221 {
222 };
223
224 class UnsupportedEncryptionException
225 {
226 };
227
228 class SupportedEncryptionException
229 {
230 };
231
232 class WrongPasswordException
233 {
234 };
235
236 // Various usefull, but cheesey functions
237
238 int _extractNumericValueFromRoman(const char romanChar);
239 int _extractDisplayReferenceNumberFromBuf(const librevenge::RVNGString &buf, const WPXNumberingType listType);
240 WPXNumberingType _extractWPXNumberingTypeFromBuf(const librevenge::RVNGString &buf, const WPXNumberingType putativeWPXNumberingType);
241 librevenge::RVNGString _numberingTypeToString(WPXNumberingType t);
242 extern const unsigned macRomanCharacterMap[];
243 librevenge::RVNGString doubleToString(const double value);
244
245 #endif /* LIBWPD_INTERNAL_H */
246 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPXNumberingType
WPXNumberingType
Definition: libwpd_internal.h:92
DUMMY
Definition: libwpd_internal.h:95
_WPXColumnDefinition::m_leftGutter
double m_leftGutter
Definition: libwpd_internal.h:184
PARALLEL_PROTECT
Definition: libwpd_internal.h:109
readU8
unsigned char readU8(librevenge::RVNGInputStream *input, WPXEncryption *encryption)
Definition: libwpd_internal.cpp:86
OTHER
Definition: libwpd_internal.h:91
PAGENUMBER_POSITION_TOP_RIGHT
Definition: libwpd_internal.h:98
PAGENUMBER_POSITION_NONE
Definition: libwpd_internal.h:97
_WPXTabStop::m_leaderCharacter
unsigned m_leaderCharacter
Definition: libwpd_internal.h:202
PAGENUMBER_POSITION_BOTTOM_RIGHT
Definition: libwpd_internal.h:100
WPXEncryption.h
WPXHeaderFooterInternalType
WPXHeaderFooterInternalType
Definition: libwpd_internal.h:95
readU16
unsigned short readU16(librevenge::RVNGInputStream *input, WPXEncryption *encryption, bool bigendian=false)
Definition: libwpd_internal.cpp:99
extendedCharacterWP5ToUCS4
int extendedCharacterWP5ToUCS4(unsigned char character, unsigned char characterSet, const unsigned **chars)
Definition: libwpd_internal.cpp:1000
NEVER
Definition: libwpd_internal.h:96
FOOTER_A
Definition: libwpd_internal.h:95
_WPXColumnProperties::m_alignment
unsigned char m_alignment
Definition: libwpd_internal.h:193
readCString
librevenge::RVNGString readCString(librevenge::RVNGInputStream *input, WPXEncryption *encryption)
Definition: libwpd_internal.cpp:166
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
_WPXTabStop::m_position
double m_position
Definition: libwpd_internal.h:200
_RGBSColor::m_g
unsigned char m_g
Definition: libwpd_internal.h:174
_WPXColumnDefinition::m_rightGutter
double m_rightGutter
Definition: libwpd_internal.h:185
ENDNOTE
Definition: libwpd_internal.h:93
WPXHeaderFooterOccurrence
WPXHeaderFooterOccurrence
Definition: libwpd_internal.h:96
_RGBSColor::_RGBSColor
_RGBSColor()
Definition: libwpd_internal.cpp:1174
_numberingTypeToString
librevenge::RVNGString _numberingTypeToString(WPXNumberingType t)
Definition: libwpd_internal.cpp:1305
HEADER
Definition: libwpd_internal.h:94
SupportedEncryptionException
Definition: libwpd_internal.h:228
_WPXColumnDefinition::_WPXColumnDefinition
_WPXColumnDefinition()
Definition: libwpd_internal.cpp:1198
_WPXTabStop::m_alignment
WPXTabAlignment m_alignment
Definition: libwpd_internal.h:201
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:1391
libwpd.h
WPXSubDocumentType
WPXSubDocumentType
Definition: libwpd_internal.h:111
wpuToFontPointSize
double wpuToFontPointSize(const unsigned short wpuNumber)
Definition: libwpd_internal.cpp:1161
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
_RGBSColor
Definition: libwpd_internal.h:167
WPX_SUBDOCUMENT_NOTE
Definition: libwpd_internal.h:111
fixedPointToWPUs
unsigned short fixedPointToWPUs(const unsigned fixedPointNumber)
Definition: libwpd_internal.cpp:1146
_WPXTabStop::_WPXTabStop
_WPXTabStop()
Definition: libwpd_internal.cpp:1190
_extractNumericValueFromRoman
int _extractNumericValueFromRoman(const char romanChar)
Definition: libwpd_internal.cpp:1212
WrongPasswordException
Definition: libwpd_internal.h:232
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:114
FileException
Definition: libwpd_internal.h:212
LEFT
Definition: libwpd_internal.h:106
_WPXTabStop
Definition: libwpd_internal.h:197
extendedCharacterWP6ToUCS4
int extendedCharacterWP6ToUCS4(unsigned char character, unsigned char characterSet, const unsigned **chars)
Definition: libwpd_internal.cpp:642
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:216
UPPERCASE
Definition: libwpd_internal.h:92
UnsupportedEncryptionException
Definition: libwpd_internal.h:224
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:1239
doubleToString
librevenge::RVNGString doubleToString(const double value)
Definition: libwpd_internal.cpp:1367
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
_RGBSColor::m_r
unsigned char m_r
Definition: libwpd_internal.h:173
MIDDLE
Definition: libwpd_internal.h:107
macRomanCharacterMap
const unsigned macRomanCharacterMap[]
Definition: libwpd_internal.cpp:1335
_WPXColumnDefinition::m_width
double m_width
Definition: libwpd_internal.h:183
UPPERCASE_ROMAN
Definition: libwpd_internal.h:92
_WPXTabStop::m_leaderNumSpaces
unsigned char m_leaderNumSpaces
Definition: libwpd_internal.h:203
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:1154
WPXVerticalAlignment
WPXVerticalAlignment
Definition: libwpd_internal.h:107
BAR
Definition: libwpd_internal.h:106
PAGENUMBER_POSITION_BOTTOM_LEFT_AND_RIGHT
Definition: libwpd_internal.h:100
DECIMAL
Definition: libwpd_internal.h:106
WPX_SUBDOCUMENT_TEXT_BOX
Definition: libwpd_internal.h:111
CENTER
Definition: libwpd_internal.h:106
WPXEncryption
Definition: WPXEncryption.h:33
_WPXColumnProperties::m_attributes
unsigned m_attributes
Definition: libwpd_internal.h:192
PAGENUMBER_POSITION_BOTTOM_LEFT
Definition: libwpd_internal.h:99
ODD
Definition: libwpd_internal.h:96
GenericException
Definition: libwpd_internal.h:220
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:134
readU32
unsigned readU32(librevenge::RVNGInputStream *input, WPXEncryption *encryption, bool bigendian=false)
Definition: libwpd_internal.cpp:119
TOP
Definition: libwpd_internal.h:107
_RGBSColor::m_b
unsigned char m_b
Definition: libwpd_internal.h:175
WPX_TABLE_CELL_RIGHT_BORDER_OFF
const unsigned char WPX_TABLE_CELL_RIGHT_BORDER_OFF
Definition: libwpd_internal.h:150
_RGBSColor::m_s
unsigned char m_s
Definition: libwpd_internal.h:176
FOOTNOTE
Definition: libwpd_internal.h:93
VersionException
Definition: libwpd_internal.h:208
HEADER_A
Definition: libwpd_internal.h:95
_WPXColumnProperties::_WPXColumnProperties
_WPXColumnProperties()
Definition: libwpd_internal.cpp:1205
WPX_TABLE_CELL_LEFT_BORDER_OFF
const unsigned char WPX_TABLE_CELL_LEFT_BORDER_OFF
Definition: libwpd_internal.h:149
_WPXColumnDefinition
Definition: libwpd_internal.h:180
WPXHeaderFooterType
WPXHeaderFooterType
Definition: libwpd_internal.h:94
readPascalString
librevenge::RVNGString readPascalString(librevenge::RVNGInputStream *input, WPXEncryption *encryption)
Definition: libwpd_internal.cpp:145
PARALLEL
Definition: libwpd_internal.h:109
extendedCharacterWP42ToUCS4
int extendedCharacterWP42ToUCS4(unsigned char character, const unsigned **chars)
Definition: libwpd_internal.cpp:1133
FOOTER_B
Definition: libwpd_internal.h:95
_extractWPXNumberingTypeFromBuf
WPXNumberingType _extractWPXNumberingTypeFromBuf(const librevenge::RVNGString &buf, const WPXNumberingType putativeWPXNumberingType)
Definition: libwpd_internal.cpp:1285
FULL
Definition: libwpd_internal.h:107
WPX_SUBDOCUMENT_COMMENT_ANNOTATION
Definition: libwpd_internal.h:111
_WPXColumnProperties
Definition: libwpd_internal.h:189
WPXNoteType
WPXNoteType
Definition: libwpd_internal.h:93
FOOTER
Definition: libwpd_internal.h:94
WPX_SUBDOCUMENT_NONE
Definition: libwpd_internal.h:111