20#include <tqfontmetrics.h>
24#include "glyphelement.h"
26KFORMULA_NAMESPACE_BEGIN
31bool GlyphElement::readAttributesFromMathMLDom(
const TQDomElement& element )
38 m_fontFamily = element.attribute(
"fontfamily" );
39 if ( m_fontFamily.isNull() ) {
40 kdWarning( DEBUGID ) <<
"Required attribute fontfamily not found in glyph element\n";
43 TQString indexStr = element.attribute(
"index" );
44 if ( indexStr.isNull() ) {
45 kdWarning( DEBUGID ) <<
"Required attribute index not found in glyph element\n";
49 ushort index = indexStr.toUShort( &ok );
51 kdWarning( DEBUGID ) <<
"Invalid index value in glyph element\n";
54 m_char = TQChar( index );
56 m_alt = element.attribute(
"alt" );
57 if ( m_alt.isNull() ) {
58 kdWarning( DEBUGID ) <<
"Required attribute alt not found in glyph element\n";
63 FontStyle::testFont( missing, m_fontFamily.lower() );
64 m_hasFont = missing.isEmpty();
74void GlyphElement::calcSizes(
const ContextStyle& context,
76 ContextStyle::IndexStyle ,
77 StyleAttributes& style )
79 double factor = style.sizeFactor();
84 TQFont font( m_fontFamily );
85 font.setPointSizeFloat( context.layoutUnitPtToPt( mySize ) );
86 TQFontMetrics fm ( font );
87 bound = fm.boundingRect( m_char );
91 TQFont font( context.getDefaultFont() );
92 font.setPointSizeFloat( context.layoutUnitPtToPt( mySize ) );
93 TQFontMetrics fm ( font );
94 bound = fm.boundingRect( m_alt );
102 if ( getBaseline() == 0 ) {
112void GlyphElement::draw( TQPainter& painter,
const LuPixelRect& ,
115 ContextStyle::IndexStyle ,
116 StyleAttributes& style,
117 const LuPixelPoint& parentOrigin )
119 LuPixelPoint myPos( parentOrigin.x()+getX(), parentOrigin.y()+getY() );
123 double factor = style.sizeFactor();
129 painter.setPen( style.color() );
130 setCharStyle( style.charStyle() );
131 setCharFamily( style.charFamily() );
132 font = TQFont( m_fontFamily );
135 context.layoutUnitToPixelY( myPos.y() ),
137 context.layoutUnitToPixelY( getHeight() ),
138 style.background() );
141 painter.setPen( context.getErrorColor() );
142 font = context.getDefaultFont();
146 painter.setFont( font );
148 context.layoutUnitToPixelY( myPos.y()+getBaseline() ),
152void GlyphElement::writeMathMLAttributes( TQDomElement& element )
const
154 element.setAttribute(
"fontfamily", m_fontFamily );
155 element.setAttribute(
"index", m_char.unicode() );
156 element.setAttribute(
"alt", m_alt );
159KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML 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.
double layoutUnitToFontSize(int luSize, bool) const
Given the font size for the font in layout units, in pt (use pointSize()) this returns the font size ...
static double ptToLayoutUnitPt(double pt)
Not zoom dependent.
int layoutUnitToPixelX(int lupix) const
The "layout unit pixel" -> "[zoomed] view pixel" conversions.
An element that represents one char.