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"
8 #include "LaTeXFeatures.h"
15 MathSymbolInset::MathSymbolInset(const latexkeys * l)
20 MathSymbolInset::MathSymbolInset(const char * name)
21 : sym_(in_word_set(name)), h_(0)
25 MathSymbolInset::MathSymbolInset(string const & name)
26 : sym_(in_word_set(name.c_str())), h_(0)
31 MathInset * MathSymbolInset::clone() const
33 return new MathSymbolInset(*this);
37 MathTextCodes MathSymbolInset::code() const
39 switch (sym_->token) {
58 MathTextCodes MathSymbolInset::code2() const
60 if (sym_->token == LM_TK_CMEX)
61 return LM_TC_BOLDSYMB;
67 string MathSymbolInset::name() const
73 void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
76 MathTextCodes c = code();
77 if (sym_->latex_font_id > 0 && math_font_available(c)) {
78 mathed_char_dim(c, mi_, sym_->latex_font_id, ascent_, descent_, width_);
79 if (c == LM_TC_CMEX) {
80 h_ = 4 * descent_ / 5;
85 if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
86 mathed_char_dim(code2(), mi_, sym_->id, ascent_, descent_, width_);
88 mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
91 width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
95 void MathSymbolInset::draw(Painter & pain, int x, int y) const
98 x += mathed_char_width(LM_TC_TEX, mi_, 'I') / 2;
99 MathTextCodes Code = code();
100 if (sym_->latex_font_id > 0 && math_font_available(Code))
101 drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);
102 else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
103 drawChar(pain, code2(), mi_, x, y, sym_->id);
105 drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name);
109 bool MathSymbolInset::isRelOp() const
111 return sym_->type == "mathrel";
115 bool MathSymbolInset::isScriptable() const
117 return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
121 bool MathSymbolInset::takesLimits() const
123 return sym_->token == LM_TK_CMEX;
126 void MathSymbolInset::validate(LaTeXFeatures & features) const
128 if (sym_->token == LM_TK_MSA || sym_->token == LM_TK_MSB)
129 features.require("amssymb");
132 void MathSymbolInset::normalize(NormalStream & os) const
134 os << "[symbol " << name() << "]";
138 void MathSymbolInset::maplize(MapleStream & os) const
140 if (name() == "cdot")
147 char const * MathMLtype(string const & s)
155 bool MathSymbolInset::match(MathInset * p) const
157 MathSymbolInset const * q = p->asSymbolInset();
158 return q && name() == q->name();
162 void MathSymbolInset::mathmlize(MathMLStream & os) const
164 char const * type = MathMLtype(sym_->type);
165 os << '<' << type << "> ";
166 if (sym_->xmlname == "x") // unknown so far
170 os << " </" << type << '>';
174 void MathSymbolInset::octavize(OctaveStream & os) const
176 if (name() == "cdot")
183 void MathSymbolInset::write(WriteStream & os) const
185 os << '\\' << name() << ' ';
189 void MathSymbolInset::infoize(ostream & os) const
191 os << '\\' << name();