lib
tokenelement.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <algorithm>
00021
00022 #include <qpainter.h>
00023
00024 #include <klocale.h>
00025
00026 #include "entities.h"
00027 #include "elementtype.h"
00028 #include "sequenceelement.h"
00029 #include "textelement.h"
00030 #include "glyphelement.h"
00031 #include "tokenelement.h"
00032 #include "identifierelement.h"
00033 #include "kformulacommand.h"
00034 #include "kformulacontainer.h"
00035 #include "kformuladocument.h"
00036 #include "formulaelement.h"
00037 #include "creationstrategy.h"
00038
00039 KFORMULA_NAMESPACE_BEGIN
00040
00041 TokenElement::TokenElement( BasicElement* parent ) : TokenStyleElement( parent ),
00042 m_textOnly( true )
00043 {
00044 }
00045
00046 int TokenElement::buildChildrenFromMathMLDom(QPtrList<BasicElement>& list, QDomNode n)
00047 {
00048 while ( ! n.isNull() ) {
00049 if ( n.isText() ) {
00050 QString textelements = n.toText().data();
00051 textelements = textelements.stripWhiteSpace();
00052
00053 for (uint i = 0; i < textelements.length(); i++) {
00054 TextElement* child = new TextElement(textelements[i]);
00055 child->setParent(this);
00056 child->setCharFamily( charFamily() );
00057 child->setCharStyle( charStyle() );
00058 list.append(child);
00059 }
00060 }
00061 else if ( n.isEntityReference() ) {
00062 QString entity = n.toEntityReference().nodeName();
00063 const entityMap* begin = entities;
00064 const entityMap* end = entities + entityMap::size();
00065 const entityMap* pos = std::lower_bound( begin, end, entity.ascii() );
00066 if ( pos == end || QString( pos->name ) != entity ) {
00067 kdWarning() << "Invalid entity refererence: " << entity << endl;
00068 }
00069 else {
00070 TextElement* child = new TextElement( QChar( pos->unicode ) );
00071 child->setParent(this);
00072 child->setCharFamily( charFamily() );
00073 child->setCharStyle( charStyle() );
00074 list.append(child);
00075 }
00076 }
00077 else if ( n.isElement() ) {
00078 m_textOnly = false;
00079
00080 QDomElement e = n.toElement();
00081 if ( e.tagName().lower() != "mglyph" ) {
00082 kdWarning( DEBUGID ) << "Invalid element inside Token Element\n";
00083 return -1;
00084 }
00085 GlyphElement* child = new GlyphElement();
00086 child->setParent(this);
00087 child->setCharFamily( charFamily() );
00088 child->setCharStyle( charStyle() );
00089 if ( child->buildFromMathMLDom( e ) == -1 ) {
00090 return -1;
00091 }
00092 list.append( child );
00093 }
00094 else {
00095 kdWarning() << "Invalid content in TokenElement\n";
00096 }
00097 n = n.nextSibling();
00098 }
00099
00100 kdWarning() << "Num of children " << list.count() << endl;
00101 return 1;
00102 }
00103
00104 luPt TokenElement::getSpaceBefore( const ContextStyle& context,
00105 ContextStyle::TextStyle tstyle,
00106 double factor )
00107 {
00108 if ( !context.isScript( tstyle ) ) {
00109 return context.getMediumSpace( tstyle, factor );
00110 }
00111 return 0;
00112 }
00113
00114 luPt TokenElement::getSpaceAfter( const ContextStyle& context,
00115 ContextStyle::TextStyle tstyle,
00116 double factor )
00117 {
00118 if ( !context.isScript( tstyle ) ) {
00119 return context.getThinSpace( tstyle, factor );
00120 }
00121 return 0;
00122 }
00123
00124 KFORMULA_NAMESPACE_END
|