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
33 bool isBinaryOp(char c)
35 return strchr("+-<>=/*", c);
41 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
42 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
48 MathCharInset::MathCharInset(char c)
54 MathInset * MathCharInset::clone() const
56 return new MathCharInset(*this);
60 void MathCharInset::metrics(MathMetricsInfo & mi) const
63 if (slanted(char_) && mi.base.fontname == "mathnormal") {
64 MathShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE);
65 mathed_char_dim(mi.base.font, char_, ascent_, descent_, width_);
67 mathed_char_dim(mi.base.font, char_, ascent_, descent_, width_);
69 if (isBinaryOp(char_))
70 width_ += 2 * font_metrics::width(' ', mi.base.font);
72 whichFont(font_, code_, mi);
73 mathed_char_dim(font_, char_, ascent_, descent_, width_);
74 if (isBinaryOp(char_, code_))
75 width_ += 2 * font_metrics::width(' ', font_);
80 void MathCharInset::draw(MathPainterInfo & pi, int x, int y) const
82 //lyxerr << "drawing '" << char_ << "' font: " << pi.base.fontname << endl;
83 if (isBinaryOp(char_))
84 x += font_metrics::width(' ', pi.base.font);
86 if (slanted(char_) && pi.base.fontname == "mathnormal") {
87 MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
93 drawChar(pain, font_, x, y, char_);
98 void MathCharInset::metricsT(TextMetricsInfo const &) const
106 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
108 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
109 pain.draw(x, y, char_);
113 void MathCharInset::write(WriteStream & os) const
119 void MathCharInset::normalize(NormalStream & os) const
121 os << "[char " << char_ << " " << "mathalpha" << "]";
125 void MathCharInset::octavize(OctaveStream & os) const
131 bool MathCharInset::isRelOp() const
133 return char_ == '=' || char_ == '<' || char_ == '>';
137 bool MathCharInset::match(MathInset * p) const
139 MathCharInset const * q = p->asCharInset();
140 return q && char_ == q->char_;