lib

elementtype.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef ELEMENTTYPE_H
22#define ELEMENTTYPE_H
23
24#include <tqfont.h>
25#include <tqstring.h>
26#include <tqdom.h>
27
28#include "contextstyle.h"
29#include "kformuladefs.h"
30
31class TQPainter;
32
33KFORMULA_NAMESPACE_BEGIN
34
35class BasicElement;
36class BracketType;
37class ComplexElementType;
38class InnerElementType;
40class OperatorType;
41class PunctuationType;
42class RelationType;
43class SequenceElement;
44class SequenceParser;
45class TextElement;
46
47
52class ElementType {
53public:
54 ElementType(SequenceParser* parser);
55 virtual ~ElementType();
56
60 virtual bool isInvisible(const TextElement&) const { return false; }
61
66 virtual TQString text( SequenceElement* seq ) const;
67
71 uint start() const { return from; }
72
76 uint end() const { return to; }
77
82 virtual luPt getSpaceBefore( const ContextStyle& context,
84 double factor );
85 virtual luPt getSpaceAfter( MultiElementType* type,
86 const ContextStyle& context,
88 double factor );
89 virtual luPt getSpaceAfter( OperatorType* type,
90 const ContextStyle& context,
92 double factor );
93 virtual luPt getSpaceAfter( RelationType* type,
94 const ContextStyle& context,
96 double factor );
97 virtual luPt getSpaceAfter( PunctuationType* type,
98 const ContextStyle& context,
100 double factor );
101 virtual luPt getSpaceAfter( BracketType* type,
102 const ContextStyle& context,
104 double factor );
105 virtual luPt getSpaceAfter( ComplexElementType* type,
106 const ContextStyle& context,
108 double factor );
109 virtual luPt getSpaceAfter( InnerElementType* type,
110 const ContextStyle& context,
112 double factor );
113
117 virtual TQFont getFont( const ContextStyle& context );
118
122 virtual void setUpPainter( const ContextStyle& context, TQPainter& painter );
123
124 // debug
125 static int getEvilDestructionCount() { return evilDestructionCount; }
126
127 virtual void output();
128
132 void append( ElementType* );
133
134 ElementType* getPrev() const { return prev; }
135
136 virtual void saveMathML( SequenceElement* se, TQDomDocument& doc, TQDomElement de, bool oasisFormat = false );
137
138 virtual bool multiElement() const { return false; }
139
140protected:
141
142 void setStart( uint start ) { from = start; }
143 void setEnd( uint end ) { to = end; }
144
145 luPt thinSpaceIfNotScript( const ContextStyle& context,
147 double factor );
148 luPt mediumSpaceIfNotScript( const ContextStyle& context,
150 double factor );
151 luPt thickSpaceIfNotScript( const ContextStyle& context,
153 double factor );
154
155private:
156
161 uint from;
162
167 uint to;
168
173 ElementType* prev;
174
175 // debug
176 static int evilDestructionCount;
177};
178
179
184class SequenceType : public ElementType {
185public:
186 SequenceType( SequenceParser* parser );
187 ~SequenceType();
188
189 virtual void output();
190private:
191
195 ElementType* last;
196};
197
198
202class MultiElementType : public ElementType {
203public:
204 MultiElementType( SequenceParser* parser );
205
206 virtual luPt getSpaceBefore( const ContextStyle& context,
208 double factor );
209 virtual luPt getSpaceAfter( OperatorType* type,
210 const ContextStyle& context,
212 double factor );
213 virtual luPt getSpaceAfter( RelationType* type,
214 const ContextStyle& context,
216 double factor );
217 virtual luPt getSpaceAfter( InnerElementType* type,
218 const ContextStyle& context,
220 double factor );
221
222 virtual bool multiElement() const { return true; }
223
228 virtual TQString text( SequenceElement* /*seq*/ ) const { return m_text; }
229
230private:
231
232 TQString m_text;
233};
234
235
240class TextType : public MultiElementType {
241public:
242 TextType( SequenceParser* parser );
243 virtual void saveMathML( SequenceElement* se, TQDomDocument& doc, TQDomElement de, bool oasisFormat = false );
244};
245
246
250class NumberType : public MultiElementType {
251public:
252 NumberType(SequenceParser* parser);
253
257 virtual TQFont getFont(const ContextStyle& context);
258
262 virtual void setUpPainter(const ContextStyle& context, TQPainter& painter);
263
264 virtual void saveMathML( SequenceElement* se, TQDomDocument& doc, TQDomElement de, bool oasisFormat = false );
265};
266
267
271class SingleElementType : public ElementType {
272public:
273 SingleElementType( SequenceParser* parser );
274};
275
276
280class NameType : public MultiElementType {
281public:
282 NameType( SequenceParser* parser );
283
287 virtual TQFont getFont( const ContextStyle& context );
288
289 virtual void saveMathML( SequenceElement* se, TQDomDocument& doc, TQDomElement de, bool oasisFormat = false );
290
291private:
292};
293
294
295class AbstractOperatorType : public SingleElementType {
296public:
297 AbstractOperatorType( SequenceParser* parser );
298
299 void saveMathML( SequenceElement* se, TQDomDocument& doc, TQDomElement de, bool oasisFormat = false );
300};
301
302class OperatorType : public AbstractOperatorType {
303public:
304 OperatorType( SequenceParser* parser );
305
306 virtual luPt getSpaceBefore( const ContextStyle& context,
308 double factor );
309 virtual luPt getSpaceAfter( MultiElementType* type,
310 const ContextStyle& context,
312 double factor );
313 virtual luPt getSpaceAfter( BracketType* type,
314 const ContextStyle& context,
316 double factor );
317 virtual luPt getSpaceAfter( ComplexElementType* type,
318 const ContextStyle& context,
320 double factor );
321 virtual luPt getSpaceAfter( InnerElementType* type,
322 const ContextStyle& context,
324 double factor );
325
329 virtual TQFont getFont(const ContextStyle& context);
330
334 virtual void setUpPainter(const ContextStyle& context, TQPainter& painter);
335};
336
337
338class RelationType : public AbstractOperatorType {
339public:
340 RelationType( SequenceParser* parser );
341
342 virtual luPt getSpaceBefore( const ContextStyle& context,
344 double factor );
345 virtual luPt getSpaceAfter( MultiElementType* type,
346 const ContextStyle& context,
348 double factor );
349 virtual luPt getSpaceAfter( BracketType* type,
350 const ContextStyle& context,
352 double factor );
353 virtual luPt getSpaceAfter( ComplexElementType* type,
354 const ContextStyle& context,
356 double factor );
357 virtual luPt getSpaceAfter( InnerElementType* type,
358 const ContextStyle& context,
360 double factor );
361
365 virtual TQFont getFont( const ContextStyle& context );
366
370 virtual void setUpPainter( const ContextStyle& context, TQPainter& painter );
371};
372
373
374class PunctuationType : public AbstractOperatorType {
375public:
376 PunctuationType( SequenceParser* parser );
377
378 virtual luPt getSpaceBefore( const ContextStyle& context,
380 double factor );
381 virtual luPt getSpaceAfter( MultiElementType* type,
382 const ContextStyle& context,
384 double factor );
385 virtual luPt getSpaceAfter( RelationType* type,
386 const ContextStyle& context,
388 double factor );
389 virtual luPt getSpaceAfter( PunctuationType* type,
390 const ContextStyle& context,
392 double factor );
393 virtual luPt getSpaceAfter( BracketType* type,
394 const ContextStyle& context,
396 double factor );
397 virtual luPt getSpaceAfter( ComplexElementType* type,
398 const ContextStyle& context,
400 double factor );
401 virtual luPt getSpaceAfter( InnerElementType* type,
402 const ContextStyle& context,
404 double factor );
405
409 virtual TQFont getFont( const ContextStyle& context );
410
414 virtual void setUpPainter( const ContextStyle& context, TQPainter& painter );
415};
416
417
418class BracketType : public SingleElementType {
419public:
420 BracketType( SequenceParser* parser );
421
422 virtual luPt getSpaceBefore( const ContextStyle& context,
424 double factor );
425 virtual luPt getSpaceAfter( OperatorType* type,
426 const ContextStyle& context,
428 double factor );
429 virtual luPt getSpaceAfter( RelationType* type,
430 const ContextStyle& context,
432 double factor );
433 virtual luPt getSpaceAfter( InnerElementType* type,
434 const ContextStyle& context,
436 double factor );
437};
438
439
440class ComplexElementType : public SingleElementType {
441public:
442 ComplexElementType( SequenceParser* parser );
443
444 // these spacings are equal to the ones from MultiElementType
445 virtual luPt getSpaceBefore( const ContextStyle& context,
447 double factor );
448 virtual luPt getSpaceAfter( OperatorType* type,
449 const ContextStyle& context,
451 double factor );
452 virtual luPt getSpaceAfter( RelationType* type,
453 const ContextStyle& context,
455 double factor );
456 virtual luPt getSpaceAfter( InnerElementType* type,
457 const ContextStyle& context,
459 double factor );
460};
461
462
463class InnerElementType : public SingleElementType {
464public:
465 InnerElementType( SequenceParser* parser );
466
467 virtual luPt getSpaceBefore( const ContextStyle& context,
469 double factor );
470 virtual luPt getSpaceAfter( MultiElementType* type,
471 const ContextStyle& context,
473 double factor );
474 virtual luPt getSpaceAfter( OperatorType* type,
475 const ContextStyle& context,
477 double factor );
478 virtual luPt getSpaceAfter( RelationType* type,
479 const ContextStyle& context,
481 double factor );
482 virtual luPt getSpaceAfter( PunctuationType* type,
483 const ContextStyle& context,
485 double factor );
486 virtual luPt getSpaceAfter( BracketType* type,
487 const ContextStyle& context,
489 double factor );
490 virtual luPt getSpaceAfter( ComplexElementType* type,
491 const ContextStyle& context,
493 double factor );
494 virtual luPt getSpaceAfter( InnerElementType* type,
495 const ContextStyle& context,
497 double factor );
498};
499
500
501KFORMULA_NAMESPACE_END
502
503#endif // ELEMENTTYPE_H
Basis of every formula element.
Contains all the style information for the formela.
TextStyle
Textstyles like in TeX.
virtual TQFont getFont(const ContextStyle &context)
virtual TQString text(SequenceElement *seq) const
uint start() const
Definition elementtype.h:71
virtual bool isInvisible(const TextElement &) const
Definition elementtype.h:60
void append(ElementType *)
Adds a type at the end of the list.
virtual luPt getSpaceBefore(const ContextStyle &context, ContextStyle::TextStyle tstyle, double factor)
uint end() const
Definition elementtype.h:76
virtual void setUpPainter(const ContextStyle &context, TQPainter &painter)
sets the painters pen to a appropriate value
Basis for all tokens that run along several elements.
virtual luPt getSpaceBefore(const ContextStyle &context, ContextStyle::TextStyle tstyle, double factor)
virtual TQString text(SequenceElement *) const
virtual TQFont getFont(const ContextStyle &context)
virtual void setUpPainter(const ContextStyle &context, TQPainter &painter)
sets the painters pen to a appropriate value
virtual TQFont getFont(const ContextStyle &context)
The element that contains a number of children.
The parser that gets the element list and returns a syntax tree.
Basis for all tokens that consist of one element only.
An element that represents one char.
Definition textelement.h:37