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