lib
symboltable.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qfile.h>
00023 #include <qregexp.h>
00024 #include <qstring.h>
00025 #include <qstringlist.h>
00026 #include <qtextstream.h>
00027 #include <qfontmetrics.h>
00028
00029 #include <kconfig.h>
00030 #include <kdebug.h>
00031 #include <kglobal.h>
00032 #include <klocale.h>
00033 #include <kstandarddirs.h>
00034
00035 #include "symboltable.h"
00036 #include "contextstyle.h"
00037 #include "unicodetable.cc"
00038
00039
00040 KFORMULA_NAMESPACE_BEGIN
00041
00042 #include "symbolfontmapping.cc"
00043
00044 SymbolFontHelper::SymbolFontHelper()
00045 : greek("abgdezhqiklmnxpvrstufjcywGDQLXPSUFYVW")
00046 {
00047 for ( uint i = 0; symbolMap[ i ].unicode != 0; i++ ) {
00048 compatibility[ symbolMap[ i ].pos ] = symbolMap[ i ].unicode;
00049 }
00050 }
00051
00052 QChar SymbolFontHelper::unicodeFromSymbolFont( QChar pos ) const
00053 {
00054 if ( compatibility.contains( pos ) ) {
00055 return compatibility[ pos.latin1() ];
00056 }
00057 return QChar::null;
00058 }
00059
00060
00061 SymbolTable::SymbolTable()
00062 {
00063 }
00064
00065
00066 void SymbolTable::init( const QFont& font )
00067 {
00068 backupFont = font;
00069 for ( int i=0; operatorTable[i].unicode != 0; ++i ) {
00070 names[QChar( operatorTable[i].unicode )] = get_name( operatorTable[i] );
00071 entries[get_name( operatorTable[i] )] = QChar( operatorTable[i].unicode );
00072 }
00073 for ( int i=0; arrowTable[i].unicode != 0; ++i ) {
00074 names[QChar( arrowTable[i].unicode )] = get_name( arrowTable[i] );
00075 entries[get_name( arrowTable[i] )] = QChar( arrowTable[i].unicode );
00076 }
00077 for ( int i=0; greekTable[i].unicode != 0; ++i ) {
00078 names[QChar( greekTable[i].unicode )] = get_name( greekTable[i] );
00079 entries[get_name( greekTable[i] )] = QChar( greekTable[i].unicode );
00080 }
00081 }
00082
00083 bool SymbolTable::contains(QString name) const
00084 {
00085 return entries.find( name ) != entries.end();
00086 }
00087
00088 QChar SymbolTable::unicode(QString name) const
00089 {
00090 return entries[ name ];
00091 }
00092
00093
00094 QString SymbolTable::name( QChar symbol ) const
00095 {
00096 return names[symbol];
00097 }
00098
00099 QFont SymbolTable::font( QChar symbol, const QFont& f ) const {
00100 QFontMetrics fm( f );
00101 if ( fm.inFont( symbol ) ) {
00102 return f;
00103 }
00104 return QFont("Arev Sans");
00105 }
00106
00107 CharClass SymbolTable::charClass( QChar symbol ) const
00108 {
00109 return ORDINARY;
00110
00111
00112 }
00113
00114
00115 QChar SymbolTable::unicodeFromSymbolFont( QChar pos ) const
00116 {
00117 return symbolFontHelper.unicodeFromSymbolFont( pos );
00118 }
00119
00120
00121 QString SymbolTable::greekLetters() const
00122 {
00123 return symbolFontHelper.greekLetters();
00124 }
00125
00126
00127 QStringList SymbolTable::allNames() const
00128 {
00129 QStringList list;
00130
00131 for ( int i=0; operatorTable[i].unicode != 0; ++i ) {
00132 list.append( get_name( operatorTable[i] ));
00133 }
00134 for ( int i=0; arrowTable[i].unicode != 0; ++i ) {
00135 list.append( get_name( arrowTable[i] ));
00136 }
00137 for ( int i=0; greekTable[i].unicode != 0; ++i ) {
00138 list.append( get_name( greekTable[i] ) );
00139 }
00140 return list;
00141 }
00142
00143
00144 QString SymbolTable::get_name( struct UnicodeNameTable entry ) const
00145 {
00146 if ( !*entry.name ) {
00147 return "U" + QString( "%1" ).arg( entry.unicode, 4, 16 ).upper();
00148 }
00149 return entry.name;
00150 }
00151
00152 KFORMULA_NAMESPACE_END
|