~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to filters/kword/wordperfect/import/parser.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
 
 
21
#ifndef __WP_PARSER_H
 
22
#define __WP_PARSER_H
 
23
 
 
24
#include <qptrlist.h>
 
25
#include <qmemarray.h>
 
26
#include <qstring.h>
 
27
 
 
28
namespace WP
 
29
{
 
30
 
 
31
/**
 
32
 * This class is an abstract encapsulation of a token to be use in the parser.
 
33
 * @see Parser
 
34
 */
 
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, 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 QString & 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, QString fontface){ m_type = FontFace; m_fontface = fontface;  }
 
109
 
 
110
    Token (const QPtrList < 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
    QString 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
    QString fontface (){ return m_fontface; }
 
131
    int charset (){ return m_charset; }
 
132
    int charcode (){ return m_charcode; }
 
133
    QPtrList < Tab > tabs (){  return m_tabs; }
 
134
 
 
135
 
 
136
  private:
 
137
 
 
138
    Type m_type;
 
139
    int m_value;
 
140
    QString m_text;
 
141
    Attr m_attr;
 
142
    Align m_align;
 
143
    int m_red, m_green, m_blue;
 
144
    QString m_fontface;
 
145
    int m_charset, m_charcode;
 
146
    QPtrList < Tab > m_tabs;
 
147
 
 
148
 
 
149
 
 
150
  };
 
151
 
 
152
  class Packet
 
153
  {
 
154
    public:
 
155
      unsigned type, size, pos;
 
156
      QMemArray<Q_UINT8> data;
 
157
  };
 
158
 
 
159
/**
 
160
 * This class implements a functional parser for WordPerfect documents.
 
161
 * @author Ariya Hidayat
 
162
 * @see Token
 
163
 */
 
164
 
 
165
  class Parser
 
166
  {
 
167
 
 
168
  public:
 
169
    Parser ();
 
170
 
 
171
    /**
 
172
     * Parses given filename.
 
173
     * @returns TRUE if parsing was successful, otherwise FALSE.
 
174
     *
 
175
     */
 
176
    bool parse (const QString & filename);
 
177
 
 
178
    // high byte is major version, 0=WP 5.x, 2=WP 6/7/8
 
179
    int version;
 
180
 
 
181
    QString docTitle, docAuthor, docAbstract;
 
182
 
 
183
    QPtrList<Token> tokens;
 
184
    QPtrList<Packet> packets;
 
185
 
 
186
    /**
 
187
     * Maps WordPerfect extended character to its Unicode equivalent. Supported character
 
188
     * sets at the moment are Multinational (charset 1), Phonetic Symbol (charset 2),
 
189
     * Typographic Symbol (charset 4), Iconic Symbol (charset 5),
 
190
     * Math/Scientific (charset 6 and 7), Greek (charset 8), Hebrew (harset 9), and
 
191
     * Cyrillic (charset 10)
 
192
     */
 
193
    static unsigned int ExtCharToUnicode (int charset, int charcode);
 
194
 
 
195
  protected:
 
196
 
 
197
  private:
 
198
 
 
199
    void handleTab ( QMemArray <Q_UINT8> data );
 
200
 
 
201
    void parsePacketWP5( const QString & filename );
 
202
    void parseDocWP5( const QString & filename, int start );
 
203
 
 
204
    void parsePacketWP6( const QString & filename );
 
205
    void parseDocWP6( const QString & filename, int start );
 
206
 
 
207
  };
 
208
 
 
209
}
 
210
 
 
211
 
 
212
#endif