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