]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
enable direct input of #1...#9; some whitespace changes
[lyx.git] / src / mathed / math_charinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include <cctype>
8
9 #include "math_charinset.h"
10 #include "LColor.h"
11 #include "Painter.h"
12 #include "support/LOstream.h"
13 #include "math_support.h"
14 #include "math_parser.h"
15 #include "debug.h"
16 #include "math_mathmlstream.h"
17
18
19 MathCharInset::MathCharInset(char c)
20         : char_(c), code_(nativeCode(c))
21 {
22 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
23 }
24
25
26 MathCharInset::MathCharInset(char c, MathTextCodes t)
27         : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
28 {
29 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
30 }
31
32
33 MathTextCodes MathCharInset::nativeCode(char c)
34 {
35         if (isalpha(c))
36                 return LM_TC_VAR;
37         //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
38         return LM_TC_CONST;
39 }
40
41
42 MathInset * MathCharInset::clone() const
43 {   
44         return new MathCharInset(*this);
45 }
46
47
48 int MathCharInset::ascent() const
49 {
50         return mathed_char_ascent(code_, mi_, char_);
51 }
52
53
54 int MathCharInset::descent() const
55 {
56         return mathed_char_descent(code_, mi_, char_);
57 }
58
59
60 int MathCharInset::width() const
61 {
62         return mathed_char_width(code_, mi_, char_);
63 }
64
65
66 void MathCharInset::metrics(MathMetricsInfo const & mi) const
67 {
68         mi_ = mi;
69 }
70
71
72 void MathCharInset::draw(Painter & pain, int x, int y) const
73
74         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
75         drawChar(pain, code_, mi_, x, y, char_);
76 }
77
78
79 void MathCharInset::writeHeader(std::ostream & os) const
80 {
81         if (math_font_name(code_))
82                 os << '\\' << math_font_name(code_) << '{';
83 }
84
85
86 void MathCharInset::writeTrailer(std::ostream & os) const
87 {
88         if (math_font_name(code_))
89                 os << '}';
90 }
91
92
93 void MathCharInset::writeRaw(std::ostream & os) const
94 {
95         os << char_;
96 }
97
98
99 void MathCharInset::write(WriteStream & os) const
100 {
101         writeHeader(os.os());
102         writeRaw(os.os());
103         writeTrailer(os.os());
104 }
105
106
107 void MathCharInset::normalize(NormalStream & os) const
108 {
109         os << "[char " << char_ << " " << "mathalpha" << "]";
110 }
111
112
113 bool MathCharInset::isRelOp() const
114 {
115         return char_ == '=' || char_ == '<' || char_ == '>';
116 }
117
118
119 void MathCharInset::handleFont(MathTextCodes t)
120 {
121         code_ = (code_ == t) ? LM_TC_VAR : t;
122 }
123
124
125 bool MathCharInset::match(MathInset * p) const
126 {
127         MathCharInset const * q = p->asCharInset();
128         return q && char_ == q->char_ && code_ == q->code_;
129 }