libwpd_internal.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* libwpd
00003  * Version: MPL 2.0 / LGPLv2.1+
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Major Contributor(s):
00010  * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00011  * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00012  *
00013  * For minor contributions see the git repository.
00014  *
00015  * Alternatively, the contents of this file may be used under the terms
00016  * of the GNU Lesser General Public License Version 2.1 or later
00017  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00018  * applicable instead of those above.
00019  *
00020  * For further information visit http://libwpd.sourceforge.net
00021  */
00022 
00023 /* "This product is not manufactured, approved, or supported by
00024  * Corel Corporation or Corel Corporation Limited."
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 /* Various functions/defines that need not/should not be exported externally */
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_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
00062 
00063 // add more of these as needed for byteswapping
00064 // (the 8-bit functions are just there to make things consistent)
00065 uint8_t readU8(WPXInputStream *input, WPXEncryption *encryption);
00066 uint16_t readU16(WPXInputStream *input, WPXEncryption *encryption, bool bigendian=false);
00067 int16_t readS16(WPXInputStream *input, WPXEncryption *encryption, bool bigendian=false);
00068 uint32_t readU32(WPXInputStream *input, WPXEncryption *encryption, bool bigendian=false);
00069 
00070 WPXString readPascalString(WPXInputStream *input, WPXEncryption *encryption);
00071 WPXString readCString(WPXInputStream *input, WPXEncryption *encryption);
00072 
00073 void appendUCS4(WPXString &str, uint32_t ucs4);
00074 
00075 // Various helper structures for the libwpd parser..
00076 
00077 int extendedCharacterWP6ToUCS4(uint8_t character, uint8_t characterSet,
00078                                const uint32_t **chars);
00079 
00080 int extendedCharacterWP5ToUCS4(uint8_t character, uint8_t characterSet,
00081                                const uint32_t **chars);
00082 
00083 int appleWorldScriptToUCS4(uint16_t character, const uint32_t **chars);
00084 
00085 int extendedCharacterWP42ToUCS4(uint8_t character, const uint32_t **chars);
00086 
00087 uint16_t fixedPointToWPUs(const uint32_t fixedPointNumber);
00088 double fixedPointToDouble(const uint32_t fixedPointNumber);
00089 double wpuToFontPointSize(const uint16_t wpuNumber);
00090 
00091 enum WPXFileType { WP6_DOCUMENT, WP5_DOCUMENT, WP42_DOCUMENT, OTHER };
00092 enum WPXNumberingType { ARABIC, LOWERCASE, UPPERCASE, LOWERCASE_ROMAN, UPPERCASE_ROMAN };
00093 enum WPXNoteType { FOOTNOTE, ENDNOTE };
00094 enum WPXHeaderFooterType { HEADER, FOOTER };
00095 enum WPXHeaderFooterInternalType { HEADER_A, HEADER_B, FOOTER_A, FOOTER_B, DUMMY };
00096 enum WPXHeaderFooterOccurence { ODD, EVEN, ALL, NEVER };
00097 enum WPXPageNumberPosition { PAGENUMBER_POSITION_NONE = 0, PAGENUMBER_POSITION_TOP_LEFT, PAGENUMBER_POSITION_TOP_CENTER,
00098                              PAGENUMBER_POSITION_TOP_RIGHT, PAGENUMBER_POSITION_TOP_LEFT_AND_RIGHT,
00099                              PAGENUMBER_POSITION_BOTTOM_LEFT, PAGENUMBER_POSITION_BOTTOM_CENTER,
00100                              PAGENUMBER_POSITION_BOTTOM_RIGHT, PAGENUMBER_POSITION_BOTTOM_LEFT_AND_RIGHT,
00101                              PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT,
00102                              PAGENUMBER_POSITION_BOTTOM_INSIDE_LEFT_AND_RIGHT
00103                            };
00104 
00105 enum WPXFormOrientation { PORTRAIT, LANDSCAPE };
00106 enum WPXTabAlignment { LEFT, RIGHT, CENTER, DECIMAL, BAR };
00107 enum WPXVerticalAlignment { TOP, MIDDLE, BOTTOM, FULL };
00108 
00109 enum WPXTextColumnType { NEWSPAPER, NEWSPAPER_VERTICAL_BALANCE, PARALLEL, PARALLEL_PROTECT };
00110 
00111 enum WPXSubDocumentType { WPX_SUBDOCUMENT_NONE, WPX_SUBDOCUMENT_HEADER_FOOTER, WPX_SUBDOCUMENT_NOTE, WPX_SUBDOCUMENT_TEXT_BOX, WPX_SUBDOCUMENT_COMMENT_ANNOTATION };
00112 
00113 // ATTRIBUTE bits
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 // JUSTIFICATION bits.
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 // TABLE POSITION bits.
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 // TABLE CELL BORDER bits
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 // BREAK bits
00155 #define WPX_PAGE_BREAK 0x00
00156 #define WPX_SOFT_PAGE_BREAK 0x01
00157 #define WPX_COLUMN_BREAK 0x02
00158 
00159 // Generic bits
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); // Construct
00171         // RBBSColor from double precision RGB color used by WP3.x for Mac
00172         _RGBSColor(); // initializes all values to 0
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(); // initializes all values to 0
00183         double m_width;
00184         double m_leftGutter;
00185         double 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();
00200         double m_position;
00201         WPXTabAlignment m_alignment;
00202         uint32_t m_leaderCharacter;
00203         uint8_t m_leaderNumSpaces;
00204 };
00205 
00206 // Various exceptions: libwpd does not propagate exceptions externally..
00207 
00208 class VersionException
00209 {
00210 };
00211 
00212 class FileException
00213 {
00214 };
00215 
00216 class ParseException
00217 {
00218 };
00219 
00220 class GenericException
00221 {
00222 };
00223 
00224 class UnsupportedEncryptionException
00225 {
00226 };
00227 
00228 class SupportedEncryptionException
00229 {
00230 };
00231 
00232 class WrongPasswordException
00233 {
00234 };
00235 
00236 // Various usefull, but cheesey functions
00237 
00238 int _extractNumericValueFromRoman(const char romanChar);
00239 int _extractDisplayReferenceNumberFromBuf(const WPXString &buf, const WPXNumberingType listType);
00240 WPXNumberingType _extractWPXNumberingTypeFromBuf(const WPXString &buf, const WPXNumberingType putativeWPXNumberingType);
00241 WPXString _numberingTypeToString(WPXNumberingType t);
00242 extern const uint32_t macRomanCharacterMap[];
00243 WPXString doubleToString(const double value);
00244 
00245 #endif /* LIBWPD_INTERNAL_H */
00246 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */