9 #include "math_charinset.h"
12 #include "support/LOstream.h"
15 #include "math_support.h"
16 #include "math_mathmlstream.h"
17 #include "LaTeXFeatures.h"
18 #include "textpainter.h"
25 bool isBinaryOp(char c, MathTextCodes type)
27 return type < LM_TC_SYMB && strchr("+-<>=/*", c);
31 MathCharInset::MathCharInset(char c)
32 : char_(c), code_(nativeCode(c))
34 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
38 MathCharInset::MathCharInset(char c, MathTextCodes t)
39 : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
41 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
45 MathTextCodes MathCharInset::nativeCode(char c)
49 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
54 MathInset * MathCharInset::clone() const
56 return new MathCharInset(*this);
60 void MathCharInset::metrics(MathMetricsInfo const & mi) const
62 whichFont(font_, code_, mi);
63 mathed_char_dim(font_, char_, ascent_, descent_, width_);
64 if (isBinaryOp(char_, code_))
65 width_ += 2 * lyxfont::width(' ', font_);
69 void MathCharInset::draw(Painter & pain, int x, int y) const
71 //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
72 if (isBinaryOp(char_, code_))
73 x += lyxfont::width(' ', font_);
74 drawChar(pain, font_, x, y, char_);
78 void MathCharInset::metrics(TextMetricsInfo const &) const
86 void MathCharInset::draw(TextPainter & pain, int x, int y) const
88 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
89 pain.draw(x, y, char_);
93 void MathCharInset::writeHeader(ostream & os) const
95 if (math_font_name(code_))
96 os << '\\' << math_font_name(code_) << '{';
100 void MathCharInset::writeTrailer(ostream & os) const
102 if (math_font_name(code_))
107 void MathCharInset::writeRaw(ostream & os) const
113 void MathCharInset::write(WriteStream & os) const
115 writeHeader(os.os());
117 writeTrailer(os.os());
121 void MathCharInset::normalize(NormalStream & os) const
123 os << "[char " << char_ << " " << "mathalpha" << "]";
127 bool MathCharInset::isRelOp() const
129 return char_ == '=' || char_ == '<' || char_ == '>';
133 void MathCharInset::handleFont(MathTextCodes t)
135 code_ = (code_ == t) ? LM_TC_VAR : t;
139 void MathCharInset::validate(LaTeXFeatures & features) const
141 // Make sure amssymb is put in preamble if Blackboard Bold or
143 if ((code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK))
144 features.require("amssymb");
148 bool MathCharInset::match(MathInset * p) const
150 MathCharInset const * q = p->asCharInset();
151 return q && char_ == q->char_ && code_ == q->code_;