3 #include "math_symbolinset.h"
4 #include "math_mathmlstream.h"
5 #include "math_streamstr.h"
6 #include "math_support.h"
7 #include "math_parser.h"
11 MathSymbolInset::MathSymbolInset(const latexkeys * l)
16 MathSymbolInset::MathSymbolInset(const char * name)
17 : sym_(in_word_set(name)), h_(0)
21 MathSymbolInset::MathSymbolInset(string const & name)
22 : sym_(in_word_set(name.c_str())), h_(0)
27 MathInset * MathSymbolInset::clone() const
29 return new MathSymbolInset(*this);
33 MathTextCodes MathSymbolInset::code() const
54 MathTextCodes MathSymbolInset::code2() const
56 if (sym_->token == LM_TK_CMEX)
57 return LM_TC_BOLDSYMB;
63 string MathSymbolInset::name() const
69 void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
72 MathTextCodes c = code();
73 if (sym_->latex_font_id > 0 && math_font_available(c)) {
74 mathed_char_dim(c, mi_, sym_->latex_font_id, ascent_, descent_, width_);
75 if (c == LM_TC_CMEX) {
76 h_ = 4 * descent_ / 5;
81 if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
82 mathed_char_dim(code2(), mi_, sym_->id, ascent_, descent_, width_);
84 mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
87 width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
91 void MathSymbolInset::draw(Painter & pain, int x, int y) const
94 x += mathed_char_width(LM_TC_TEX, mi_, 'I') / 2;
95 MathTextCodes Code = code();
96 if (sym_->latex_font_id > 0 && math_font_available(Code))
97 drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);
98 else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
99 drawChar(pain, code2(), mi_, x, y, sym_->id);
101 drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name);
105 bool MathSymbolInset::isRelOp() const
107 return sym_->type == "mathrel";
111 bool MathSymbolInset::isScriptable() const
113 return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
117 bool MathSymbolInset::takesLimits() const
119 return sym_->token == LM_TK_CMEX;
123 void MathSymbolInset::normalize(NormalStream & os) const
125 os << "[symbol " << name() << "]";
129 void MathSymbolInset::maplize(MapleStream & os) const
131 if (name() == "cdot")
138 char const * MathMLtype(string const & s)
146 bool MathSymbolInset::match(MathInset * p) const
148 MathSymbolInset const * q = p->asSymbolInset();
149 return q && name() == q->name();
153 void MathSymbolInset::mathmlize(MathMLStream & os) const
155 char const * type = MathMLtype(sym_->type);
156 os << '<' << type << "> ";
157 if (sym_->xmlname == "x") // unknown so far
161 os << " </" << type << '>';
165 void MathSymbolInset::octavize(OctaveStream & os) const
167 if (name() == "cdot")
174 void MathSymbolInset::write(WriteStream & os) const
176 os << '\\' << name() << ' ';