00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef LIBWPD_INTERNAL_H
00028 #define LIBWPD_INTERNAL_H
00029 #include "WPXStream.h"
00030 #include <stdio.h>
00031 #include <string>
00032 #include <algorithm>
00033 #include "WPXString.h"
00034 #include "WPXEncryption.h"
00035 #include "libwpd_types.h"
00036
00037
00038
00039 #ifdef _MSC_VER
00040 #include <minmax.h>
00041 #define LIBWPD_MIN min
00042 #define LIBWPD_MAX max
00043 #else
00044 #define LIBWPD_MIN std::min
00045 #define LIBWPD_MAX std::max
00046 #endif
00047
00048 #define WPD_CHECK_FILE_ERROR(v) if (v==EOF) { WPD_DEBUG_MSG(("X_CheckFileError: %d\n", __LINE__)); throw FileException(); }
00049 #define WPD_CHECK_FILE_SEEK_ERROR(v) if (v) { WPD_DEBUG_MSG(("X_CheckFileSeekError: %d\n", __LINE__)); throw FileException(); }
00050 #define WPD_CHECK_FILE_READ_ERROR(v,num_elements) if (v != num_elements) {\
00051 WPD_DEBUG_MSG(("X_CheckFileReadElementError: %d\n", __LINE__)); throw FileException(); }
00052
00053 #define DELETEP(m) if (m) { delete m; m = 0; }
00054
00055 #ifdef DEBUG
00056 #define WPD_DEBUG_MSG(M) printf M
00057 #else
00058 #define WPD_DEBUG_MSG(M)
00059 #endif
00060
00061 #define WPD_LE_GET_GUINT8(p) (*(uint8_t const *)(p))
00062 #define WPD_LE_GET_GUINT16(p) \
00063 (uint16_t)((((uint8_t const *)(p))[0] << 0) | \
00064 (((uint8_t const *)(p))[1] << 8))
00065 #define WPD_LE_GET_GUINT32(p) \
00066 (uint32_t)((((uint8_t const *)(p))[0] << 0) | \
00067 (((uint8_t const *)(p))[1] << 8) | \
00068 (((uint8_t const *)(p))[2] << 16) | \
00069 (((uint8_t const *)(p))[3] << 24))
00070
00071 #define WPD_BE_GET_GUINT8(p) (*(uint8_t const *)(p))
00072 #define WPD_BE_GET_GUINT16(p) \
00073 (uint16_t)((((uint8_t const *)(p))[1] << 0) | \
00074 (((uint8_t const *)(p))[0] << 8))
00075 #define WPD_BE_GET_GUINT32(p) \
00076 (uint32_t)((((uint8_t const *)(p))[3] << 0) | \
00077 (((uint8_t const *)(p))[2] << 8) | \
00078 (((uint8_t const *)(p))[1] << 16) | \
00079 (((uint8_t const *)(p))[0] << 24))
00080
00081 #define WPD_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
00082
00083
00084
00085 uint8_t readU8(WPXInputStream *input, WPXEncryption *encryption);
00086 uint16_t readU16(WPXInputStream *input, WPXEncryption *encryption, bool bigendian=false);
00087 uint32_t readU32(WPXInputStream *input, WPXEncryption *encryption, bool bigendian=false);
00088
00089 WPXString readPascalString(WPXInputStream *input, WPXEncryption *encryption);
00090 WPXString readCString(WPXInputStream *input, WPXEncryption *encryption);
00091
00092 void appendUCS4(WPXString &str, uint32_t ucs4);
00093
00094
00095
00096 int extendedCharacterWP6ToUCS4(uint8_t character, uint8_t characterSet,
00097 const uint32_t **chars);
00098
00099 int extendedCharacterWP5ToUCS4(uint8_t character, uint8_t characterSet,
00100 const uint32_t **chars);
00101
00102 int appleWorldScriptToUCS4(uint16_t character, const uint32_t **chars);
00103
00104 int extendedCharacterWP42ToUCS4(uint8_t character, const uint32_t **chars);
00105
00106 uint16_t fixedPointToWPUs(const uint32_t fixedPointNumber);
00107 double fixedPointToDouble(const uint32_t fixedPointNumber);
00108 double wpuToFontPointSize(const uint16_t wpuNumber);
00109
00110 enum WPXFileType { WP6_DOCUMENT, WP5_DOCUMENT, WP42_DOCUMENT, OTHER };
00111 enum WPXNumberingType { ARABIC, LOWERCASE, UPPERCASE, LOWERCASE_ROMAN, UPPERCASE_ROMAN };
00112 enum WPXNoteType { FOOTNOTE, ENDNOTE };
00113 enum WPXHeaderFooterType { HEADER, FOOTER };
00114 enum WPXHeaderFooterInternalType { HEADER_A, HEADER_B, FOOTER_A, FOOTER_B, DUMMY };
00115 enum WPXHeaderFooterOccurence { ODD, EVEN, ALL, NEVER };
00116 enum WPXPageNumberPosition { PAGENUMBER_POSITION_NONE = 0, PAGENUMBER_POSITION_TOP_LEFT, PAGENUMBER_POSITION_TOP_CENTER,
00117 PAGENUMBER_POSITION_TOP_RIGHT, PAGENUMBER_POSITION_TOP_LEFT_AND_RIGHT,
00118 PAGENUMBER_POSITION_BOTTOM_LEFT, PAGENUMBER_POSITION_BOTTOM_CENTER,
00119 PAGENUMBER_POSITION_BOTTOM_RIGHT, PAGENUMBER_POSITION_BOTTOM_LEFT_AND_RIGHT,
00120 PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT,
00121 PAGENUMBER_POSITION_BOTTOM_INSIDE_LEFT_AND_RIGHT
00122 };
00123
00124 enum WPXFormOrientation { PORTRAIT, LANDSCAPE };
00125 enum WPXTabAlignment { LEFT, RIGHT, CENTER, DECIMAL, BAR };
00126 enum WPXVerticalAlignment { TOP, MIDDLE, BOTTOM, FULL };
00127
00128 enum WPXTextColumnType { NEWSPAPER, NEWSPAPER_VERTICAL_BALANCE, PARALLEL, PARALLEL_PROTECT };
00129
00130 enum WPXSubDocumentType { WPX_SUBDOCUMENT_NONE, WPX_SUBDOCUMENT_HEADER_FOOTER, WPX_SUBDOCUMENT_NOTE, WPX_SUBDOCUMENT_TEXT_BOX, WPX_SUBDOCUMENT_COMMENT_ANNOTATION };
00131
00132
00133 #define WPX_EXTRA_LARGE_BIT 1
00134 #define WPX_VERY_LARGE_BIT 2
00135 #define WPX_LARGE_BIT 4
00136 #define WPX_SMALL_PRINT_BIT 8
00137 #define WPX_FINE_PRINT_BIT 16
00138 #define WPX_SUPERSCRIPT_BIT 32
00139 #define WPX_SUBSCRIPT_BIT 64
00140 #define WPX_OUTLINE_BIT 128
00141 #define WPX_ITALICS_BIT 256
00142 #define WPX_SHADOW_BIT 512
00143 #define WPX_REDLINE_BIT 1024
00144 #define WPX_DOUBLE_UNDERLINE_BIT 2048
00145 #define WPX_BOLD_BIT 4096
00146 #define WPX_STRIKEOUT_BIT 8192
00147 #define WPX_UNDERLINE_BIT 16384
00148 #define WPX_SMALL_CAPS_BIT 32768
00149 #define WPX_BLINK_BIT 65536
00150 #define WPX_REVERSEVIDEO_BIT 131072
00151
00152
00153 #define WPX_PARAGRAPH_JUSTIFICATION_LEFT 0x00
00154 #define WPX_PARAGRAPH_JUSTIFICATION_FULL 0x01
00155 #define WPX_PARAGRAPH_JUSTIFICATION_CENTER 0x02
00156 #define WPX_PARAGRAPH_JUSTIFICATION_RIGHT 0x03
00157 #define WPX_PARAGRAPH_JUSTIFICATION_FULL_ALL_LINES 0x04
00158 #define WPX_PARAGRAPH_JUSTIFICATION_DECIMAL_ALIGNED 0x05
00159
00160
00161 #define WPX_TABLE_POSITION_ALIGN_WITH_LEFT_MARGIN 0x00
00162 #define WPX_TABLE_POSITION_ALIGN_WITH_RIGHT_MARGIN 0x01
00163 #define WPX_TABLE_POSITION_CENTER_BETWEEN_MARGINS 0x02
00164 #define WPX_TABLE_POSITION_FULL 0x03
00165 #define WPX_TABLE_POSITION_ABSOLUTE_FROM_LEFT_MARGIN 0x04
00166
00167
00168 const uint8_t WPX_TABLE_CELL_LEFT_BORDER_OFF = 0x01;
00169 const uint8_t WPX_TABLE_CELL_RIGHT_BORDER_OFF = 0x02;
00170 const uint8_t WPX_TABLE_CELL_TOP_BORDER_OFF = 0x04;
00171 const uint8_t WPX_TABLE_CELL_BOTTOM_BORDER_OFF = 0x08;
00172
00173
00174 #define WPX_PAGE_BREAK 0x00
00175 #define WPX_SOFT_PAGE_BREAK 0x01
00176 #define WPX_COLUMN_BREAK 0x02
00177
00178
00179 #define WPX_LEFT 0x00
00180 #define WPX_RIGHT 0x01
00181 #define WPX_CENTER 0x02
00182 #define WPX_TOP 0x03
00183 #define WPX_BOTTOM 0x04
00184
00185 typedef struct _RGBSColor RGBSColor;
00186 struct _RGBSColor
00187 {
00188 _RGBSColor(uint8_t r, uint8_t g, uint8_t b, uint8_t s);
00189 _RGBSColor(uint16_t red, uint16_t green, uint16_t blue);
00190
00191 _RGBSColor();
00192 uint8_t m_r;
00193 uint8_t m_g;
00194 uint8_t m_b;
00195 uint8_t m_s;
00196 };
00197
00198 typedef struct _WPXColumnDefinition WPXColumnDefinition;
00199 struct _WPXColumnDefinition
00200 {
00201 _WPXColumnDefinition();
00202 double m_width;
00203 double m_leftGutter;
00204 double m_rightGutter;
00205 };
00206
00207 typedef struct _WPXColumnProperties WPXColumnProperties;
00208 struct _WPXColumnProperties
00209 {
00210 _WPXColumnProperties();
00211 uint32_t m_attributes;
00212 uint8_t m_alignment;
00213 };
00214
00215 typedef struct _WPXTabStop WPXTabStop;
00216 struct _WPXTabStop
00217 {
00218 _WPXTabStop(double position, WPXTabAlignment alignment, uint16_t leaderCharacter, uint8_t leaderNumSpaces);
00219 _WPXTabStop();
00220 double m_position;
00221 WPXTabAlignment m_alignment;
00222 uint16_t m_leaderCharacter;
00223 uint8_t m_leaderNumSpaces;
00224 };
00225
00226
00227
00228 class VersionException
00229 {
00230 };
00231
00232 class FileException
00233 {
00234 };
00235
00236 class ParseException
00237 {
00238 };
00239
00240 class GenericException
00241 {
00242 };
00243
00244 class UnsupportedEncryptionException
00245 {
00246 };
00247
00248 class SupportedEncryptionException
00249 {
00250 };
00251
00252 class WrongPasswordException
00253 {
00254 };
00255
00256
00257
00258 int _extractNumericValueFromRoman(const char romanChar);
00259 int _extractDisplayReferenceNumberFromBuf(const WPXString &buf, const WPXNumberingType listType);
00260 WPXNumberingType _extractWPXNumberingTypeFromBuf(const WPXString &buf, const WPXNumberingType putativeWPXNumberingType);
00261 WPXString _numberingTypeToString(WPXNumberingType t);
00262 extern const uint32_t macRomanCharacterMap[];
00263 WPXString doubleToString(const double value);
00264
00265 #endif
00266