00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __RTFIMPORT_H__
00016 #define __RTFIMPORT_H__
00017
00018 #include <KoFilter.h>
00019 #include <qasciidict.h>
00020 #include <qcolor.h>
00021 #include <qcstring.h>
00022 #include <qfile.h>
00023 #include <qfont.h>
00024 #include <qmap.h>
00025 #include <qstring.h>
00026 #include <qvaluelist.h>
00027 #include <qvaluestack.h>
00028 #include <qtextcodec.h>
00029 #include "rtfimport_dom.h"
00030 #include "rtfimport_tokenizer.h"
00031 #include <qptrlist.h>
00032
00033
00034 class DomNode;
00035 class RTFImport;
00036
00037
00039 struct RTFProperty
00040 {
00041 const char *onlyValidIn;
00042 const char *name;
00043 void (RTFImport::*cwproc)( struct RTFProperty * );
00045 int offset;
00047 int value;
00048 };
00049
00051 struct RTFField
00052 {
00053 const char *id;
00054 int type;
00055 int subtype;
00056 const char *value;
00057 };
00058
00059 struct RTFTextState;
00060
00062 struct RTFDestination
00063 {
00064 const char *group;
00065 const char *name;
00066 void (RTFImport::*destproc)( RTFProperty * );
00067 RTFTextState* target;
00068 };
00069
00071 struct RTFBorder
00072 {
00073 enum BorderStyle { Solid, Dashes, Dots, DashDot, DashDotDot, None = 16 };
00074
00075 BorderStyle style;
00076 int color;
00077 int width;
00078 int space;
00079 };
00080
00082 struct RTFTab
00083 {
00084 enum TabType { Left, Centered, FlushRight, Decimal };
00085 enum LeaderType { None, Dots, Hyphens, Underline, ThickLine };
00086
00087 TabType type;
00088 LeaderType leader;
00089 int position;
00090 };
00091
00093 struct RTFFont
00094 {
00095 QString name;
00096 QFont::StyleHint styleHint;
00097 int fixedPitch;
00098 int number;
00099 };
00100
00102 struct RTFPicture
00103 {
00104 enum PictureType { BMP, WMF, MacPict, EMF, PNG, JPEG };
00105
00106 QByteArray bits;
00107 PictureType type;
00108 int width, height;
00109 int cropLeft, cropTop, cropRight, cropBottom;
00110 int desiredWidth, desiredHeight;
00111 int scalex, scaley;
00112 int nibble;
00113 bool scaled;
00115 QString identifier;
00116 };
00117
00119 struct RTFLayout
00120 {
00121 enum Alignment { Left, Right, Justified, Centered };
00122
00123 QValueStack<RTFTab> tablist;
00124 RTFTab tab;
00125 RTFBorder borders[4];
00126 RTFBorder *border;
00127 Alignment alignment;
00128 int style;
00129 int firstIndent, leftIndent, rightIndent;
00130 int spaceBefore, spaceAfter;
00131 int spaceBetween;
00132 bool spaceBetweenMultiple;
00133 bool inTable;
00134 bool keep, keepNext;
00135 bool pageBB, pageBA;
00136 };
00137
00139 struct RTFFormat
00140 {
00141 enum VertAlign { Normal = 0, SubScript, SuperScript };
00142 enum Underline { UnderlineNone=0, UnderlineSimple, UnderlineThick, UnderlineDouble, UnderlineWordByWord,
00143 UnderlineWave, UnderlineDash, UnderlineDot, UnderlineDashDot, UnderlineDashDotDot };
00144
00145 VertAlign vertAlign;
00146 Underline underline;
00147 int font, fontSize, baseline;
00148 int color, bgcolor, underlinecolor;
00149 int uc;
00150 bool bold, italic, strike, striked;
00151 bool hidden, caps, smallCaps;
00152 };
00153
00155 inline bool operator == ( const RTFFormat& f1, const RTFFormat& f2 )
00156 {
00157 return f1.vertAlign == f2.vertAlign && f1.underline == f2.underline
00158 && f1.font == f2.font && f1.fontSize == f2.fontSize && f1.baseline == f2.baseline
00159 && f1.color == f2.color && f1.bgcolor == f2.color && f1.underlinecolor == f2.underlinecolor
00160 && f1.uc == f2.uc
00161 && f1.bold == f2.bold && f1.italic == f2.italic && f1.strike == f2.strike && f1.striked == f2.striked
00162 && f1.hidden == f2.hidden && f1.caps == f2.caps && f1.smallCaps == f2.smallCaps
00163 ;
00164 }
00166 inline bool operator != ( const RTFFormat& f1, const RTFFormat& f2 )
00167 {
00168 return ! ( f1 == f2 );
00169 }
00170
00172 struct RTFStyle
00173 {
00174 QString name;
00175 RTFFormat format;
00176 RTFLayout layout;
00177 int next;
00178 };
00179
00181 struct RTFSectionLayout
00182 {
00183 int headerMargin;
00184 int footerMargin;
00185 bool titlePage;
00186 };
00187
00189 struct RTFTableCell
00190 {
00191 RTFBorder borders[4];
00192 int bgcolor;
00193 int x;
00194 };
00195
00197 struct RTFTableRow
00198 {
00199 QValueList<RTFTableCell> cells;
00200 QStringList frameSets;
00201 RTFLayout::Alignment alignment;
00202 int height;
00203 int left;
00204 };
00205
00207 struct KWFormat
00208 {
00209 RTFFormat fmt;
00210 QString xmldata;
00211 uint id, pos, len;
00212 };
00213
00215 struct RTFTextState
00216 {
00218 DomNode node;
00220 DomNode cell;
00222 DomNode text;
00223 QValueList<KWFormat> formats;
00224 QStringList frameSets;
00225 QValueList<RTFTableRow> rows;
00226 uint table, length;
00227 };
00228
00230 struct RTFGroupState
00231 {
00232 RTFTableRow tableRow;
00233 RTFTableCell tableCell;
00234 RTFFormat format;
00235 RTFLayout layout;
00236 RTFSectionLayout section;
00238 bool brace0;
00240 bool ignoreGroup;
00241 };
00242
00243
00244 class RTFImport : public KoFilter
00245 {
00246 Q_OBJECT
00247
00248 public:
00249 RTFImport( KoFilter *parent, const char *name, const QStringList& );
00250
00257 virtual KoFilter::ConversionStatus convert( const QCString& from, const QCString& to );
00258
00263 void ignoreKeyword( RTFProperty * );
00268 void setCodepage( RTFProperty * );
00272 void setMacCodepage( RTFProperty * );
00277 void setAnsiCodepage( RTFProperty * );
00281 void setPcaCodepage( RTFProperty * );
00286 void setPcCodepage( RTFProperty * );
00292 void setToggleProperty( RTFProperty * );
00298 void setFlagProperty( RTFProperty *property );
00304 void setCharset( RTFProperty *property );
00310 void setNumericProperty( RTFProperty *property );
00316 void setEnumProperty( RTFProperty *property );
00321 void setFontStyleHint( RTFProperty* property );
00327 void setPictureType( RTFProperty* property );
00334 void setSimpleUnderlineProperty( RTFProperty* );
00340 void setUnderlineProperty( RTFProperty* property );
00345 void setBorderProperty( RTFProperty *property );
00350 void setBorderColor( RTFProperty * );
00355 void setBorderStyle( RTFProperty *property );
00359 void setUpProperty( RTFProperty * );
00363 void setPlainFormatting( RTFProperty * = 0L );
00367 void setParagraphDefaults( RTFProperty * = 0L );
00371 void setSectionDefaults( RTFProperty * = 0L );
00375 void setTableRowDefaults( RTFProperty * = 0L );
00380 void selectLayoutBorder( RTFProperty * property );
00385 void selectLayoutBorderFromCell( RTFProperty * property );
00386 void insertParagraph( RTFProperty * = 0L );
00387 void insertPageBreak( RTFProperty * );
00388 void insertTableCell( RTFProperty * );
00392 void insertTableRow( RTFProperty * = 0L );
00396 void insertCellDef( RTFProperty * );
00400 void insertTabDef( RTFProperty * );
00405 void insertUTF8( int ch );
00407 void insertSymbol( RTFProperty *property );
00409 void insertHexSymbol( RTFProperty * );
00411 void insertUnicodeSymbol( RTFProperty * );
00415 void insertDateTime( RTFProperty *property );
00419 void insertPageNumber( RTFProperty * );
00423 void parseBlipUid( RTFProperty* );
00429 void parseField( RTFProperty* );
00430 void parseFldinst( RTFProperty* );
00431 void parseFldrslt( RTFProperty* );
00435 void parseFontTable( RTFProperty * );
00440 void parseFootNote( RTFProperty * );
00444 void parseStyleSheet( RTFProperty * );
00448 void parseColorTable( RTFProperty * );
00452 void parsePicture( RTFProperty * );
00456 void parseRichText( RTFProperty * );
00460 void parsePlainText( RTFProperty * );
00464 void parseGroup( RTFProperty * );
00468 void skipGroup( RTFProperty * );
00472 void changeDestination( RTFProperty *property );
00473
00477 void resetState();
00482 void addAnchor( const char *instance );
00489 void addFormat( DomNode &node, const KWFormat& format, const RTFFormat* baseFormat );
00497 void addLayout( DomNode &node, const QString &name, const RTFLayout &layout, bool frameBreak );
00503 void addParagraph( DomNode &node, bool frameBreak );
00504 void addVariable(const DomNode& spec, int type, const QString& key, const RTFFormat* fmt=0);
00505 void addImportedPicture( const QString& rawFileName );
00511 void addDateTime( const QString& format, const bool isDate, RTFFormat& fmt );
00515 void finishTable();
00521 void writeOutPart( const char *name, const DomNode &node );
00522
00523
00524 RTFTokenizer token;
00525 DomNode frameSets;
00526 DomNode pictures;
00527 DomNode author, company, title, doccomm;
00528 RTFTextState bodyText;
00529 QPtrList<RTFTextState> footnotes;
00530 int fnnum;
00531 RTFTextState firstPageHeader, oddPagesHeader, evenPagesHeader;
00532 RTFTextState firstPageFooter, oddPagesFooter, evenPagesFooter;
00537 RTFTextState m_dummyTextState;
00538 QMap<int,QString> fontTable;
00539 QValueList<RTFStyle> styleSheet;
00540 QValueList<QColor> colorTable;
00541 QValueStack<RTFGroupState> stateStack;
00542 QValueStack<RTFDestination> destinationStack;
00543 RTFGroupState state;
00544 RTFDestination destination;
00545 RTFTextState *textState;
00546 RTFFont font;
00547 RTFStyle style;
00548 RTFPicture picture;
00549 RTFTableCell emptyCell;
00550 KWFormat kwFormat;
00551 QAsciiDict<RTFProperty> properties;
00552 QAsciiDict<RTFProperty> destinationProperties;
00553 uint table;
00554 uint pictureNumber;
00555
00556
00557 int red, green, blue;
00558 int paperWidth, paperHeight;
00559 int leftMargin, topMargin, rightMargin, bottomMargin;
00560 int defaultTab, defaultFont;
00561 bool landscape, facingPages;
00562
00563
00564 QCString fldinst, fldrslt;
00565 RTFFormat fldfmt;
00566 int flddst;
00567 QString inFileName;
00568 protected:
00569 QTextCodec* textCodec;
00570 QTextCodec* utf8TextCodec;
00571 QMap<QString,int> debugUnknownKeywords;
00572 bool m_batch;
00573 };
00574
00575 #endif