rtfimport.h
1/*
2 This file is part of the KDE project
3 Copyright (C) 2001 Ewald Snel <ewald@rambo.its.tudelft.nl>
4 Copyright (C) 2001 Tomasz Grobelny <grotk@poczta.onet.pl>
5 Copyright (C) 2003, 2004 Nicolas GOUTTE <goutte@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11*/
12
13// ### FIXME: copyright holders/date
14
15#ifndef __RTFIMPORT_H__
16#define __RTFIMPORT_H__
17
18#include <KoFilter.h>
19#include <tqasciidict.h>
20#include <tqcolor.h>
21#include <tqcstring.h>
22#include <tqfile.h>
23#include <tqfont.h>
24#include <tqmap.h>
25#include <tqstring.h>
26#include <tqvaluelist.h>
27#include <tqvaluestack.h>
28#include <tqtextcodec.h>
29#include "rtfimport_dom.h"
30#include "rtfimport_tokenizer.h"
31#include <tqptrlist.h>
32
33
34class DomNode;
35class RTFImport;
36
37
40{
41 const char *onlyValidIn;
42 const char *name;
43 void (RTFImport::*cwproc)( struct RTFProperty * );
45 int offset;
47 int value;
48};
49
52{
53 const char *id;
54 int type;
55 int subtype;
56 const char *value;
57};
58
59struct RTFTextState;
60
63{
64 const char *group;
65 const char *name;
66 void (RTFImport::*destproc)( RTFProperty * );
67 RTFTextState* target;
68};
69
72{
73 enum BorderStyle { Solid, Dashes, Dots, DashDot, DashDotDot, None = 16 };
74
75 BorderStyle style;
76 int color;
77 int width;
78 int space;
79};
80
82struct RTFTab
83{
84 enum TabType { Left, Centered, FlushRight, Decimal };
85 enum LeaderType { None, Dots, Hyphens, Underline, ThickLine };
86
87 TabType type;
88 LeaderType leader;
89 int position;
90};
91
93struct RTFFont
94{
95 TQString name;
96 TQFont::StyleHint styleHint;
97 int fixedPitch;
98 int number;
99};
100
103{
104 enum PictureType { BMP, WMF, MacPict, EMF, PNG, JPEG };
105
106 TQByteArray bits;
107 PictureType type;
108 int width, height;
109 int cropLeft, cropTop, cropRight, cropBottom;
110 int desiredWidth, desiredHeight;
111 int scalex, scaley;
112 int nibble;
113 bool scaled;
115 TQString identifier;
116};
117
120{
121 enum Alignment { Left, Right, Justified, Centered };
122
123 TQValueStack<RTFTab> tablist;
124 RTFTab tab;
125 RTFBorder borders[4];
126 RTFBorder *border;
127 Alignment alignment;
128 int style;
129 int firstIndent, leftIndent, rightIndent;
130 int spaceBefore, spaceAfter;
133 bool inTable;
134 bool keep, keepNext;
135 bool pageBB, pageBA;
136};
137
140{
141 enum VertAlign { Normal = 0, SubScript, SuperScript };
142 enum Underline { UnderlineNone=0, UnderlineSimple, UnderlineThick, UnderlineDouble, UnderlineWordByWord,
143 UnderlineWave, UnderlineDash, UnderlineDot, UnderlineDashDot, UnderlineDashDotDot };
144
145 VertAlign vertAlign;
146 Underline underline;
147 int font, fontSize, baseline;
148 int color, bgcolor, underlinecolor;
149 int uc;
150 bool bold, italic, strike, striked;
151 bool hidden, caps, smallCaps;
152};
153
155inline bool operator == ( const RTFFormat& f1, const RTFFormat& f2 )
156{
157 return f1.vertAlign == f2.vertAlign && f1.underline == f2.underline
158 && f1.font == f2.font && f1.fontSize == f2.fontSize && f1.baseline == f2.baseline
159 && f1.color == f2.color && f1.bgcolor == f2.color && f1.underlinecolor == f2.underlinecolor
160 && f1.uc == f2.uc
161 && f1.bold == f2.bold && f1.italic == f2.italic && f1.strike == f2.strike && f1.striked == f2.striked
162 && f1.hidden == f2.hidden && f1.caps == f2.caps && f1.smallCaps == f2.smallCaps
163 ;
164}
166inline bool operator != ( const RTFFormat& f1, const RTFFormat& f2 )
167{
168 return ! ( f1 == f2 );
169}
170
173{
174 TQString name;
175 RTFFormat format;
176 RTFLayout layout;
177 int next;
178};
179
182{
183 int headerMargin;
184 int footerMargin;
185 bool titlePage;
186};
187
190{
191 RTFBorder borders[4];
192 int bgcolor;
193 int x;
194};
195
198{
199 TQValueList<RTFTableCell> cells;
200 TQStringList frameSets;
201 RTFLayout::Alignment alignment;
202 int height;
203 int left;
204};
205
208{
209 RTFFormat fmt;
210 TQString xmldata;
211 uint id, pos, len;
212};
213
216{
218 DomNode node;
220 DomNode cell;
222 DomNode text;
223 TQValueList<KWFormat> formats;
224 TQStringList frameSets;
225 TQValueList<RTFTableRow> rows;
226 uint table, length;
227};
228
231{
232 RTFTableRow tableRow;
233 RTFTableCell tableCell;
234 RTFFormat format;
235 RTFLayout layout;
236 RTFSectionLayout section;
238 bool brace0;
241};
242
243
244class RTFImport : public KoFilter
245{
246 TQ_OBJECT
247
248
249public:
250 RTFImport( KoFilter *parent, const char *name, const TQStringList& );
251
258 virtual KoFilter::ConversionStatus convert( const TQCString& from, const TQCString& to );
259
264 void ignoreKeyword( RTFProperty * );
269 void setCodepage( RTFProperty * );
273 void setMacCodepage( RTFProperty * );
278 void setAnsiCodepage( RTFProperty * );
282 void setPcaCodepage( RTFProperty * );
287 void setPcCodepage( RTFProperty * );
293 void setToggleProperty( RTFProperty * );
299 void setFlagProperty( RTFProperty *property );
305 void setCharset( RTFProperty *property );
311 void setNumericProperty( RTFProperty *property );
317 void setEnumProperty( RTFProperty *property );
322 void setFontStyleHint( RTFProperty* property );
328 void setPictureType( RTFProperty* property );
335 void setSimpleUnderlineProperty( RTFProperty* );
341 void setUnderlineProperty( RTFProperty* property );
346 void setBorderProperty( RTFProperty *property );
351 void setBorderColor( RTFProperty * );
356 void setBorderStyle( RTFProperty *property );
360 void setUpProperty( RTFProperty * );
364 void setPlainFormatting( RTFProperty * = 0L );
368 void setParagraphDefaults( RTFProperty * = 0L );
372 void setSectionDefaults( RTFProperty * = 0L );
376 void setTableRowDefaults( RTFProperty * = 0L );
381 void selectLayoutBorder( RTFProperty * property );
386 void selectLayoutBorderFromCell( RTFProperty * property );
387 void insertParagraph( RTFProperty * = 0L );
388 void insertPageBreak( RTFProperty * );
389 void insertTableCell( RTFProperty * );
393 void insertTableRow( RTFProperty * = 0L );
397 void insertCellDef( RTFProperty * );
401 void insertTabDef( RTFProperty * );
406 void insertUTF8( int ch );
408 void insertSymbol( RTFProperty *property );
410 void insertHexSymbol( RTFProperty * );
412 void insertUnicodeSymbol( RTFProperty * );
416 void insertDateTime( RTFProperty *property );
420 void insertPageNumber( RTFProperty * );
424 void parseBlipUid( RTFProperty* );
430 void parseField( RTFProperty* );
431 void parseFldinst( RTFProperty* );
432 void parseFldrslt( RTFProperty* );
436 void parseFontTable( RTFProperty * );
441 void parseFootNote( RTFProperty * );
445 void parseStyleSheet( RTFProperty * );
449 void parseColorTable( RTFProperty * );
453 void parsePicture( RTFProperty * );
457 void parseRichText( RTFProperty * );
461 void parsePlainText( RTFProperty * );
465 void parseGroup( RTFProperty * );
469 void skipGroup( RTFProperty * );
473 void changeDestination( RTFProperty *property );
474
478 void resetState();
483 void addAnchor( const char *instance );
490 void addFormat( DomNode &node, const KWFormat& format, const RTFFormat* baseFormat );
498 void addLayout( DomNode &node, const TQString &name, const RTFLayout &layout, bool frameBreak );
504 void addParagraph( DomNode &node, bool frameBreak );
505 void addVariable(const DomNode& spec, int type, const TQString& key, const RTFFormat* fmt=0);
506 void addImportedPicture( const TQString& rawFileName );
512 void addDateTime( const TQString& format, const bool isDate, RTFFormat& fmt );
516 void finishTable();
522 void writeOutPart( const char *name, const DomNode &node );
523
524
525 RTFTokenizer token;
526 DomNode frameSets;
527 DomNode pictures;
528 DomNode author, company, title, doccomm;
529 RTFTextState bodyText;
530 TQPtrList<RTFTextState> footnotes;
531 int fnnum;
532 RTFTextState firstPageHeader, oddPagesHeader, evenPagesHeader;
533 RTFTextState firstPageFooter, oddPagesFooter, evenPagesFooter;
538 RTFTextState m_dummyTextState;
539 TQMap<int,TQString> fontTable;
540 TQValueList<RTFStyle> styleSheet;
541 TQValueList<TQColor> colorTable;
542 TQValueStack<RTFGroupState> stateStack;
543 TQValueStack<RTFDestination> destinationStack;
544 RTFGroupState state;
545 RTFDestination destination;
546 RTFTextState *textState;
547 RTFFont font;
548 RTFStyle style;
549 RTFPicture picture;
550 RTFTableCell emptyCell;
551 KWFormat kwFormat;
552 TQAsciiDict<RTFProperty> properties;
553 TQAsciiDict<RTFProperty> destinationProperties;
554 uint table;
555 uint pictureNumber;
556
557 // Color table and document-formatting properties
558 int red, green, blue;
559 int paperWidth, paperHeight;
560 int leftMargin, topMargin, rightMargin, bottomMargin;
561 int defaultTab, defaultFont;
562 bool landscape, facingPages;
563
564 // Field support
565 TQCString fldinst, fldrslt;
566 RTFFormat fldfmt;
567 int flddst;
568 TQString inFileName;
569protected:
570 TQTextCodec* textCodec;
571 TQTextCodec* utf8TextCodec;
572 TQMap<TQString,int> debugUnknownKeywords;
573 bool m_batch;
574};
575
576#endif
This class represents the tokenizer and the token.
KWord format.
Definition rtfimport.h:208
Paragraph border.
Definition rtfimport.h:72
RTF destination.
Definition rtfimport.h:63
RTF field description.
Definition rtfimport.h:52
Font table entry.
Definition rtfimport.h:94
Character-formatting properties.
Definition rtfimport.h:140
RTF group state (formatting properties)
Definition rtfimport.h:231
bool ignoreGroup
Should the group be ignored?
Definition rtfimport.h:240
bool brace0
'}' will close the current destination
Definition rtfimport.h:238
Paragraph-formatting properties.
Definition rtfimport.h:120
bool spaceBetweenMultiple
Is the linespacing defined as multiple of line height (true) or by a height in 1/20 pt (false)?
Definition rtfimport.h:132
int spaceBetween
Line spacing.
Definition rtfimport.h:131
RTF embedded picture.
Definition rtfimport.h:103
TQString identifier
\blipuid
Definition rtfimport.h:115
RTF property (control word table entry)
Definition rtfimport.h:40
int value
default value
Definition rtfimport.h:47
int offset
offset of formatting property
Definition rtfimport.h:45
Section-formatting properties.
Definition rtfimport.h:182
Style sheet entry.
Definition rtfimport.h:173
Tabulator.
Definition rtfimport.h:83
Table cell definition.
Definition rtfimport.h:190
Table-formatting properties.
Definition rtfimport.h:198
RTF rich text state (text and tables)
Definition rtfimport.h:216
DomNode cell
table cell(s)
Definition rtfimport.h:220
DomNode text
plain text (for paragraph or table cell)
Definition rtfimport.h:222
DomNode node
paragraphs
Definition rtfimport.h:218