lib

symboltable.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                   Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004    Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
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     // FIXME
00111 //    return entry( symbol, style ).charClass();
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
KDE Home | KDE Accessibility Home | Description of Access Keys