3 #include "math_charinset.h"
5 #include "frontends/Painter.h"
6 #include "frontends/font_metrics.h"
7 #include "support/LOstream.h"
9 #include "math_support.h"
10 #include "math_mathmlstream.h"
11 #include "LaTeXFeatures.h"
12 #include "textpainter.h"
21 #ifndef CXX_GLOBAL_CSTD
26 extern bool has_math_fonts;
30 bool isBinaryOp(char c)
32 return strchr("+-<>=/*", c);
38 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
39 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
45 MathCharInset::MathCharInset(char c)
51 MathInset * MathCharInset::clone() const
53 return new MathCharInset(*this);
57 Dimension MathCharInset::metrics(MetricsInfo & mi) const
61 if (char_ == '=' && has_math_fonts) {
62 FontSetChanger dummy(mi.base, "cmr");
63 mathed_char_dim(mi.base.font, char_, dim);
64 } else if ((char_ == '>' || char_ == '<') && has_math_fonts) {
65 FontSetChanger dummy(mi.base, "cmm");
66 mathed_char_dim(mi.base.font, char_, dim);
67 } else if (slanted(char_) && mi.base.fontname == "mathnormal") {
68 ShapeChanger 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.wid += static_cast<int>(0.5*em+0.5);
76 else if (char_ == '\'')
77 dim.wid += 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";
89 void MathCharInset::draw(PainterInfo & pi, int x, int y) const
91 //lyxerr << "drawing '" << char_ << "' font: " << pi.base.fontname << endl;
92 int const em = mathed_char_width(pi.base.font, 'M');
93 if (isBinaryOp(char_))
94 x += static_cast<int>(0.25*em+0.5);
95 else if (char_ == '\'')
96 x += static_cast<int>(0.0833*em+0.5);
98 if (char_ == '=' && has_math_fonts) {
99 FontSetChanger dummy(pi.base, "cmr");
100 pi.draw(x, y, char_);
101 } else if ((char_ == '>' || char_ == '<') && has_math_fonts) {
102 FontSetChanger dummy(pi.base, "cmm");
103 pi.draw(x, y, char_);
104 } else if (slanted(char_) && pi.base.fontname == "mathnormal") {
105 ShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
106 pi.draw(x, y, char_);
108 pi.draw(x, y, char_);
111 drawChar(pain, font_, x, y, char_);
116 void MathCharInset::metricsT(TextMetricsInfo const &, Dimension & dim) const
124 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
126 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
127 pain.draw(x, y, char_);
131 void MathCharInset::write(WriteStream & os) const
137 void MathCharInset::normalize(NormalStream & os) const
139 os << "[char " << char_ << ' ' << "mathalpha]";
143 void MathCharInset::octave(OctaveStream & os) const
149 bool MathCharInset::isRelOp() const
151 return char_ == '=' || char_ == '<' || char_ == '>';
155 bool MathCharInset::match(MathInset const * p) const
157 MathCharInset const * q = p->asCharInset();
158 return q && char_ == q->char_;