filters

amiproparser.h
1/* This file is part of the KDE project
2 Copyright (C) 2002 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#ifndef __AMIPROPARSER_H
21#define __AMIPROPARSER_H
22
23class TQString;
24class TQStringList;
25#include <tqvaluelist.h>
26#include <tqcolor.h>
27
28class AmiPro
29{
30 public:
31 static const float LS_Single, LS_OneAndHalf, LS_Double;
32};
33
34class AmiProStyle;
35
36class AmiProFormat
37{
38 public:
39 int pos, len;
40 bool bold, italic, underline;
41 bool word_underline, double_underline;
42 bool subscript, superscript, strikethrough;
43 TQString fontFamily;
44 float fontSize;
45 TQColor fontColor;
46 enum { Left, Right, Center, Justified } align;
47 AmiProFormat();
48 AmiProFormat( const AmiProFormat& );
49 AmiProFormat& operator=( const AmiProFormat& );
50 void assign( const AmiProFormat& );
51 void applyStyle( const AmiProStyle& );
52};
53
54typedef TQValueList<AmiProFormat> AmiProFormatList;
55
56
57class AmiProLayout
58{
59 public:
60 TQString name;
61 TQString fontFamily;
62 float fontSize;
63 TQColor fontColor;
64 bool bold, italic, underline;
65 bool word_underline, double_underline;
66 bool subscript, superscript, strikethrough;
67 TQt::AlignmentFlags align;
68 float linespace;
69 float spaceBefore, spaceAfter;
70 AmiProLayout();
71 AmiProLayout( const AmiProLayout& );
72 AmiProLayout& operator=( const AmiProLayout& );
73 void assign( const AmiProLayout& );
74 void applyStyle( const AmiProStyle& );
75};
76
77class AmiProStyle
78{
79 public:
80 TQString name;
81 TQString fontFamily;
82 float fontSize;
83 TQColor fontColor;
84 bool bold, italic, underline;
85 bool word_underline, double_underline;
86 bool subscript, superscript, strikethrough;
87 TQt::AlignmentFlags align;
88 float linespace;
89 float spaceBefore, spaceAfter;
90 AmiProStyle();
91 AmiProStyle( const AmiProStyle& );
92 AmiProStyle& operator=( const AmiProStyle& );
93 void assign( const AmiProStyle& );
94};
95
96typedef TQValueList<AmiProStyle> AmiProStyleList;
97
98class AmiProListener
99{
100 public:
101 AmiProListener();
102 virtual ~AmiProListener();
103 virtual bool doOpenDocument();
104 virtual bool doCloseDocument();
105 virtual bool doDefineStyle( const AmiProStyle& style );
106 virtual bool doParagraph( const TQString& text, AmiProFormatList formatList,
107 AmiProLayout& layout );
108};
109
110class AmiProParser
111{
112
113 public:
114 AmiProParser();
115 virtual ~AmiProParser();
116
117 enum { OK, UnknownError, FileError, InvalidFormat } Error;
118
119 bool process( const TQString& filename );
120 int result(){ return m_result; }
121
122 void setListener( AmiProListener * );
123
124 private:
125
126 int m_result;
127 TQString m_text;
128 AmiProFormat m_currentFormat;
129 AmiProFormatList m_formatList;
130 AmiProLayout m_layout;
131 AmiProStyleList m_styleList;
132
133
134 AmiProListener *m_listener;
135
136 TQString m_currentSection;
137
138 bool setResult( int );
139 bool parseParagraph( const TQStringList& lines );
140 bool parseStyle( const TQStringList& line );
141 AmiProStyle findStyle( const TQString& name );
142
143 bool handleTag( const TQString& tag );
144 bool processOpenDocument();
145 bool processCloseDocument();
146 bool processParagraph( const TQString& text, AmiProFormatList formatList,
147 AmiProLayout& layout );
148
149};
150
151#endif