libwpd_internal.h

Go to the documentation of this file.
00001 /* libwpd
00002  * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00003  * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00004  *  
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00018  *
00019  * For further information visit http://libwpd.sourceforge.net
00020  */
00021 
00022 /* "This product is not manufactured, approved, or supported by 
00023  * Corel Corporation or Corel Corporation Limited."
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 #include "WPXEncryption.h"
00034 #include "libwpd_types.h"
00035 
00036 /* Various functions/defines that need not/should not be exported externally */
00037 
00038 #ifdef _MSC_VER
00039 #include <minmax.h>
00040 #define LIBWPD_MIN min
00041 #define LIBWPD_MAX max
00042 #else
00043 #define LIBWPD_MIN std::min
00044 #define LIBWPD_MAX std::max
00045 #endif
00046 
00047 #define WPD_CHECK_FILE_ERROR(v) if (v==EOF) { WPD_DEBUG_MSG(("X_CheckFileError: %d\n", __LINE__)); throw FileException(); }
00048 #define WPD_CHECK_FILE_SEEK_ERROR(v) if (v) { WPD_DEBUG_MSG(("X_CheckFileSeekError: %d\n", __LINE__)); throw FileException(); }
00049 #define WPD_CHECK_FILE_READ_ERROR(v,num_elements) if (v != num_elements) {\
00050  WPD_DEBUG_MSG(("X_CheckFileReadElementError: %d\n", __LINE__)); throw FileException(); }
00051 
00052 #define DELETEP(m) if (m) { delete m; m = 0; }
00053  
00054 #ifdef DEBUG
00055 #define WPD_DEBUG_MSG(M) printf M
00056 #else
00057 #define WPD_DEBUG_MSG(M)
00058 #endif
00059 
00060 #define WPD_LE_GET_GUINT8(p) (*(uint8_t const *)(p))
00061 #define WPD_LE_GET_GUINT16(p)                             \
00062         (uint16_t)((((uint8_t const *)(p))[0] << 0)  |    \
00063                   (((uint8_t const *)(p))[1] << 8))
00064 #define WPD_LE_GET_GUINT32(p) \
00065         (uint32_t)((((uint8_t const *)(p))[0] << 0)  |    \
00066                   (((uint8_t const *)(p))[1] << 8)  |    \
00067                   (((uint8_t const *)(p))[2] << 16) |    \
00068                   (((uint8_t const *)(p))[3] << 24))
00069 
00070 #define WPD_BE_GET_GUINT8(p) (*(uint8_t const *)(p))
00071 #define WPD_BE_GET_GUINT16(p)                           \
00072         (uint16_t)((((uint8_t const *)(p))[1] << 0)  |    \
00073                   (((uint8_t const *)(p))[0] << 8))
00074 #define WPD_BE_GET_GUINT32(p)                           \
00075         (uint32_t)((((uint8_t const *)(p))[3] << 0)  |    \
00076                   (((uint8_t const *)(p))[2] << 8)  |    \
00077                   (((uint8_t const *)(p))[1] << 16) |    \
00078                   (((uint8_t const *)(p))[0] << 24))
00079 
00080 // add more of these as needed for byteswapping
00081 // (the 8-bit functions are just there to make things consistent)
00082 uint8_t readU8(WPXInputStream *input, WPXEncryption *encryption); 
00083 uint16_t readU16(WPXInputStream *input, WPXEncryption *encryption, bool bigendian=false);
00084 uint32_t readU32(WPXInputStream *input, WPXEncryption *encryption, bool bigendian=false);
00085 
00086 WPXString readPascalString(WPXInputStream *input, WPXEncryption *encryption);
00087 WPXString readCString(WPXInputStream *input, WPXEncryption *encryption);
00088 
00089 void appendUCS4(WPXString &str, uint32_t ucs4);
00090 
00091 // Various helper structures for the libwpd parser..
00092 
00093 int extendedCharacterWP6ToUCS2(uint8_t character, uint8_t characterSet,
00094                             const uint16_t **chars);
00095 
00096 int extendedCharacterWP5ToUCS2(uint8_t character, uint8_t characterSet,
00097                             const uint16_t **chars);
00098 
00099 uint16_t fixedPointToWPUs(const uint32_t fixedPointNumber);
00100 float fixedPointToFloat(const uint32_t fixedPointNumber);
00101 
00102 enum WPXFileType { WP6_DOCUMENT, WP5_DOCUMENT, WP42_DOCUMENT, OTHER };
00103 enum WPXNumberingType { ARABIC, LOWERCASE, UPPERCASE, LOWERCASE_ROMAN, UPPERCASE_ROMAN };
00104 enum WPXNoteType { FOOTNOTE, ENDNOTE };
00105 enum WPXHeaderFooterType { HEADER, FOOTER };
00106 enum WPXHeaderFooterInternalType { HEADER_A, HEADER_B, FOOTER_A, FOOTER_B, DUMMY };
00107 enum WPXHeaderFooterOccurence { ODD, EVEN, ALL, NEVER };
00108 enum WPXFormOrientation { PORTRAIT, LANDSCAPE };
00109 enum WPXTabAlignment { LEFT, RIGHT, CENTER, DECIMAL, BAR };
00110 enum WPXVerticalAlignment { TOP, MIDDLE, BOTTOM, FULL };
00111 
00112 enum WPXTextColumnType { NEWSPAPER, NEWSPAPER_VERTICAL_BALANCE, PARALLEL, PARALLEL_PROTECT };
00113 
00114 enum WPXSubDocumentType { WPX_SUBDOCUMENT_NONE, WPX_SUBDOCUMENT_HEADER_FOOTER, WPX_SUBDOCUMENT_NOTE, WPX_SUBDOCUMENT_TEXT_BOX, WPX_SUBDOCUMENT_COMMENT_ANNOTATION };
00115 
00116 // ATTRIBUTE bits
00117 #define WPX_EXTRA_LARGE_BIT 1
00118 #define WPX_VERY_LARGE_BIT 2
00119 #define WPX_LARGE_BIT 4
00120 #define WPX_SMALL_PRINT_BIT 8
00121 #define WPX_FINE_PRINT_BIT 16
00122 #define WPX_SUPERSCRIPT_BIT 32
00123 #define WPX_SUBSCRIPT_BIT 64
00124 #define WPX_OUTLINE_BIT 128
00125 #define WPX_ITALICS_BIT 256
00126 #define WPX_SHADOW_BIT 512
00127 #define WPX_REDLINE_BIT 1024
00128 #define WPX_DOUBLE_UNDERLINE_BIT 2048
00129 #define WPX_BOLD_BIT 4096
00130 #define WPX_STRIKEOUT_BIT 8192
00131 #define WPX_UNDERLINE_BIT 16384
00132 #define WPX_SMALL_CAPS_BIT 32768
00133 #define WPX_BLINK_BIT 65536
00134 #define WPX_REVERSEVIDEO_BIT 131072
00135 
00136 // JUSTIFICATION bits.
00137 #define WPX_PARAGRAPH_JUSTIFICATION_LEFT 0x00
00138 #define WPX_PARAGRAPH_JUSTIFICATION_FULL 0x01
00139 #define WPX_PARAGRAPH_JUSTIFICATION_CENTER 0x02
00140 #define WPX_PARAGRAPH_JUSTIFICATION_RIGHT 0x03
00141 #define WPX_PARAGRAPH_JUSTIFICATION_FULL_ALL_LINES 0x04
00142 #define WPX_PARAGRAPH_JUSTIFICATION_DECIMAL_ALIGNED 0x05
00143 
00144 // TABLE POSITION bits.
00145 #define WPX_TABLE_POSITION_ALIGN_WITH_LEFT_MARGIN 0x00
00146 #define WPX_TABLE_POSITION_ALIGN_WITH_RIGHT_MARGIN 0x01
00147 #define WPX_TABLE_POSITION_CENTER_BETWEEN_MARGINS 0x02
00148 #define WPX_TABLE_POSITION_FULL 0x03
00149 #define WPX_TABLE_POSITION_ABSOLUTE_FROM_LEFT_MARGIN 0x04
00150 
00151 // TABLE CELL BORDER bits
00152 const uint8_t WPX_TABLE_CELL_LEFT_BORDER_OFF = 0x01;
00153 const uint8_t WPX_TABLE_CELL_RIGHT_BORDER_OFF = 0x02;
00154 const uint8_t WPX_TABLE_CELL_TOP_BORDER_OFF = 0x04;
00155 const uint8_t WPX_TABLE_CELL_BOTTOM_BORDER_OFF = 0x08;
00156 
00157 // BREAK bits
00158 #define WPX_PAGE_BREAK 0x00
00159 #define WPX_SOFT_PAGE_BREAK 0x01
00160 #define WPX_COLUMN_BREAK 0x02
00161 
00162 // Generic bits
00163 #define WPX_LEFT 0x00
00164 #define WPX_RIGHT 0x01
00165 #define WPX_CENTER 0x02
00166 #define WPX_TOP 0x03
00167 #define WPX_BOTTOM 0x04
00168 
00169 typedef struct _RGBSColor RGBSColor;
00170 struct _RGBSColor
00171 {
00172         _RGBSColor(uint8_t r, uint8_t g, uint8_t b, uint8_t s);
00173         _RGBSColor(uint16_t red, uint16_t green, uint16_t blue); // Construct
00174         // RBBSColor from double precision RGB color used by WP3.x for Mac
00175         _RGBSColor(); // initializes all values to 0
00176         uint8_t m_r;
00177         uint8_t m_g;
00178         uint8_t m_b;
00179         uint8_t m_s;
00180 };
00181 
00182 typedef struct _WPXColumnDefinition WPXColumnDefinition;
00183 struct _WPXColumnDefinition
00184 {
00185         _WPXColumnDefinition(); // initializes all values to 0
00186         float m_width;
00187         float m_leftGutter;
00188         float m_rightGutter;
00189 };
00190 
00191 typedef struct _WPXColumnProperties WPXColumnProperties;
00192 struct _WPXColumnProperties
00193 {
00194         _WPXColumnProperties();
00195         uint32_t m_attributes;
00196         uint8_t m_alignment;
00197 };
00198 
00199 typedef struct _WPXTabStop WPXTabStop;
00200 struct _WPXTabStop
00201 {
00202         _WPXTabStop(float position, WPXTabAlignment alignment, uint16_t leaderCharacter, uint8_t leaderNumSpaces);
00203         _WPXTabStop();
00204         float m_position;
00205         WPXTabAlignment m_alignment;
00206         uint16_t m_leaderCharacter;
00207         uint8_t m_leaderNumSpaces;
00208 };
00209 
00210 // Various exceptions: libwpd does not propagate exceptions externally..
00211 
00212 class VersionException
00213 {
00214 };
00215 
00216 class FileException
00217 {
00218 };
00219 
00220 class ParseException
00221 {
00222 };
00223 
00224 class GenericException
00225 {
00226 };
00227 
00228 class UnsupportedEncryptionException
00229 {
00230 };
00231 
00232 class SupportedEncryptionException
00233 {
00234 };
00235 
00236 class WrongPasswordException
00237 {
00238 };
00239 
00240 // Various usefull, but cheesey functions
00241 
00242 int _extractNumericValueFromRoman(const char romanChar);
00243 int _extractDisplayReferenceNumberFromBuf(const WPXString &buf, const WPXNumberingType listType);
00244 WPXNumberingType _extractWPXNumberingTypeFromBuf(const WPXString &buf, const WPXNumberingType putativeWPXNumberingType);
00245 WPXString _numberingTypeToString(WPXNumberingType t);
00246 extern const uint16_t macintoshCharacterMap[];
00247 WPXString doubleToString(const double value);
00248 
00249 #endif /* LIBWPD_INTERNAL_H */

Generated on Mon Nov 15 19:50:25 2010 for libwpd by doxygen 1.5.4