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_, dim_);
67 mathed_char_dim(mi.base.font, char_, dim_);
69 if (isBinaryOp(char_))
70 dim_.w += 2 * font_metrics::width(' ', mi.base.font);
72 whichFont(font_, code_, mi);
73 mathed_char_dim(font_, char_, dim_);
74 if (isBinaryOp(char_, code_))
75 width_ += 2 * font_metrics::width(' ', font_);
76 lyxerr << "MathCharInset::metrics: " << dim_ << "\n";
81 void MathCharInset::draw(MathPainterInfo & pi, int x, int y) const
83 //lyxerr << "drawing '" << char_ << "' font: " << pi.base.fontname << endl;
84 if (isBinaryOp(char_))
85 x += font_metrics::width(' ', pi.base.font);
87 if (slanted(char_) && pi.base.fontname == "mathnormal") {
88 MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
94 drawChar(pain, font_, x, y, char_);
99 void MathCharInset::metricsT(TextMetricsInfo const &) const
107 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
109 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
110 pain.draw(x, y, char_);
114 void MathCharInset::write(WriteStream & os) const
120 void MathCharInset::normalize(NormalStream & os) const
122 os << "[char " << char_ << " " << "mathalpha" << "]";
126 void MathCharInset::octavize(OctaveStream & os) const
132 bool MathCharInset::isRelOp() const
134 return char_ == '=' || char_ == '<' || char_ == '>';
138 bool MathCharInset::match(MathInset const * p) const
140 MathCharInset const * q = p->asCharInset();
141 return q && char_ == q->char_;