diff options
| author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
|---|---|---|
| committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
| commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
| tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kformula/tokenelement.cc | |
| download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip | |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kformula/tokenelement.cc')
| -rw-r--r-- | lib/kformula/tokenelement.cc | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/lib/kformula/tokenelement.cc b/lib/kformula/tokenelement.cc new file mode 100644 index 000000000..6c849e9c9 --- /dev/null +++ b/lib/kformula/tokenelement.cc @@ -0,0 +1,124 @@ +/* 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> + +#include <qpainter.h> + +#include <klocale.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(QPtrList<BasicElement>& list, QDomNode n) +{ + while ( ! n.isNull() ) { + if ( n.isText() ) { + QString 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() ) { + QString 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 || QString( pos->name ) != entity ) { + kdWarning() << "Invalid entity refererence: " << entity << endl; + } + else { + TextElement* child = new TextElement( QChar( 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 + QDomElement 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 |
