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 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qfile.h>
00022 #include <qregexp.h>
00023 #include <qstring.h>
00024 #include <qstringlist.h>
00025 #include <qtextstream.h>
00026 
00027 #include <kconfig.h>
00028 #include <kdebug.h>
00029 #include <kglobal.h>
00030 #include <klocale.h>
00031 #include <kstandarddirs.h>
00032 
00033 #include "symboltable.h"
00034 #include "contextstyle.h"
00035 
00036 
00037 KFORMULA_NAMESPACE_BEGIN
00038 
00039 /* -- moved to "symbolfontstyle.cc" to have access to the symbolMap.
00040 SymbolFontHelper::SymbolFontHelper()
00041     : greek("abgdezhqiklmnxpvrstufjcywGDQLXPSUFYVW")
00042 {
00043     for ( uint i = 0; symbolMap[ i ].unicode != 0; i++ ) {
00044         compatibility[ symbolMap[ i ].pos ] = symbolMap[ i ].unicode;
00045     }
00046 }
00047 */
00048 
00049 QChar SymbolFontHelper::unicodeFromSymbolFont( QChar pos ) const
00050 {
00051     if ( compatibility.contains( pos ) ) {
00052         return compatibility[ pos.latin1() ];
00053     }
00054     return QChar::null;
00055 }
00056 
00057 
00058 SymbolTable::SymbolTable()
00059 {
00060 }
00061 
00062 
00063 void SymbolTable::init( ContextStyle* /*context*/ )
00064 {
00065     normalChars.clear();
00066     boldChars.clear();
00067     italicChars.clear();
00068     boldItalicChars.clear();
00069     entries.clear();
00070     fontTable.clear();
00071 }
00072 
00073 
00074 void SymbolTable::initFont( const InternFontTable* table,
00075                             const char* fontname,
00076                             const NameTable& tempNames )
00077 {
00078     uint fontnr = fontTable.size();
00079     fontTable.push_back( QFont( fontname ) );
00080     for ( uint i = 0; table[ i ].unicode != 0; ++i ) {
00081         QChar uc = table[ i ].unicode;
00082         unicodeTable( table[ i ].style )[ uc ] =
00083             CharTableEntry( table[ i ].cl,
00084                             static_cast<char>( fontnr ),
00085                             table[ i ].pos );
00086 
00087         if ( tempNames.contains( uc ) ) {
00088             entries[ tempNames[uc] ] = uc;
00089             names[uc] = tempNames[uc];
00090         }
00091     }
00092 }
00093 
00094 
00095 bool SymbolTable::contains(QString name) const
00096 {
00097     return entries.find( name ) != entries.end();
00098 }
00099 
00100 QChar SymbolTable::unicode(QString name) const
00101 {
00102     return entries[ name ];
00103 }
00104 
00105 
00106 QString SymbolTable::name( QChar symbol ) const
00107 {
00108     return names[symbol];
00109 }
00110 
00111 
00112 const CharTableEntry& SymbolTable::entry( QChar symbol, CharStyle style ) const
00113 {
00114     const UnicodeTable& table = unicodeTable( style );
00115     if ( table.contains( symbol ) ) {
00116         return table[symbol];
00117     }
00118     if ( ( style != normalChar ) && ( style != anyChar ) ) {
00119         if ( normalChars.contains( symbol ) ) {
00120             return normalChars[symbol];
00121         }
00122     }
00123     if ( style != boldChar ) {
00124         if ( boldChars.contains( symbol ) ) {
00125             return boldChars[symbol];
00126         }
00127     }
00128     if ( style != italicChar ) {
00129         if ( italicChars.contains( symbol ) ) {
00130             return italicChars[symbol];
00131         }
00132     }
00133     if ( style != boldItalicChar ) {
00134         if ( boldItalicChars.contains( symbol ) ) {
00135             return boldItalicChars[symbol];
00136         }
00137     }
00138     return dummyEntry;
00139 }
00140 
00141 
00142 QFont SymbolTable::font( QChar symbol, CharStyle style ) const
00143 {
00144     char f = entry( symbol, style ).font();
00145     return fontTable[f];
00146 }
00147 
00148 
00149 QChar SymbolTable::character( QChar symbol, CharStyle style ) const
00150 {
00151     return entry( symbol, style ).character();
00152 }
00153 
00154 
00155 CharClass SymbolTable::charClass( QChar symbol, CharStyle style ) const
00156 {
00157     return entry( symbol, style ).charClass();
00158 }
00159 
00160 
00161 QChar SymbolTable::unicodeFromSymbolFont( QChar pos ) const
00162 {
00163     return symbolFontHelper.unicodeFromSymbolFont( pos );
00164 }
00165 
00166 
00167 QString SymbolTable::greekLetters() const
00168 {
00169     return symbolFontHelper.greekLetters();
00170 }
00171 
00172 
00173 QStringList SymbolTable::allNames() const
00174 {
00175     QStringList list;
00176 
00177     for ( EntryTable::const_iterator iter = entries.begin();
00178           iter != entries.end();
00179           ++iter ) {
00180         if ( QChar( character( iter.data() ) ) != QChar::null ) {
00181             list.append( iter.key() );
00182         }
00183     }
00184     list.sort();
00185     return list;
00186 }
00187 
00188 
00189 bool SymbolTable::inTable( QChar ch, CharStyle style ) const
00190 {
00191     if ( style == anyChar ) {
00192         return normalChars.contains( ch ) ||
00193             boldChars.contains( ch ) ||
00194             italicChars.contains( ch ) ||
00195             boldItalicChars.contains( ch );
00196     }
00197     return unicodeTable( style ).contains( ch );
00198 }
00199 
00200 
00201 SymbolTable::UnicodeTable& SymbolTable::unicodeTable( CharStyle style )
00202 {
00203     switch ( style ) {
00204     case boldChar: return boldChars;
00205     case italicChar: return italicChars;
00206     case boldItalicChar: return boldItalicChars;
00207     default: break;
00208     }
00209     return normalChars;
00210 }
00211 
00212 const SymbolTable::UnicodeTable& SymbolTable::unicodeTable( CharStyle style ) const
00213 {
00214     switch ( style ) {
00215     case boldChar: return boldChars;
00216     case italicChar: return italicChars;
00217     case boldItalicChar: return boldItalicChars;
00218     default: break;
00219     }
00220     return normalChars;
00221 }
00222 
00223 
00224 KFORMULA_NAMESPACE_END
KDE Home | KDE Accessibility Home | Description of Access Keys