22#include <tqfontmetrics.h>
27#include "basicelement.h"
28#include "contextstyle.h"
29#include "elementtype.h"
30#include "sequenceelement.h"
31#include "sequenceparser.h"
32#include "textelement.h"
35KFORMULA_NAMESPACE_BEGIN
37int ElementType::evilDestructionCount = 0;
43TQString format2variant( CharStyle style, CharFamily family )
52 result =
"normal";
break;
54 result =
"bold";
break;
56 result =
"italic";
break;
58 result =
"bold-italic";
break;
65 if ( style == boldChar || style == boldItalicChar )
66 result =
"bold-" + result;
70 if ( style == boldChar || style == boldItalicChar )
71 result =
"bold-" + result;
73 case doubleStruckFamily:
74 result =
"double-struck";
break;
81 : from( parser->getStart() ), to( parser->getEnd() ), prev( 0 )
83 evilDestructionCount++;
86ElementType::~ElementType()
89 evilDestructionCount--;
96 for ( uint i=
start(); i<
end(); ++i ) {
118luPt ElementType::getSpaceAfter( OperatorType*,
126luPt ElementType::getSpaceAfter( RelationType*,
134luPt ElementType::getSpaceAfter( PunctuationType*,
142luPt ElementType::getSpaceAfter( BracketType*,
150luPt ElementType::getSpaceAfter( ComplexElementType*,
158luPt ElementType::getSpaceAfter( InnerElementType*,
166luPt ElementType::thinSpaceIfNotScript(
const ContextStyle& context,
170 if ( !context.isScript( tstyle ) ) {
171 return context.getThinSpace( tstyle, factor );
176luPt ElementType::mediumSpaceIfNotScript(
const ContextStyle& context,
180 if ( !context.isScript( tstyle ) ) {
181 return context.getMediumSpace( tstyle, factor );
186luPt ElementType::thickSpaceIfNotScript(
const ContextStyle& context,
190 if ( !context.isScript( tstyle ) ) {
191 return context.getThickSpace( tstyle, factor );
199 return context.getDefaultFont();
204 painter.setPen(context.getDefaultColor());
209 element->prev =
this;
212void ElementType::output()
214 kdDebug( DEBUGID ) <<
start() <<
" - " <<
end() << endl;
217void ElementType::saveMathML(
SequenceElement* se, TQDomDocument& doc, TQDomElement de,
bool oasisFormat )
219 for ( uint i = from; i < to; ++i ) {
232 if ( parser->getTokenType() == END ) {
236 if ( nextType == 0 ) {
246SequenceType::~SequenceType()
252void SequenceType::output()
260 for ( uint i =
start(); i <
end(); i++ ) {
263 m_text = parser->
text();
271 if ( getPrev() != 0 ) {
272 return getPrev()->getSpaceAfter(
this, context, tstyle, factor );
277luPt MultiElementType::getSpaceAfter( OperatorType*,
282 return mediumSpaceIfNotScript( context, tstyle, factor );
285luPt MultiElementType::getSpaceAfter( RelationType*,
290 return thickSpaceIfNotScript( context, tstyle, factor );
293luPt MultiElementType::getSpaceAfter( InnerElementType*,
298 return thinSpaceIfNotScript( context, tstyle, factor );
307void TextType::saveMathML(
SequenceElement* se, TQDomDocument& doc, TQDomElement de,
bool oasisFormat )
309 for ( uint i =
start(); i <
end(); ++i ) {
310 TQDomElement
text = doc.createElement( oasisFormat ?
"math:mi" :
"mi" );
313 TQString mathvariant = format2variant( te->getCharStyle(), te->getCharFamily());
314 if ( !mathvariant.isNull() )
315 text.setAttribute(
"mathvariant", mathvariant );
319 de.appendChild(
text );
320 if ( i !=
end() - 1 ) {
321 TQDomElement op = doc.createElement( oasisFormat ?
"math:mo" :
"mo" );
322 op.appendChild( doc.createEntityReference(
"InvisibleTimes" ) );
323 de.appendChild( op );
334void NameType::saveMathML(
SequenceElement* se, TQDomDocument& doc, TQDomElement de,
bool oasisFormat )
353 return context.getNameFont();
363 return context.getNumberFont();
368 painter.setPen(context.getNumberColor());
371void NumberType::saveMathML(
SequenceElement* se, TQDomDocument& doc, TQDomElement de,
bool oasisFormat )
373 TQDomElement name = doc.createElement( oasisFormat ?
"math:mn" :
"mn" );
375 for ( uint i =
start(); i <
end(); ++i ) {
380 TQString mathvariant = format2variant( te->getCharStyle(), te->getCharFamily() );
381 if ( !mathvariant.isNull() )
382 name.setAttribute(
"mathvariant", mathvariant );
384 name.appendChild( doc.createTextNode( value ) );
385 de.appendChild( name );
395AbstractOperatorType::AbstractOperatorType(
SequenceParser* parser )
400void AbstractOperatorType::saveMathML(
SequenceElement* se, TQDomDocument& doc, TQDomElement de,
bool oasisFormat )
402 TQDomElement op = doc.createElement( oasisFormat ?
"math:mo" :
"mo" );
406 op.appendChild( doc.createTextNode( be->
getCharacter() ) );
411 op.appendChild( doc.createEntityReference( s.sprintf(
"#x%05X", be->
getCharacter().unicode() ) ) );
414 TQString mathvariant = format2variant( te->getCharStyle(), te->getCharFamily() );
415 if ( !mathvariant.isNull() )
416 op.setAttribute(
"mathvariant", mathvariant );
418 de.appendChild( op );
422 : AbstractOperatorType( parser )
426luPt OperatorType::getSpaceBefore(
const ContextStyle& context,
430 if ( getPrev() != 0 ) {
431 return getPrev()->getSpaceAfter(
this, context, tstyle, factor );
441 return mediumSpaceIfNotScript( context, tstyle, factor );
444luPt OperatorType::getSpaceAfter( BracketType*,
449 return mediumSpaceIfNotScript( context, tstyle, factor );
452luPt OperatorType::getSpaceAfter( ComplexElementType*,
457 return mediumSpaceIfNotScript( context, tstyle, factor );
460luPt OperatorType::getSpaceAfter( InnerElementType*,
465 return mediumSpaceIfNotScript( context, tstyle, factor );
469TQFont OperatorType::getFont(
const ContextStyle& context)
471 return context.getOperatorFont();
474void OperatorType::setUpPainter(
const ContextStyle& context, TQPainter& painter)
476 painter.setPen(context.getOperatorColor());
481 : AbstractOperatorType( parser )
485luPt RelationType::getSpaceBefore(
const ContextStyle& context,
489 if ( getPrev() != 0 ) {
490 return getPrev()->getSpaceAfter(
this, context, tstyle, factor );
500 return thickSpaceIfNotScript( context, tstyle, factor );
503luPt RelationType::getSpaceAfter( BracketType*,
508 return thickSpaceIfNotScript( context, tstyle, factor );
511luPt RelationType::getSpaceAfter( ComplexElementType*,
516 return thickSpaceIfNotScript( context, tstyle, factor );
519luPt RelationType::getSpaceAfter( InnerElementType*,
524 return thickSpaceIfNotScript( context, tstyle, factor );
527TQFont RelationType::getFont(
const ContextStyle& context )
529 return context.getOperatorFont();
532void RelationType::setUpPainter(
const ContextStyle& context, TQPainter& painter )
534 painter.setPen(context.getOperatorColor());
540 : AbstractOperatorType( parser )
544luPt PunctuationType::getSpaceBefore(
const ContextStyle& context,
548 if ( getPrev() != 0 ) {
549 return getPrev()->getSpaceAfter(
this, context, tstyle, factor );
559 return thinSpaceIfNotScript( context, tstyle, factor );
562luPt PunctuationType::getSpaceAfter( RelationType*,
567 return thickSpaceIfNotScript( context, tstyle, factor );
570luPt PunctuationType::getSpaceAfter( PunctuationType*,
575 return thinSpaceIfNotScript( context, tstyle, factor );
578luPt PunctuationType::getSpaceAfter( BracketType*,
583 return thinSpaceIfNotScript( context, tstyle, factor );
586luPt PunctuationType::getSpaceAfter( ComplexElementType*,
591 return thinSpaceIfNotScript( context, tstyle, factor );
594luPt PunctuationType::getSpaceAfter( InnerElementType*,
599 return thinSpaceIfNotScript( context, tstyle, factor );
602TQFont PunctuationType::getFont(
const ContextStyle& context )
604 return context.getOperatorFont();
607void PunctuationType::setUpPainter(
const ContextStyle& context, TQPainter& painter )
609 painter.setPen( context.getDefaultColor() );
618luPt BracketType::getSpaceBefore(
const ContextStyle& context,
622 if ( getPrev() != 0 ) {
623 return getPrev()->getSpaceAfter(
this, context, tstyle, factor );
628luPt BracketType::getSpaceAfter( OperatorType*,
633 return mediumSpaceIfNotScript( context, tstyle, factor );
636luPt BracketType::getSpaceAfter( RelationType*,
641 return thickSpaceIfNotScript( context, tstyle, factor );
644luPt BracketType::getSpaceAfter( InnerElementType*,
649 return thinSpaceIfNotScript( context, tstyle, factor );
658luPt ComplexElementType::getSpaceBefore(
const ContextStyle& context,
662 if ( getPrev() != 0 ) {
663 return getPrev()->getSpaceAfter(
this, context, tstyle, factor );
668luPt ComplexElementType::getSpaceAfter( OperatorType*,
673 return mediumSpaceIfNotScript( context, tstyle, factor );
676luPt ComplexElementType::getSpaceAfter( RelationType*,
681 return thickSpaceIfNotScript( context, tstyle, factor );
684luPt ComplexElementType::getSpaceAfter( InnerElementType*,
689 return thinSpaceIfNotScript( context, tstyle, factor );
698luPt InnerElementType::getSpaceBefore(
const ContextStyle& context,
702 if ( getPrev() != 0 ) {
703 return getPrev()->getSpaceAfter(
this, context, tstyle, factor );
713 return thinSpaceIfNotScript( context, tstyle, factor );
716luPt InnerElementType::getSpaceAfter( OperatorType*,
721 return mediumSpaceIfNotScript( context, tstyle, factor );
724luPt InnerElementType::getSpaceAfter( RelationType*,
729 return thickSpaceIfNotScript( context, tstyle, factor );
732luPt InnerElementType::getSpaceAfter( PunctuationType*,
737 return thinSpaceIfNotScript( context, tstyle, factor );
740luPt InnerElementType::getSpaceAfter( BracketType*,
745 return thinSpaceIfNotScript( context, tstyle, factor );
748luPt InnerElementType::getSpaceAfter( ComplexElementType*,
753 return thinSpaceIfNotScript( context, tstyle, factor );
756luPt InnerElementType::getSpaceAfter( InnerElementType*,
761 return thinSpaceIfNotScript( context, tstyle, factor );
765KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual TQChar getCharacter() const
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.
Contains all the style information for the formela.
TextStyle
Textstyles like in TeX.
virtual TQFont getFont(const ContextStyle &context)
virtual TQString text(SequenceElement *seq) const
void append(ElementType *)
Adds a type at the end of the list.
virtual luPt getSpaceBefore(const ContextStyle &context, ContextStyle::TextStyle tstyle, double factor)
virtual void setUpPainter(const ContextStyle &context, TQPainter &painter)
sets the painters pen to a appropriate value
Basis for all tokens that run along several elements.
virtual luPt getSpaceBefore(const ContextStyle &context, ContextStyle::TextStyle tstyle, double factor)
virtual TQString text(SequenceElement *) const
virtual TQFont getFont(const ContextStyle &context)
virtual void setUpPainter(const ContextStyle &context, TQPainter &painter)
sets the painters pen to a appropriate value
virtual TQFont getFont(const ContextStyle &context)
The element that contains a number of children.
virtual BasicElement * getChild(FormulaCursor *, Direction=beforeCursor)
Returns the child at the cursor.
The parser that gets the element list and returns a syntax tree.
void nextToken()
Reads the next token.
ElementType * getPrimitive()
void setElementType(uint pos, ElementType *type)
Tells the element about its new type.
Basis for all tokens that consist of one element only.
An element that represents one char.
const char * name(StdAction id)