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