4 #include "math_charinset.h"
6 #include "frontends/Painter.h"
7 #include "frontends/font_metrics.h"
8 #include "support/LOstream.h"
10 #include "math_support.h"
11 #include "math_mathmlstream.h"
12 #include "LaTeXFeatures.h"
13 #include "textpainter.h"
22 #ifndef CXX_GLOBAL_CSTD
27 extern bool has_math_fonts;
31 bool isBinaryOp(char c)
33 return strchr("+-<>=/*", c);
39 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
40 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
46 MathCharInset::MathCharInset(char c)
52 MathInset * MathCharInset::clone() const
54 return new MathCharInset(*this);
58 void MathCharInset::metrics(MathMetricsInfo & mi) const
61 if (char_ == '=' && has_math_fonts) {
62 MathFontSetChanger dummy(mi.base, "cmr");
63 mathed_char_dim(mi.base.font, char_, dim_);
64 } else if ((char_ == '>' || char_ == '<') && has_math_fonts) {
65 MathFontSetChanger dummy(mi.base, "cmm");
66 mathed_char_dim(mi.base.font, char_, dim_);
67 } else if (slanted(char_) && mi.base.fontname == "mathnormal") {
68 MathShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE);
69 mathed_char_dim(mi.base.font, char_, dim_);
71 mathed_char_dim(mi.base.font, char_, dim_);
73 int const em = mathed_char_width(mi.base.font, 'M');
74 if (isBinaryOp(char_))
75 dim_.w += static_cast<int>(0.5*em+0.5);
76 else if (char_ == '\'')
77 dim_.w += static_cast<int>(0.1667*em+0.5);
79 whichFont(font_, code_, mi);
80 mathed_char_dim(font_, char_, dim_);
81 if (isBinaryOp(char_, code_))
82 width_ += 2 * font_metrics::width(' ', font_);
83 lyxerr << "MathCharInset::metrics: " << dim_ << "\n";
88 void MathCharInset::draw(MathPainterInfo & pi, int x, int y) const
90 //lyxerr << "drawing '" << char_ << "' font: " << pi.base.fontname << endl;
91 int const em = mathed_char_width(pi.base.font, 'M');
92 if (isBinaryOp(char_))
93 x += static_cast<int>(0.25*em+0.5);
94 else if (char_ == '\'')
95 x += static_cast<int>(0.0833*em+0.5);
97 if (char_ == '=' && has_math_fonts) {
98 MathFontSetChanger dummy(pi.base, "cmr");
100 } else if ((char_ == '>' || char_ == '<') && has_math_fonts) {
101 MathFontSetChanger dummy(pi.base, "cmm");
102 pi.draw(x, y, char_);
103 } else if (slanted(char_) && pi.base.fontname == "mathnormal") {
104 MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
105 pi.draw(x, y, char_);
107 pi.draw(x, y, char_);
110 drawChar(pain, font_, x, y, char_);
115 void MathCharInset::metricsT(TextMetricsInfo const &) const
123 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
125 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
126 pain.draw(x, y, char_);
130 void MathCharInset::write(WriteStream & os) const
136 void MathCharInset::normalize(NormalStream & os) const
138 os << "[char " << char_ << ' ' << "mathalpha]";
142 void MathCharInset::octave(OctaveStream & os) const
148 bool MathCharInset::isRelOp() const
150 return char_ == '=' || char_ == '<' || char_ == '>';
154 bool MathCharInset::match(MathInset const * p) const
156 MathCharInset const * q = p->asCharInset();
157 return q && char_ == q->char_;