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