21#include <tqfontmetrics.h>
26#include "basicelement.h"
27#include "contextstyle.h"
28#include "elementtype.h"
29#include "elementvisitor.h"
31#include "formulaelement.h"
32#include "kformulacommand.h"
33#include "sequenceelement.h"
34#include "symboltable.h"
35#include "textelement.h"
38KFORMULA_NAMESPACE_BEGIN
40TextElement::TextElement(TQChar ch,
bool beSymbol,
BasicElement* parent)
44 charFamily( anyFamily );
50 character( other.character ),
51 symbol( other.symbol ),
52 m_format( other.m_format )
59 return visitor->visit(
this );
66 return getSymbolTable().charClass( character );
69 switch ( character.unicode() ) {
88 if ( character.isNumber() ) {
113 ContextStyle::IndexStyle ,
114 StyleAttributes& style )
116 double factor = style.sizeFactor();
119 setCharStyle( style.charStyle() );
120 setCharFamily( style.charFamily() );
122 TQFont font =
getFont( context, style );
123 double fontsize = context.layoutUnitPtToPt( mySize );
124 double scriptsize = pow( style.scriptSizeMultiplier(), style.scriptLevel() );
125 double size = fontsize * scriptsize;
126 font.setPointSizeFloat( size < style.scriptMinSize() ? style.scriptMinSize() : size );
128 TQFontMetrics fm( font );
129 if ( character == applyFunctionChar || character == invisibleTimes || character == invisibleComma ) {
132 setBaseline( getHeight() );
136 if ( ch == TQChar::null ) {
137 setWidth( tqRound( context.getEmptyRectWidth( factor ) * 2./3. ) );
138 setHeight( tqRound( context.getEmptyRectHeight( factor ) * 2./3. ) );
139 setBaseline( getHeight() );
142 TQRect bound = fm.boundingRect( ch );
149 if ( getBaseline() == 0 ) {
165 ContextStyle::IndexStyle ,
166 StyleAttributes& style,
167 const LuPixelPoint& parentOrigin )
169 if ( character == applyFunctionChar || character == invisibleTimes || character == invisibleComma ) {
173 LuPixelPoint myPos( parentOrigin.x()+getX(), parentOrigin.y()+getY() );
179 painter.setPen( style.color() );
181 setCharStyle( style.charStyle() );
182 setCharFamily( style.charFamily() );
184 double factor = style.sizeFactor();
186 TQFont font =
getFont( context, style );
187 double fontsize = context.layoutUnitPtToPt( mySize );
188 double scriptsize = pow( style.scriptSizeMultiplier(), style.scriptLevel() );
189 double size = fontsize * scriptsize;
190 font.setPointSizeFloat( size < style.scriptMinSize() ? style.scriptMinSize() : size );
191 painter.setFont( font );
220 if ( ch != TQChar::null ) {
221 luPixel bl = getBaseline();
227 bl = -( getHeight()/2 + context.axisHeight( tstyle, factor ) );
230 context.layoutUnitToPixelY( myPos.y()+bl ),
234 painter.setPen( TQPen( context.getErrorColor(),
237 context.layoutUnitToPixelY( myPos.y() ),
239 context.layoutUnitToPixelY( getHeight() ) );
263void TextElement::setCharStyle( CharStyle cs )
269void TextElement::setCharFamily( CharFamily cf )
301 const FontStyle& fontStyle = context.fontStyle();
303 if ( style.customFont() ) {
310 font = context.getDefaultFont();
312 switch ( charStyle() ) {
314 font.setItalic(
false );
315 font.setBold(
false );
318 font.setItalic(
false );
319 font.setBold(
false );
322 font.setItalic(
false );
323 font.setBold(
true );
326 font.setItalic(
true );
327 font.setBold(
false );
330 font.setItalic(
true );
331 font.setBold(
true );
334 return fontStyle.
symbolTable()->font( character, font );
344 painter.setPen(TQt::red);
348const SymbolTable& TextElement::getSymbolTable()
const
356 parent.appendChild( doc.createTextNode(
getCharacter() ) );
365 element.setAttribute(
"CHAR", TQString(character));
368 if (symbol) element.setAttribute(
"SYMBOL",
"3");
370 switch ( charStyle() ) {
372 case normalChar: element.setAttribute(
"STYLE",
"normal");
break;
373 case boldChar: element.setAttribute(
"STYLE",
"bold");
break;
374 case italicChar: element.setAttribute(
"STYLE",
"italic");
break;
375 case boldItalicChar: element.setAttribute(
"STYLE",
"bolditalic");
break;
378 switch ( charFamily() ) {
379 case normalFamily: element.setAttribute(
"FAMILY",
"normal");
break;
380 case scriptFamily: element.setAttribute(
"FAMILY",
"script");
break;
381 case frakturFamily: element.setAttribute(
"FAMILY",
"fraktur");
break;
382 case doubleStruckFamily: element.setAttribute(
"FAMILY",
"doublestruck");
break;
383 case anyFamily:
break;
396 TQString charStr = element.attribute(
"CHAR");
397 if(!charStr.isNull()) {
398 character = charStr.at(0);
400 TQString symbolStr = element.attribute(
"SYMBOL");
401 if(!symbolStr.isNull()) {
402 int symbolInt = symbolStr.toInt();
403 if ( symbolInt == 1 ) {
406 if ( symbolInt == 2 ) {
407 switch ( character.unicode() ) {
408 case 0x03D5: character = 0x03C6;
break;
409 case 0x03C6: character = 0x03D5;
break;
410 case 0x03Ba: character = 0x03BA;
break;
411 case 0x00B4: character = 0x2032;
break;
412 case 0x2215: character = 0x2244;
break;
413 case 0x00B7: character = 0x2022;
break;
414 case 0x1D574: character = 0x2111;
break;
415 case 0x1D579: character = 0x211C;
break;
416 case 0x2219: character = 0x22C5;
break;
417 case 0x2662: character = 0x26C4;
break;
418 case 0x220B: character = 0x220D;
break;
419 case 0x224C: character = 0x2245;
break;
420 case 0x03DB: character = 0x03C2;
break;
423 symbol = symbolInt != 0;
426 TQString styleStr = element.attribute(
"STYLE");
427 if ( styleStr ==
"normal" ) {
428 charStyle( normalChar );
430 else if ( styleStr ==
"bold" ) {
431 charStyle( boldChar );
433 else if ( styleStr ==
"italic" ) {
434 charStyle( italicChar );
436 else if ( styleStr ==
"bolditalic" ) {
437 charStyle( boldItalicChar );
440 charStyle( anyChar );
443 TQString familyStr = element.attribute(
"FAMILY" );
444 if ( familyStr ==
"normal" ) {
445 charFamily( normalFamily );
447 else if ( familyStr ==
"script" ) {
448 charFamily( scriptFamily );
450 else if ( familyStr ==
"fraktur" ) {
451 charFamily( frakturFamily );
453 else if ( familyStr ==
"doublestruck" ) {
454 charFamily( doubleStruckFamily );
457 charFamily( anyFamily );
480 TQString texName = getSymbolTable().name( character );
481 if ( !texName.isNull() )
482 return " \\" + texName +
" ";
486 return TQString(character);
490TQString TextElement::formulaString()
493 TQString texName = getSymbolTable().name( character );
494 if ( !texName.isNull() )
495 return " " + texName +
" ";
517 return visitor->visit(
this );
523 ContextStyle::IndexStyle ,
524 StyleAttributes& style )
529 TQFont font = context.getDefaultFont();
530 font.setPointSizeFloat( context.layoutUnitPtToPt( mySize ) );
532 TQFontMetrics fm( font );
534 TQRect bound = fm.boundingRect( ch );
543 ContextStyle::IndexStyle ,
545 const LuPixelPoint& parentOrigin )
547 LuPixelPoint myPos( parentOrigin.x()+getX(), parentOrigin.y()+getY() );
553 if ( context.edit() ) {
554 painter.setPen( context.getHelpColor() );
556 context.layoutUnitToPixelY( myPos.y() ),
558 context.layoutUnitToPixelY( myPos.y()+getHeight() ) );
567KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual FormulaElement * formula()
Provide fast access to the rootElement for each child.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
ElementType * getElementType() const
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
Contains all the style information for the formela.
luPt getAdjustedSize(TextStyle tstyle, double factor) const
Calculates the font size corresponding to the given TextStyle.
TextStyle
Textstyles like in TeX.
luPixel getLineWidth(double factor) const
All simple lines like the one that makes up a fraction.
virtual TQFont getFont(const ContextStyle &context)
virtual bool isInvisible(const TextElement &) const
virtual void setUpPainter(const ContextStyle &context, TQPainter &painter)
sets the painters pen to a appropriate value
An element that represents an empty box.
virtual void calcSizes(const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
virtual void draw(TQPainter &painter, const LuPixelRect &r, const ContextStyle &context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style, const LuPixelPoint &parentOrigin)
Draws the whole element including its children.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual TQString toLatex()
Base for all font commands that act on the current selection.
void addTextElement(TextElement *element)
Collects all elements that are to be modified.
Base class for all supported font styles.
const SymbolTable * symbolTable() const
the table for ordinary symbols (those that have a unicode value)
static double ptToLayoutUnitPt(double pt)
Not zoom dependent.
int layoutUnitToPixelX(int lupix) const
The "layout unit pixel" -> "[zoomed] view pixel" conversions.
TQChar unicodeFromSymbolFont(TQChar pos) const
An element that represents one char.
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
void setUpPainter(const ContextStyle &context, TQPainter &painter)
Sets up the painter to be used for drawing.
virtual bool isInvisible() const
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.
virtual TQString toLatex()
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual TQChar getCharacter() const
TQChar getRealCharacter(const ContextStyle &context)
bool isSymbol() const
Moves the cursor away from the given child.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual TokenType getTokenType() const
virtual void draw(TQPainter &painter, const LuPixelRect &r, const ContextStyle &context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style, const LuPixelPoint &parentOrigin)
Draws the whole element including its children.
virtual void calcSizes(const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
TQFont getFont(const ContextStyle &context, const StyleAttributes &style)