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"
17 #include "LaTeXFeatures.h"
20 MathCharInset::MathCharInset(char c)
21 : char_(c), code_(nativeCode(c))
23 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
27 MathCharInset::MathCharInset(char c, MathTextCodes t)
28 : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
30 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
34 MathTextCodes MathCharInset::nativeCode(char c)
38 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
43 MathInset * MathCharInset::clone() const
45 return new MathCharInset(*this);
49 int MathCharInset::ascent() const
51 return mathed_char_ascent(code_, mi_, char_);
55 int MathCharInset::descent() const
57 return mathed_char_descent(code_, mi_, char_);
61 int MathCharInset::width() const
63 return mathed_char_width(code_, mi_, char_);
67 void MathCharInset::metrics(MathMetricsInfo const & mi) const
73 void MathCharInset::draw(Painter & pain, int x, int y) const
75 //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
76 drawChar(pain, code_, mi_, x, y, char_);
80 void MathCharInset::writeHeader(std::ostream & os) const
82 if (math_font_name(code_))
83 os << '\\' << math_font_name(code_) << '{';
87 void MathCharInset::writeTrailer(std::ostream & os) const
89 if (math_font_name(code_))
94 void MathCharInset::writeRaw(std::ostream & os) const
100 void MathCharInset::write(WriteStream & os) const
102 writeHeader(os.os());
104 writeTrailer(os.os());
108 void MathCharInset::normalize(NormalStream & os) const
110 os << "[char " << char_ << " " << "mathalpha" << "]";
114 bool MathCharInset::isRelOp() const
116 return char_ == '=' || char_ == '<' || char_ == '>';
120 void MathCharInset::handleFont(MathTextCodes t)
122 code_ = (code_ == t) ? LM_TC_VAR : t;
125 void MathCharInset::validate(LaTeXFeatures & features) const
127 // Make sure amssymb is put in preamble if Blackboard Bold or
129 if ( (code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK) )
130 features.require("amssymb");
133 bool MathCharInset::match(MathInset * p) const
135 MathCharInset const * q = p->asCharInset();
136 return q && char_ == q->char_ && code_ == q->code_;