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 void MathCharInset::metrics(MathMetricsInfo const & mi) const
52 ascent_ = mathed_char_ascent(code_, mi_, char_);
53 descent_ = mathed_char_descent(code_, mi_, char_);
54 width_ = mathed_char_width(code_, mi_, char_);
58 void MathCharInset::draw(Painter & pain, int x, int y) const
60 //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
61 drawChar(pain, code_, mi_, x, y, char_);
65 void MathCharInset::writeHeader(std::ostream & os) const
67 if (math_font_name(code_))
68 os << '\\' << math_font_name(code_) << '{';
72 void MathCharInset::writeTrailer(std::ostream & os) const
74 if (math_font_name(code_))
79 void MathCharInset::writeRaw(std::ostream & os) const
85 void MathCharInset::write(WriteStream & os) const
89 writeTrailer(os.os());
93 void MathCharInset::normalize(NormalStream & os) const
95 os << "[char " << char_ << " " << "mathalpha" << "]";
99 bool MathCharInset::isRelOp() const
101 return char_ == '=' || char_ == '<' || char_ == '>';
105 void MathCharInset::handleFont(MathTextCodes t)
107 code_ = (code_ == t) ? LM_TC_VAR : t;
111 void MathCharInset::validate(LaTeXFeatures & features) const
113 // Make sure amssymb is put in preamble if Blackboard Bold or
115 if ( (code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK) )
116 features.require("amssymb");
120 bool MathCharInset::match(MathInset * p) const
122 MathCharInset const * q = p->asCharInset();
123 return q && char_ == q->char_ && code_ == q->code_;