lib

symboltable.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4 Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include <tqfile.h>
23#include <tqregexp.h>
24#include <tqstring.h>
25#include <tqstringlist.h>
26#include <tqtextstream.h>
27#include <tqfontmetrics.h>
28
29#include <tdeconfig.h>
30#include <kdebug.h>
31#include <tdeglobal.h>
32#include <tdelocale.h>
33#include <kstandarddirs.h>
34
35#include "symboltable.h"
36#include "contextstyle.h"
37#include "unicodetable.cpp"
38
39
40KFORMULA_NAMESPACE_BEGIN
41
42#include "symbolfontmapping.cpp"
43
44SymbolFontHelper::SymbolFontHelper()
45 : greek("abgdezhqiklmnxpvrstufjcywGDTQLXPSUFYVW")
46{
47 for ( uint i = 0; symbolMap[ i ].unicode != 0; i++ ) {
48 compatibility[ symbolMap[ i ].pos ] = symbolMap[ i ].unicode;
49 }
50}
51
53{
54 if ( compatibility.contains( pos ) ) {
55 return compatibility[ pos.latin1() ];
56 }
57 return TQChar::null;
58}
59
60
61SymbolTable::SymbolTable()
62{
63}
64
65
66void SymbolTable::init( const TQFont& font )
67{
68 backupFont = font;
69 for ( int i=0; operatorTable[i].unicode != 0; ++i ) {
70 names[TQChar( operatorTable[i].unicode )] = get_name( operatorTable[i] );
71 entries[get_name( operatorTable[i] )] = TQChar( operatorTable[i].unicode );
72 }
73 for ( int i=0; arrowTable[i].unicode != 0; ++i ) {
74 names[TQChar( arrowTable[i].unicode )] = get_name( arrowTable[i] );
75 entries[get_name( arrowTable[i] )] = TQChar( arrowTable[i].unicode );
76 }
77 for ( int i=0; greekTable[i].unicode != 0; ++i ) {
78 names[TQChar( greekTable[i].unicode )] = get_name( greekTable[i] );
79 entries[get_name( greekTable[i] )] = TQChar( greekTable[i].unicode );
80 }
81}
82
83bool SymbolTable::contains(TQString name) const
84{
85 return entries.find( name ) != entries.end();
86}
87
88TQChar SymbolTable::unicode(TQString name) const
89{
90 return entries[ name ];
91}
92
93
94TQString SymbolTable::name( TQChar symbol ) const
95{
96 return names[symbol];
97}
98
99TQFont SymbolTable::font( TQChar symbol, const TQFont& f ) const {
100 TQFontMetrics fm( f );
101 if ( fm.inFont( symbol ) ) {
102 return f;
103 }
104 return TQFont("Arev Sans");
105}
106
107CharClass SymbolTable::charClass( TQChar symbol ) const
108{
109 return ORDINARY;
110 // FIXME
111// return entry( symbol, style ).charClass();
112}
113
114
115TQChar SymbolTable::unicodeFromSymbolFont( TQChar pos ) const
116{
117 return symbolFontHelper.unicodeFromSymbolFont( pos );
118}
119
120
122{
123 return symbolFontHelper.greekLetters();
124}
125
126
127TQStringList SymbolTable::allNames() const
128{
129 TQStringList list;
130
131 for ( int i=0; operatorTable[i].unicode != 0; ++i ) {
132 list.append( get_name( operatorTable[i] ));
133 }
134 for ( int i=0; arrowTable[i].unicode != 0; ++i ) {
135 list.append( get_name( arrowTable[i] ));
136 }
137 for ( int i=0; greekTable[i].unicode != 0; ++i ) {
138 list.append( get_name( greekTable[i] ) );
139 }
140 return list;
141}
142
143
144TQString SymbolTable::get_name( struct UnicodeNameTable entry ) const
145{
146 if ( !*entry.name ) {
147 return "U" + TQString( "%1" ).arg( entry.unicode, 4, 16 ).upper();
148 }
149 return entry.name;
150}
151
152KFORMULA_NAMESPACE_END
TQChar unicodeFromSymbolFont(TQChar pos) const
void init(const TQFont &font)
lazy init support.
TQChar unicodeFromSymbolFont(TQChar pos) const
TQStringList allNames() const
TQString greekLetters() const
TQChar unicode(TQString name) const