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
30 extern bool has_math_fonts;
34 bool isBinaryOp(char c)
36 return strchr("+-<>=/*", c);
42 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
43 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
49 MathCharInset::MathCharInset(char c)
55 MathInset * MathCharInset::clone() const
57 return new MathCharInset(*this);
61 void MathCharInset::metrics(MathMetricsInfo & mi) const
64 if (char_ == '=' && has_math_fonts) {
65 MathFontSetChanger dummy(mi.base, "cmr");
66 mathed_char_dim(mi.base.font, char_, dim_);
67 } else if ((char_ == '>' || char_ == '<') && has_math_fonts) {
68 MathFontSetChanger dummy(mi.base, "cmm");
69 mathed_char_dim(mi.base.font, char_, dim_);
70 } else if (slanted(char_) && mi.base.fontname == "mathnormal") {
71 MathShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE);
72 mathed_char_dim(mi.base.font, char_, dim_);
74 mathed_char_dim(mi.base.font, char_, dim_);
76 int const em = mathed_char_width(mi.base.font, 'M');
77 if (isBinaryOp(char_))
78 dim_.w += static_cast<int>(0.5*em+0.5);
79 else if (char_ == '\'')
80 dim_.w += static_cast<int>(0.1667*em+0.5);
82 whichFont(font_, code_, mi);
83 mathed_char_dim(font_, char_, dim_);
84 if (isBinaryOp(char_, code_))
85 width_ += 2 * font_metrics::width(' ', font_);
86 lyxerr << "MathCharInset::metrics: " << dim_ << "\n";
91 void MathCharInset::draw(MathPainterInfo & pi, int x, int y) const
93 //lyxerr << "drawing '" << char_ << "' font: " << pi.base.fontname << endl;
94 int const em = mathed_char_width(pi.base.font, 'M');
95 if (isBinaryOp(char_))
96 x += static_cast<int>(0.25*em+0.5);
97 else if (char_ == '\'')
98 x += static_cast<int>(0.0833*em+0.5);
100 if (char_ == '=' && has_math_fonts) {
101 MathFontSetChanger dummy(pi.base, "cmr");
102 pi.draw(x, y, char_);
103 } else if ((char_ == '>' || char_ == '<') && has_math_fonts) {
104 MathFontSetChanger dummy(pi.base, "cmm");
105 pi.draw(x, y, char_);
106 } else if (slanted(char_) && pi.base.fontname == "mathnormal") {
107 MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
108 pi.draw(x, y, char_);
110 pi.draw(x, y, char_);
113 drawChar(pain, font_, x, y, char_);
118 void MathCharInset::metricsT(TextMetricsInfo const &) const
126 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
128 //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
129 pain.draw(x, y, char_);
133 void MathCharInset::write(WriteStream & os) const
139 void MathCharInset::normalize(NormalStream & os) const
141 os << "[char " << char_ << " " << "mathalpha" << "]";
145 void MathCharInset::octavize(OctaveStream & os) const
151 bool MathCharInset::isRelOp() const
153 return char_ == '=' || char_ == '<' || char_ == '>';
157 bool MathCharInset::match(MathInset const * p) const
159 MathCharInset const * q = p->asCharInset();
160 return q && char_ == q->char_;