You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.3 KiB
125 lines
4.3 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
|
||
|
|
||
|
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>
|
||
|
|
||
14 years ago
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
|
#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
|
||
|
|
||
13 years ago
|
TokenElement::TokenElement( BasicElement* parent ) : TokenStyleElement( parent ),
|
||
15 years ago
|
m_textOnly( true )
|
||
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
int TokenElement::buildChildrenFromMathMLDom(TQPtrList<BasicElement>& list, TQDomNode n)
|
||
15 years ago
|
{
|
||
|
while ( ! n.isNull() ) {
|
||
|
if ( n.isText() ) {
|
||
14 years ago
|
TQString textelements = n.toText().data();
|
||
15 years ago
|
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() ) {
|
||
14 years ago
|
TQString entity = n.toEntityReference().nodeName();
|
||
15 years ago
|
const entityMap* begin = entities;
|
||
|
const entityMap* end = entities + entityMap::size();
|
||
|
const entityMap* pos = std::lower_bound( begin, end, entity.ascii() );
|
||
14 years ago
|
if ( pos == end || TQString( pos->name ) != entity ) {
|
||
15 years ago
|
kdWarning() << "Invalid entity refererence: " << entity << endl;
|
||
|
}
|
||
|
else {
|
||
13 years ago
|
TextElement* child = new TextElement( TQChar( pos->unicode ) );
|
||
15 years ago
|
child->setParent(this);
|
||
|
child->setCharFamily( charFamily() );
|
||
|
child->setCharStyle( charStyle() );
|
||
|
list.append(child);
|
||
|
}
|
||
|
}
|
||
|
else if ( n.isElement() ) {
|
||
|
m_textOnly = false;
|
||
|
// Only mglyph element is allowed
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
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();
|
||
13 years ago
|
kdWarning() << "Num of children " << list.count() << endl;
|
||
15 years ago
|
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
|