kformula/flake
GlyphElement.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "GlyphElement.h"
00021 #include "AttributeManager.h"
00022
00023 #include <KoXmlWriter.h>
00024 #include <KoXmlReader.h>
00025
00026 #include <QFontDatabase>
00027 #include <QFontMetricsF>
00028
00029 #include <kdebug.h>
00030
00031 GlyphElement::GlyphElement( BasicElement* parent ) : TokenElement( parent )
00032 {}
00033
00034 QRectF GlyphElement::renderToPath( const QString& raw, QPainterPath& path ) const
00035 {
00036 Q_UNUSED( raw )
00037 Q_UNUSED( path )
00038
00039 AttributeManager am;
00040 QString fontFamily = am.stringOf( "fontfamily", this );
00041 QFontDatabase db;
00042 QFont tmpFont;
00043
00044
00045 if( db.families().contains( fontFamily ) )
00046 {
00047 tmpFont.setFamily( fontFamily );
00048 path.addText( path.currentPosition(), tmpFont,
00049 QChar( am.stringOf( "index", this ).toInt() ) );
00050 QFontMetricsF fm(tmpFont);
00051 return fm.boundingRect(QChar( am.stringOf( "index", this ).toInt() ) );
00052 }
00053 else {
00054 path.addText( path.currentPosition(), font(), am.stringOf( "alt", this ) );
00055 QFontMetricsF fm(font());
00056 return fm.boundingRect(am.stringOf( "alt", this ));
00057 }
00058 }
00059
00060 ElementType GlyphElement::elementType() const
00061 {
00062 return Glyph;
00063 }
00064
00065 bool GlyphElement::readMathMLAttributes( const KoXmlElement& element )
00066 {
00067
00068 m_fontFamily = element.attribute( "fontfamily" );
00069 if ( m_fontFamily.isNull() ) {
00070 kWarning( DEBUGID ) << "Required attribute fontfamily not found in glyph element";
00071 return false;
00072 }
00073 QString indexStr = element.attribute( "index" );
00074 if ( indexStr.isNull() ) {
00075 kWarning( DEBUGID ) << "Required attribute index not found in glyph element";
00076 return false;
00077 }
00078 bool ok;
00079 ushort index = indexStr.toUShort( &ok );
00080 if ( ! ok ) {
00081 kWarning( DEBUGID ) << "Invalid index value in glyph element";
00082 return false;
00083 }
00084 m_char = QChar( index );
00085
00086 m_alt = element.attribute( "alt" );
00087 if ( m_alt.isNull() ) {
00088 kWarning( DEBUGID ) << "Required attribute alt not found in glyph element";
00089 return false;
00090 }
00091
00092
00093 return true;
00094 }
00095
00096 void GlyphElement::writeMathMLAttributes( KoXmlWriter* writer ) const
00097 {
00098 writer->addAttribute( "fontfamily", m_fontFamily );
00099 writer->addAttribute( "index", m_char.unicode() );
00100 writer->addAttribute( "alt", m_alt );
00101 }
00102
00103 void GlyphElement::writeMathMLContent( KoXmlWriter* writer ) const
00104 {
00105 Q_UNUSED( writer )
00106 }
|