]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
new parser
[lyx.git] / src / mathed / math_charinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include <cctype>
6
7 #include "math_charinset.h"
8 #include "LColor.h"
9 #include "Painter.h"
10 #include "support/LOstream.h"
11 #include "mathed/support.h"
12 #include "math_parser.h"
13 #include "debug.h"
14
15
16 MathCharInset::MathCharInset(char c)
17         : char_(c), code_(nativeCode(c))
18 {
19         if (isalpha(c))
20                 code_ = LM_TC_VAR;
21 }
22
23
24 MathCharInset::MathCharInset(char c, MathTextCodes t)
25         : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
26 {}
27
28
29 MathTextCodes MathCharInset::nativeCode(char c) const
30 {
31         if (isalpha(c))
32                 return LM_TC_VAR;
33         return LM_TC_MIN;
34 }
35
36
37 MathInset * MathCharInset::clone() const
38 {   
39         return new MathCharInset(*this);
40 }
41
42
43 int MathCharInset::ascent() const
44 {
45         return mathed_char_ascent(code_, size(), char_);
46 }
47
48
49 int MathCharInset::descent() const
50 {
51         return mathed_char_descent(code_, size(), char_);
52 }
53
54
55 int MathCharInset::width() const
56 {
57         return mathed_char_width(code_, size(), char_);
58 }
59
60
61 void MathCharInset::metrics(MathStyles st) const
62 {
63         size_ = st;
64 }
65
66
67 void MathCharInset::draw(Painter & pain, int x, int y) const
68
69         xo(x);
70         yo(y);
71         drawChar(pain, code_, size_, x, y, char_);
72 }
73
74
75 void MathCharInset::write(std::ostream & os, bool) const
76 {
77         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM) 
78                 os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
79
80         if (code_ == LM_TC_TEX || code_ == LM_TC_SPECIAL)
81                 os << '\\';
82
83         os << char_;
84
85         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
86                 os << '}';
87 }
88
89
90 void MathCharInset::writeNormal(std::ostream & os) const
91 {
92         os << char_;
93 }
94
95
96 bool MathCharInset::isRelOp() const
97 {
98         return char_ == '=' || char_ == '<' || char_ == '>';
99 }
100
101
102 void MathCharInset::handleFont(MathTextCodes t)
103 {
104         code_ = (code_ == t) ? LM_TC_VAR : t;
105 }