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"
25 #ifndef CXX_GLOBAL_CSTD
30 bool isBinaryOp(char c, MathTextCodes type)
32 return type < LM_TC_SYMB && strchr("+-<>=/*", c);
36 MathCharInset::MathCharInset(char c)
37 : char_(c), code_(nativeCode(c))
39 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
43 MathCharInset::MathCharInset(char c, MathTextCodes t)
44 : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
46 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
50 MathTextCodes MathCharInset::nativeCode(char c)
54 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
59 MathInset * MathCharInset::clone() const
61 return new MathCharInset(*this);
65 void MathCharInset::metrics(MathMetricsInfo const & mi) const
67 whichFont(font_, code_, mi);
68 mathed_char_dim(font_, char_, ascent_, descent_, width_);
69 if (isBinaryOp(char_, code_))
70 width_ += 2 * lyxfont::width(' ', font_);
74 void MathCharInset::draw(Painter & pain, int x, int y) const
76 //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
77 if (isBinaryOp(char_, code_))
78 x += lyxfont::width(' ', font_);
79 drawChar(pain, font_, x, y, char_);
83 void MathCharInset::metricsT(TextMetricsInfo const &) const
91 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
93 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
94 pain.draw(x, y, char_);
98 void MathCharInset::writeHeader(ostream & os) const
100 if (math_font_name(code_))
101 os << '\\' << math_font_name(code_) << '{';
105 void MathCharInset::writeTrailer(ostream & os) const
107 if (math_font_name(code_))
112 void MathCharInset::writeRaw(ostream & os) const
118 void MathCharInset::write(WriteStream & os) const
120 writeHeader(os.os());
122 writeTrailer(os.os());
126 void MathCharInset::normalize(NormalStream & os) const
128 os << "[char " << char_ << " " << "mathalpha" << "]";
132 bool MathCharInset::isRelOp() const
134 return char_ == '=' || char_ == '<' || char_ == '>';
138 void MathCharInset::handleFont(MathTextCodes t)
140 code_ = (code_ == t) ? LM_TC_VAR : t;
144 void MathCharInset::validate(LaTeXFeatures & features) const
146 // Make sure amssymb is put in preamble if Blackboard Bold or
148 if ((code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK))
149 features.require("amssymb");
153 bool MathCharInset::match(MathInset * p) const
155 MathCharInset const * q = p->asCharInset();
156 return q && char_ == q->char_ && code_ == q->code_;