1 #include "math_symbolinset.h"
2 #include "math_mathmlstream.h"
3 #include "math_support.h"
4 #include "math_parser.h"
8 MathSymbolInset::MathSymbolInset(const latexkeys * l)
13 MathSymbolInset::MathSymbolInset(const char * name)
14 : sym_(in_word_set(name)), h_(0)
19 MathInset * MathSymbolInset::clone() const
21 return new MathSymbolInset(*this);
25 MathTextCodes MathSymbolInset::code() const
46 MathTextCodes MathSymbolInset::code2() const
48 if (sym_->token == LM_TK_CMEX)
49 return LM_TC_BOLDSYMB;
55 string MathSymbolInset::name() const
61 void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
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;
73 if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
74 mathed_char_dim(code2(), mi_, sym_->id, ascent_, descent_, width_);
76 mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
79 width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
83 void MathSymbolInset::draw(Painter & pain, int x, int y) const
86 x += mathed_char_width(LM_TC_TEX, mi_, 'I') / 2;
87 MathTextCodes Code = code();
88 if (sym_->latex_font_id > 0 && math_font_available(Code))
89 drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);
90 else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
91 drawChar(pain, code2(), mi_, x, y, sym_->id);
93 drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name);
97 bool MathSymbolInset::isRelOp() const
99 return sym_->type == "mathrel";
103 bool MathSymbolInset::isScriptable() const
105 return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
109 bool MathSymbolInset::takesLimits() const
111 return sym_->token == LM_TK_CMEX;
115 void MathSymbolInset::normalize(NormalStream & os) const
117 os << "[symbol " << name().c_str() << "]";
121 void MathSymbolInset::maplize(MapleStream & os) const
123 if (name() == "cdot")
126 os << name().c_str();
130 char const * MathMLtype(string const & s)
138 bool MathSymbolInset::match(MathInset * p) const
140 MathSymbolInset const * q = p->asSymbolInset();
141 return q && name() == q->name();
145 void MathSymbolInset::mathmlize(MathMLStream & os) const
147 char const * type = MathMLtype(sym_->type);
148 os << '<' << type << "> ";
149 if (sym_->xmlname == "x") // unknown so far
150 os << name().c_str();
152 os << sym_->xmlname.c_str();
153 os << " </" << type << '>';
157 void MathSymbolInset::octavize(OctaveStream & os) const
159 if (name() == "cdot")
162 os << name().c_str();
166 void MathSymbolInset::write(WriteStream & os) const
168 os << '\\' << name().c_str() << ' ';