3 #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"
23 #ifndef CXX_GLOBAL_CSTD
28 extern bool has_math_fonts;
32 bool isBinaryOp(char c)
34 return strchr("+-<>=/*", c);
40 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
41 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
47 MathCharInset::MathCharInset(char c)
53 auto_ptr<InsetBase> MathCharInset::clone() const
55 return auto_ptr<InsetBase>(new MathCharInset(*this));
59 void MathCharInset::metrics(MetricsInfo & mi, Dimension & dim) const
62 if (char_ == '=' && has_math_fonts) {
63 FontSetChanger dummy(mi.base, "cmr");
64 mathed_char_dim(mi.base.font, char_, dim);
65 } else if ((char_ == '>' || char_ == '<') && has_math_fonts) {
66 FontSetChanger dummy(mi.base, "cmm");
67 mathed_char_dim(mi.base.font, char_, dim);
68 } else if (slanted(char_) && mi.base.fontname == "mathnormal") {
69 ShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE);
70 mathed_char_dim(mi.base.font, char_, dim);
72 mathed_char_dim(mi.base.font, char_, dim);
74 int const em = mathed_char_width(mi.base.font, 'M');
75 if (isBinaryOp(char_))
76 dim.wid += static_cast<int>(0.5*em+0.5);
77 else if (char_ == '\'')
78 dim.wid += static_cast<int>(0.1667*em+0.5);
80 whichFont(font_, code_, mi);
81 mathed_char_dim(font_, char_, dim_);
82 if (isBinaryOp(char_, code_))
83 width_ += 2 * font_metrics::width(' ', font_);
84 lyxerr << "MathCharInset::metrics: " << dim << endl;
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_;