]> git.lyx.org Git - features.git/blob - src/mathed/math_symbolinset.C
9983df5dd6139c79ef4a55df1f33f196ca227ff5
[features.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(ostream & os, bool /* fragile */) const
20 {
21         os << '\\' << sym_->name << ' ';
22 }
23
24
25 void MathSymbolInset::writeNormal(ostream & os) const
26 {
27         os << "[" << sym_->name << "] ";
28 }
29
30
31 MathTextCodes MathSymbolInset::code() const
32 {
33         switch(sym_->token) {
34         case LM_TK_CMSY:
35                 return LM_TC_CMSY;
36         case LM_TK_CMM:
37                 return LM_TC_CMM;
38         case LM_TK_CMEX:
39                 return LM_TC_CMEX;
40         case LM_TK_MSA:
41                 return LM_TC_MSA;
42         case LM_TK_MSB:
43                 return LM_TC_MSB;
44         default:
45                 return LM_TC_SYMB;
46         }
47 }
48
49 void MathSymbolInset::metrics(MathStyles st) const
50 {
51         size_ = st;
52         MathTextCodes Code = code();
53         if (sym_->latex_font_id > 0 && math_font_available(Code)) {
54                 mathed_char_dim(Code, size_, sym_->latex_font_id,
55                                 ascent_, descent_, width_);
56                 if (Code == LM_TC_CMEX) {
57                         h_ = 4*descent_/5;
58                         ascent_  += h_;
59                         descent_ -= h_;
60                 }
61         } else if (sym_->id > 0 && sym_->id < 255 &&
62                    math_font_available(LM_TC_SYMB)) {
63                 mathed_char_dim(LM_TC_SYMB, size_, sym_->id,
64                                 ascent_, descent_, width_);
65         } else {
66                 mathed_string_dim(LM_TC_TEX, size_, sym_->name, ascent_, descent_, width_);
67         }
68 }
69
70
71 void MathSymbolInset::draw(Painter & pain, int x, int y) const
72 {  
73         xo(x);
74         yo(y);
75         MathTextCodes Code = code();
76         if (sym_->latex_font_id > 0 && math_font_available(Code))
77                 drawChar(pain, Code, size_, x, y - h_, sym_->latex_font_id);
78         else if (sym_->id > 0 && sym_->id < 255 &&
79                    math_font_available(LM_TC_SYMB))
80                 drawChar(pain, LM_TC_SYMB, size_, x, y, sym_->id);
81         else
82                 drawStr(pain, LM_TC_TEX, size_, x, y, sym_->name);
83 }
84
85
86 bool MathSymbolInset::isRelOp() const
87 {
88         return sym_->type == LMB_RELATION;
89 }
90
91
92 bool MathSymbolInset::isScriptable() const
93 {
94         return sym_->token == LM_TK_CMEX;
95 }