7 #include "math_charinset.h"
9 #include "frontends/Painter.h"
10 #include "frontends/font_metrics.h"
11 #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
31 bool isBinaryOp(char c, MathTextCodes type)
33 return type < LM_TC_SYMB && strchr("+-<>=/*", c);
37 MathCharInset::MathCharInset(char c)
38 : char_(c), code_(nativeCode(c))
40 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
44 MathCharInset::MathCharInset(char c, MathTextCodes t)
45 : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
47 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
51 MathTextCodes MathCharInset::nativeCode(char c)
55 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
60 MathInset * MathCharInset::clone() const
62 return new MathCharInset(*this);
66 void MathCharInset::metrics(MathMetricsInfo const & mi) const
68 whichFont(font_, code_, mi);
69 mathed_char_dim(font_, char_, ascent_, descent_, width_);
70 if (isBinaryOp(char_, code_))
71 width_ += 2 * font_metrics::width(' ', font_);
75 void MathCharInset::draw(Painter & pain, int x, int y) const
77 //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
78 if (isBinaryOp(char_, code_))
79 x += font_metrics::width(' ', font_);
80 drawChar(pain, font_, x, y, char_);
84 void MathCharInset::metricsT(TextMetricsInfo const &) const
92 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
94 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
95 pain.draw(x, y, char_);
99 void MathCharInset::writeHeader(ostream & os) const
101 if (math_font_name(code_))
102 os << '\\' << math_font_name(code_) << '{';
106 void MathCharInset::writeTrailer(ostream & os) const
108 if (math_font_name(code_))
113 void MathCharInset::writeRaw(ostream & os) const
119 void MathCharInset::write(WriteStream & os) const
121 writeHeader(os.os());
123 writeTrailer(os.os());
127 void MathCharInset::normalize(NormalStream & os) const
129 os << "[char " << char_ << " " << "mathalpha" << "]";
133 bool MathCharInset::isRelOp() const
135 return char_ == '=' || char_ == '<' || char_ == '>';
139 void MathCharInset::handleFont(MathTextCodes t)
141 code_ = (code_ == t) ? LM_TC_VAR : t;
145 void MathCharInset::validate(LaTeXFeatures & features) const
147 // Make sure amssymb is put in preamble if Blackboard Bold or
149 if ((code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK))
150 features.require("amssymb");
154 bool MathCharInset::match(MathInset * p) const
156 MathCharInset const * q = p->asCharInset();
157 return q && char_ == q->char_ && code_ == q->code_;