9 #include "math_charinset.h"
12 #include "support/LOstream.h"
13 #include "math_support.h"
14 #include "math_parser.h"
16 #include "math_mathmlstream.h"
19 MathCharInset::MathCharInset(char c)
20 : char_(c), code_(nativeCode(c))
22 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
26 MathCharInset::MathCharInset(char c, MathTextCodes t)
27 : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
29 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
33 MathTextCodes MathCharInset::nativeCode(char c)
37 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
42 MathInset * MathCharInset::clone() const
44 return new MathCharInset(*this);
48 int MathCharInset::ascent() const
50 return mathed_char_ascent(code_, mi_, char_);
54 int MathCharInset::descent() const
56 return mathed_char_descent(code_, mi_, char_);
60 int MathCharInset::width() const
62 return mathed_char_width(code_, mi_, char_);
66 void MathCharInset::metrics(MathMetricsInfo const & mi) const
72 void MathCharInset::draw(Painter & pain, int x, int y) const
74 //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
75 drawChar(pain, code_, mi_, x, y, char_);
79 void MathCharInset::writeHeader(std::ostream & os) const
81 if (math_font_name(code_))
82 os << '\\' << math_font_name(code_) << '{';
86 void MathCharInset::writeTrailer(std::ostream & os) const
88 if (math_font_name(code_))
93 void MathCharInset::writeRaw(std::ostream & os) const
99 void MathCharInset::write(WriteStream & os) const
101 writeHeader(os.os());
103 writeTrailer(os.os());
107 void MathCharInset::normalize(NormalStream & os) const
109 os << "[char " << char_ << " " << "mathalpha" << "]";
113 bool MathCharInset::isRelOp() const
115 return char_ == '=' || char_ == '<' || char_ == '>';
119 void MathCharInset::handleFont(MathTextCodes t)
121 code_ = (code_ == t) ? LM_TC_VAR : t;
125 bool MathCharInset::match(MathInset * p) const
127 MathCharInset const * q = p->asCharInset();
128 return q && char_ == q->char_ && code_ == q->code_;