1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/* This file is part of the KDE project
Copyright (C) 2006 Alfredo Beaumont Sainz <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <algorithm>
#include <tqpainter.h>
#include <tdelocale.h>
#include "entities.h"
#include "elementtype.h"
#include "sequenceelement.h"
#include "textelement.h"
#include "glyphelement.h"
#include "tokenelement.h"
#include "identifierelement.h"
#include "kformulacommand.h"
#include "kformulacontainer.h"
#include "kformuladocument.h"
#include "formulaelement.h"
#include "creationstrategy.h"
KFORMULA_NAMESPACE_BEGIN
TokenElement::TokenElement( BasicElement* parent ) : TokenStyleElement( parent ),
m_textOnly( true )
{
}
int TokenElement::buildChildrenFromMathMLDom(TQPtrList<BasicElement>& list, TQDomNode n)
{
while ( ! n.isNull() ) {
if ( n.isText() ) {
TQString textelements = n.toText().data();
textelements = textelements.stripWhiteSpace();
for (uint i = 0; i < textelements.length(); i++) {
TextElement* child = new TextElement(textelements[i]);
child->setParent(this);
child->setCharFamily( charFamily() );
child->setCharStyle( charStyle() );
list.append(child);
}
}
else if ( n.isEntityReference() ) {
TQString entity = n.toEntityReference().nodeName();
const entityMap* begin = entities;
const entityMap* end = entities + entityMap::size();
const entityMap* pos = std::lower_bound( begin, end, entity.ascii() );
if ( pos == end || TQString( pos->name ) != entity ) {
kdWarning() << "Invalid entity refererence: " << entity << endl;
}
else {
TextElement* child = new TextElement( TQChar( pos->unicode ) );
child->setParent(this);
child->setCharFamily( charFamily() );
child->setCharStyle( charStyle() );
list.append(child);
}
}
else if ( n.isElement() ) {
m_textOnly = false;
// Only mglyph element is allowed
TQDomElement e = n.toElement();
if ( e.tagName().lower() != "mglyph" ) {
kdWarning( DEBUGID ) << "Invalid element inside Token Element\n";
return -1;
}
GlyphElement* child = new GlyphElement();
child->setParent(this);
child->setCharFamily( charFamily() );
child->setCharStyle( charStyle() );
if ( child->buildFromMathMLDom( e ) == -1 ) {
return -1;
}
list.append( child );
}
else {
kdWarning() << "Invalid content in TokenElement\n";
}
n = n.nextSibling();
}
// parse();
kdWarning() << "Num of children " << list.count() << endl;
return 1;
}
luPt TokenElement::getSpaceBefore( const ContextStyle& context,
ContextStyle::TextStyle tstyle,
double factor )
{
if ( !context.isScript( tstyle ) ) {
return context.getMediumSpace( tstyle, factor );
}
return 0;
}
luPt TokenElement::getSpaceAfter( const ContextStyle& context,
ContextStyle::TextStyle tstyle,
double factor )
{
if ( !context.isScript( tstyle ) ) {
return context.getThinSpace( tstyle, factor );
}
return 0;
}
KFORMULA_NAMESPACE_END
|