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