]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
fix cursor font bug
[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 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
20 }
21
22
23 MathCharInset::MathCharInset(char c, MathTextCodes t)
24         : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
25 {
26 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
27 }
28
29
30 MathTextCodes MathCharInset::nativeCode(char c) const
31 {
32         if (isalpha(c))
33                 return LM_TC_VAR;
34         if (strchr("#$%{|}", c))
35                 return LM_TC_SPECIAL;
36         //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
37         return LM_TC_CONST;
38 }
39
40
41 MathInset * MathCharInset::clone() const
42 {   
43         return new MathCharInset(*this);
44 }
45
46
47 int MathCharInset::ascent() const
48 {
49         return mathed_char_ascent(code_, size(), char_);
50 }
51
52
53 int MathCharInset::descent() const
54 {
55         return mathed_char_descent(code_, size(), char_);
56 }
57
58
59 int MathCharInset::width() const
60 {
61         return mathed_char_width(code_, size(), char_);
62 }
63
64
65 void MathCharInset::metrics(MathStyles st) const
66 {
67         size_ = st;
68 }
69
70
71 void MathCharInset::draw(Painter & pain, int x, int y) const
72
73         xo(x);
74         yo(y);
75         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
76         drawChar(pain, code_, size_, x, y, char_);
77 }
78
79
80 void MathCharInset::writeHeader(std::ostream & os) const
81 {
82         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM) 
83                 os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
84 }
85
86
87 void MathCharInset::writeTrailer(std::ostream & os) const
88 {
89         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
90                 os << '}';
91 }
92
93
94 void MathCharInset::writeRaw(std::ostream & os) const
95 {
96         os << char_;
97 }
98
99
100 void MathCharInset::write(std::ostream & os, bool) const
101 {
102         writeHeader(os);
103         writeRaw(os);
104         writeTrailer(os);
105 }
106
107
108 void MathCharInset::writeNormal(std::ostream & os) const
109 {
110         os << char_;
111 }
112
113
114 bool MathCharInset::isRelOp() const
115 {
116         return char_ == '=' || char_ == '<' || char_ == '>';
117 }
118
119
120 void MathCharInset::handleFont(MathTextCodes t)
121 {
122         code_ = (code_ == t) ? LM_TC_VAR : t;
123 }