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