]> git.lyx.org Git - lyx.git/blob - src/mathed/math_symbolinset.C
e27fbe1bc9bb1aabd34e5e83f1131e18a133fa1b
[lyx.git] / src / mathed / math_symbolinset.C
1 #include "math_symbolinset.h"
2 #include "math_parser.h"
3 #include "support.h"
4 #include "support/LOstream.h"
5
6
7 using std::ostream;
8
9 MathSymbolInset::MathSymbolInset(const latexkeys * l)
10         : sym_(l), h_(0) {}
11
12
13 MathInset * MathSymbolInset::clone() const
14 {
15         return new MathSymbolInset(*this);
16 }
17
18
19 void MathSymbolInset::write(MathWriteInfo & os) const
20 {
21         os << '\\' << sym_->name << ' ';
22 }
23
24
25 void MathSymbolInset::writeNormal(ostream & os) const
26 {
27         os << "[symbol " << sym_->name << "]";
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                 return;
73         }
74
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
81
82 void MathSymbolInset::draw(Painter & pain, int x, int y) const
83 {  
84         MathTextCodes Code = code();
85         if (sym_->latex_font_id > 0 && math_font_available(Code))
86                 drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);
87         else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
88                 drawChar(pain, code2(), mi_, x, y, sym_->id);
89         else
90                 drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name);
91 }
92
93
94 bool MathSymbolInset::isRelOp() const
95 {
96         return sym_->type == LMB_RELATION;
97 }
98
99
100 bool MathSymbolInset::isScriptable() const
101 {
102         return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
103 }
104
105
106 bool MathSymbolInset::takesLimits() const
107 {
108         return sym_->token == LM_TK_CMEX;
109 }