7 #include "math_charinset.h"
10 #include "support/LOstream.h"
13 #include "math_support.h"
14 #include "math_mathmlstream.h"
15 #include "LaTeXFeatures.h"
16 #include "textpainter.h"
27 bool isBinaryOp(char c, MathTextCodes type)
29 return type < LM_TC_SYMB && strchr("+-<>=/*", c);
33 MathCharInset::MathCharInset(char c)
34 : char_(c), code_(nativeCode(c))
36 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
40 MathCharInset::MathCharInset(char c, MathTextCodes t)
41 : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
43 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
47 MathTextCodes MathCharInset::nativeCode(char c)
51 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
56 MathInset * MathCharInset::clone() const
58 return new MathCharInset(*this);
62 void MathCharInset::metrics(MathMetricsInfo const & mi) const
64 whichFont(font_, code_, mi);
65 mathed_char_dim(font_, char_, ascent_, descent_, width_);
66 if (isBinaryOp(char_, code_))
67 width_ += 2 * lyxfont::width(' ', font_);
71 void MathCharInset::draw(Painter & pain, int x, int y) const
73 //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
74 if (isBinaryOp(char_, code_))
75 x += lyxfont::width(' ', font_);
76 drawChar(pain, font_, x, y, char_);
80 void MathCharInset::metrics(TextMetricsInfo const &) const
88 void MathCharInset::draw(TextPainter & pain, int x, int y) const
90 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
91 pain.draw(x, y, char_);
95 void MathCharInset::writeHeader(ostream & os) const
97 if (math_font_name(code_))
98 os << '\\' << math_font_name(code_) << '{';
102 void MathCharInset::writeTrailer(ostream & os) const
104 if (math_font_name(code_))
109 void MathCharInset::writeRaw(ostream & os) const
115 void MathCharInset::write(WriteStream & os) const
117 writeHeader(os.os());
119 writeTrailer(os.os());
123 void MathCharInset::normalize(NormalStream & os) const
125 os << "[char " << char_ << " " << "mathalpha" << "]";
129 bool MathCharInset::isRelOp() const
131 return char_ == '=' || char_ == '<' || char_ == '>';
135 void MathCharInset::handleFont(MathTextCodes t)
137 code_ = (code_ == t) ? LM_TC_VAR : t;
141 void MathCharInset::validate(LaTeXFeatures & features) const
143 // Make sure amssymb is put in preamble if Blackboard Bold or
145 if ((code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK))
146 features.require("amssymb");
150 bool MathCharInset::match(MathInset * p) const
152 MathCharInset const * q = p->asCharInset();
153 return q && char_ == q->char_ && code_ == q->code_;