filters

parser.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 Ariya Hidayat <ariyahidayat@yahoo.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20
21#ifndef __WP_PARSER_H
22#define __WP_PARSER_H
23
24#include <tqptrlist.h>
25#include <tqmemarray.h>
26#include <tqstring.h>
27
28namespace WP
29{
30
35
36 class Token
37 {
38
39 public:
40
41 enum Type
42 {
43 Unknown, Function, Text, Lang,
44 SoftSpace, HardSpace, HardHyphen, ExtChar,
45 SoftReturn, HardReturn, DormantHardReturn,
46 AttrOn, AttrOff, UnderlineMode,
47 MarkTocStart, MarkTocEnd,
48 LeftMargin, RightMargin, TopMargin, BottomMargin,
49 Linespace, Justification, ParagraphIndent, LeftMarginAdjust,
50 RightMarginAdjust,
51 TabSet, TabLeft, TabHardFlushRight,
52 FontColor, FontSize, FontFace, HighlightOn, HighlightOff,
53 TableOn, TableColumn, TableEnd, TableCell, TableRow, TableOff
54 };
55
56 enum Attr
57 {
58 None, ExtraLarge, VeryLarge, Large, Small, Fine,
59 Bold, Italic, Underline, DoubleUnderline, Subscript, Superscript,
60 StrikedOut, Redline, Shadow, Outline, SmallCaps, Blink
61 };
62
63 enum Align
64 { Left, Right, Center, Full, All };
65
66 enum TabType
67 { LeftTab, CenterTab, RightTab, DecimalTab,TQt::VerticalTab };
68
69 class Tab
70 {
71 public:
72 TabType type;
73 int pos;
74 Tab (TabType t, int p)
75 {
76 type = t;
77 pos = p;
78 }
79 };
80
81 Token () { m_type = Unknown; }
82
83 Token (Type type) { m_type = type; }
84
85 Token (const TQString & text) { m_type = Text; m_text = text; }
86
87 Token (Type type, Attr attr) { m_type = type; m_attr = attr; }
88
89 Token (Type type, int value) { m_type = type; m_value = value; }
90
91 Token (Type type, Align align){ m_type = type; m_align = align; }
92
93 Token (Type type, int charset, int charcode)
94 {
95 m_type = type;
96 m_charset = charset;
97 m_charcode = charcode;
98 }
99
100 Token (Type type, int red, int green, int blue)
101 {
102 m_type = type;
103 m_red = red;
104 m_green = green;
105 m_blue = blue;
106 }
107
108 Token (Type type, TQString fontface){ m_type = FontFace; m_fontface = fontface; }
109
110 Token (const TQPtrList < Tab > &tabs)
111 {
112 m_type = TabSet;
113 m_tabs = tabs;
114 }
115
116 Type type (){ return m_type; }
117
118 int value (){ return m_value; }
119
120 TQString text (){ return m_text; }
121
122 Attr attr (){ return m_attr; }
123
124 Align align (){ return m_align; }
125
126 int red (){ return m_red; }
127 int green (){ return m_green; }
128 int blue (){ return m_blue; }
129
130 TQString fontface (){ return m_fontface; }
131 int charset (){ return m_charset; }
132 int charcode (){ return m_charcode; }
133 TQPtrList < Tab > tabs (){ return m_tabs; }
134
135
136 private:
137
138 Type m_type;
139 int m_value;
140 TQString m_text;
141 Attr m_attr;
142 Align m_align;
143 int m_red, m_green, m_blue;
144 TQString m_fontface;
145 int m_charset, m_charcode;
146 TQPtrList < Tab > m_tabs;
147
148
149
150 };
151
152 class Packet
153 {
154 public:
155 unsigned type, size, pos;
156 TQMemArray<TQ_UINT8> data;
157 };
158
164
165 class Parser
166 {
167
168 public:
169 Parser ();
170
176 bool parse (const TQString & filename);
177
178 // high byte is major version, 0=WP 5.x, 2=WP 6/7/8
179 int version;
180
181 TQString docTitle, docAuthor, docAbstract;
182
183 TQPtrList<Token> tokens;
184 TQPtrList<Packet> packets;
185
193 static unsigned int ExtCharToUnicode (int charset, int charcode);
194
195 protected:
196
197 private:
198
199 void handleTab ( TQMemArray <TQ_UINT8> data );
200
201 void parsePacketWP5( const TQString & filename );
202 void parseDocWP5( const TQString & filename, int start );
203
204 void parsePacketWP6( const TQString & filename );
205 void parseDocWP6( const TQString & filename, int start );
206
207 };
208
209}
210
211
212#endif
static unsigned int ExtCharToUnicode(int charset, int charcode)
Maps WordPerfect extended character to its Unicode equivalent.
Definition parser.cpp:1282
bool parse(const TQString &filename)
Parses given filename.
Definition parser.cpp:99