lib

tokenelement.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
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#include <algorithm>
21
22#include <tqpainter.h>
23
24#include <tdelocale.h>
25
26#include "entities.h"
27#include "elementtype.h"
28#include "sequenceelement.h"
29#include "textelement.h"
30#include "glyphelement.h"
31#include "tokenelement.h"
32#include "identifierelement.h"
33#include "kformulacommand.h"
34#include "kformulacontainer.h"
35#include "kformuladocument.h"
36#include "formulaelement.h"
37#include "creationstrategy.h"
38
39KFORMULA_NAMESPACE_BEGIN
40
41TokenElement::TokenElement( BasicElement* parent ) : TokenStyleElement( parent ),
42 m_textOnly( true )
43{
44}
45
46int TokenElement::buildChildrenFromMathMLDom(TQPtrList<BasicElement>& list, TQDomNode n)
47{
48 while ( ! n.isNull() ) {
49 if ( n.isText() ) {
50 TQString textelements = n.toText().data();
51 textelements = textelements.stripWhiteSpace();
52
53 for (uint i = 0; i < textelements.length(); i++) {
54 TextElement* child = new TextElement(textelements[i]);
55 child->setParent(this);
56 child->setCharFamily( charFamily() );
57 child->setCharStyle( charStyle() );
58 list.append(child);
59 }
60 }
61 else if ( n.isEntityReference() ) {
62 TQString entity = n.toEntityReference().nodeName();
63 const entityMap* begin = entities;
64 const entityMap* end = entities + entityMap::size();
65 const entityMap* pos = std::lower_bound( begin, end, entity.ascii() );
66 if ( pos == end || TQString( pos->name ) != entity ) {
67 kdWarning() << "Invalid entity refererence: " << entity << endl;
68 }
69 else {
70 TextElement* child = new TextElement( TQChar( pos->unicode ) );
71 child->setParent(this);
72 child->setCharFamily( charFamily() );
73 child->setCharStyle( charStyle() );
74 list.append(child);
75 }
76 }
77 else if ( n.isElement() ) {
78 m_textOnly = false;
79 // Only mglyph element is allowed
80 TQDomElement e = n.toElement();
81 if ( e.tagName().lower() != "mglyph" ) {
82 kdWarning( DEBUGID ) << "Invalid element inside Token Element\n";
83 return -1;
84 }
85 GlyphElement* child = new GlyphElement();
86 child->setParent(this);
87 child->setCharFamily( charFamily() );
88 child->setCharStyle( charStyle() );
89 if ( child->buildFromMathMLDom( e ) == -1 ) {
90 return -1;
91 }
92 list.append( child );
93 }
94 else {
95 kdWarning() << "Invalid content in TokenElement\n";
96 }
97 n = n.nextSibling();
98 }
99// parse();
100 kdWarning() << "Num of children " << list.count() << endl;
101 return 1;
102}
103
104luPt TokenElement::getSpaceBefore( const ContextStyle& context,
106 double factor )
107{
108 if ( !context.isScript( tstyle ) ) {
109 return context.getMediumSpace( tstyle, factor );
110 }
111 return 0;
112}
113
114luPt TokenElement::getSpaceAfter( const ContextStyle& context,
116 double factor )
117{
118 if ( !context.isScript( tstyle ) ) {
119 return context.getThinSpace( tstyle, factor );
120 }
121 return 0;
122}
123
124KFORMULA_NAMESPACE_END
Basis of every formula element.
int buildFromMathMLDom(TQDomElement element)
Set this element attribute, build children and call their builFromMathMLDom.
Contains all the style information for the formela.
TextStyle
Textstyles like in TeX.
This class handles mathematical style attributes common to token elements, as explained in MathML Spe...