summaryrefslogtreecommitdiffstats
path: root/lib/kformula/symboltable.h
blob: 99cebe46b2d7b47e03a6a2022ac85fc8d26f4121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* This file is part of the KDE project
   Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
	              Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
   Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>              

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef SYMBOLTABLE_H
#define SYMBOLTABLE_H

#include <tqfont.h>
#include <tqmap.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqvaluevector.h>

#include "kformuladefs.h"

class TDEConfig;

KFORMULA_NAMESPACE_BEGIN

class ContextStyle;
struct UnicodeNameTable;

/**
 * We expect to always have the symbol font.
 */
class SymbolFontHelper {
public:

    SymbolFontHelper();

    /**
     * @returns a string with all greek letters.
     */
    TQString greekLetters() const { return greek; }

    /**
     * @returns the unicode value of the symbol font char.
     */
    TQChar unicodeFromSymbolFont( TQChar pos ) const;

private:

    /**
     * symbol font char -> unicode mapping.
     */
    TQMap<TQChar, TQChar> compatibility;

    /**
     * All greek letters that are known.
     */
    TQString greek;
};


/**
 * The symbol table.
 *
 * It contains all names that are know to the system.
 */
class KOFORMULA_EXPORT SymbolTable {
public:

    SymbolTable();

    /**
     * lazy init support. Needs to be run before anything else.
     * @param install if true fonts may be installed if needed
     */
    void init( const TQFont& font );

    bool contains( TQString name ) const;

    /**
     * @returns the char in the symbol font that belongs to
     * the given name.
     */
    TQChar unicode( TQString name ) const;
    TQString name( TQChar symbol ) const;

    TQFont font( TQChar symbol, const TQFont& f ) const;

    CharClass charClass( TQChar symbol ) const;

    /**
     * @returns a string with all greek letters.
     */
    TQString greekLetters() const;

    /**
     * @returns the unicode value of the symbol font char.
     */
    TQChar unicodeFromSymbolFont( TQChar pos ) const;

    /**
     * @returns all known names as strings.
     */
    TQStringList allNames() const;

    typedef TQMap<TQChar, TQString> NameTable;
    typedef TQMap<TQString, TQChar> EntryTable;

private:

    TQString get_name( UnicodeNameTable entry ) const;

    /**
     * unicode -> name mapping.
     */
    NameTable names;

    /**
     * Name -> unicode mapping.
     */
    EntryTable entries;

    /**
     * Basic symbol font support.
     */
    SymbolFontHelper symbolFontHelper;

    /**
     * Backup font for mathematical operators. We ensure that every symbol in
     * this table is present in this font. If user selected font doesn't have
     * the needed glyph this font will be used instead.
     */
    TQFont backupFont;
};

KFORMULA_NAMESPACE_END

#endif // SYMBOLTABLE_H