]> git.lyx.org Git - lyx.git/blob - src/mathed/math_symbolinset.C
some support for matrix operations with maple ('M-x math-extern maple evalm')
[lyx.git] / src / mathed / math_symbolinset.C
1 #include "math_symbolinset.h"
2 #include "math_parser.h"
3 #include "math_mathmlstream.h"
4 #include "debug.h"
5 #include "math_support.h"
6
7
8 MathSymbolInset::MathSymbolInset(const latexkeys * l)
9         : sym_(l), h_(0)
10 {}
11
12
13 MathInset * MathSymbolInset::clone() const
14 {
15         return new MathSymbolInset(*this);
16 }
17
18
19 void MathSymbolInset::write(WriteStream & os) const
20 {
21         os << '\\' << sym_->name.c_str() << ' ';
22 }
23
24
25 void MathSymbolInset::normalize(NormalStream & os) const
26 {
27         os << "[symbol " << sym_->name.c_str() << "]";
28 }
29
30
31 MathTextCodes MathSymbolInset::code() const
32 {
33         switch(sym_->token) {
34         case LM_TK_CMR:
35                 return LM_TC_CMR;
36         case LM_TK_CMSY:
37                 return LM_TC_CMSY;
38         case LM_TK_CMM:
39                 return LM_TC_CMM;
40         case LM_TK_CMEX:
41                 return LM_TC_CMEX;
42         case LM_TK_MSA:
43                 return LM_TC_MSA;
44         case LM_TK_MSB:
45                 return LM_TC_MSB;
46         default:
47                 return LM_TC_SYMB;
48         }
49 }
50
51
52 MathTextCodes MathSymbolInset::code2() const
53 {
54         if (sym_->token == LM_TK_CMEX)
55                 return LM_TC_BOLDSYMB;
56         else
57                 return LM_TC_SYMB;
58 }
59
60
61 void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
62 {
63         mi_ = mi;
64         MathTextCodes c = code();
65         if (sym_->latex_font_id > 0 && math_font_available(c)) {
66                 mathed_char_dim(c, mi_, sym_->latex_font_id, ascent_, descent_, width_);
67                 if (c == LM_TC_CMEX) {
68                         h_ = 4 * descent_ / 5;
69                         ascent_  += h_;
70                         descent_ -= h_;
71                 }
72         } else {
73                 if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
74                         mathed_char_dim(code2(), mi_, sym_->id, ascent_, descent_, width_);
75                 else
76                         mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
77         }
78         if (isRelOp())
79                 width_ +=  mathed_char_width(LM_TC_TEX, mi_, 'I');
80 }
81
82
83 void MathSymbolInset::draw(Painter & pain, int x, int y) const
84 {  
85         if (isRelOp())
86                 x += mathed_char_width(LM_TC_TEX, mi_, 'I') / 2;
87         MathTextCodes Code = code();
88         if (sym_->latex_font_id > 0 && math_font_available(Code))
89                 drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);
90         else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
91                 drawChar(pain, code2(), mi_, x, y, sym_->id);
92         else
93                 drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name);
94 }
95
96
97 bool MathSymbolInset::isRelOp() const
98 {       
99         return sym_->type == LMB_RELATION;
100 }
101
102
103 bool MathSymbolInset::isScriptable() const
104 {
105         return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
106 }
107
108
109 bool MathSymbolInset::takesLimits() const
110 {
111         return sym_->token == LM_TK_CMEX;
112 }
113
114
115 void MathSymbolInset::maplize(MapleStream & os) const
116 {
117         if (sym_->name == "cdot")
118                 os << '*';
119         else
120                 os << sym_->name.c_str();
121 }
122
123
124 void MathSymbolInset::mathmlize(MathMLStream & os) const
125 {
126         os << sym_->name.c_str();
127 }
128
129
130 void MathSymbolInset::octavize(OctaveStream & os) const
131 {
132         if (sym_->name == "cdot")
133                 os << '*';
134         else
135                 os << sym_->name.c_str();
136 }
137
138