9 #include "math_charinset.h"
12 #include "support/LOstream.h"
13 #include "math_support.h"
14 #include "math_parser.h"
16 #include "math_mathmlstream.h"
17 #include "LaTeXFeatures.h"
18 #include "textpainter.h"
24 MathCharInset::MathCharInset(char c)
25 : char_(c), code_(nativeCode(c))
27 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
31 MathCharInset::MathCharInset(char c, MathTextCodes t)
32 : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
34 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
38 MathTextCodes MathCharInset::nativeCode(char c)
42 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
47 MathInset * MathCharInset::clone() const
49 return new MathCharInset(*this);
53 void MathCharInset::metrics(MathMetricsInfo const & mi) const
55 whichFont(font_, code_, mi);
56 mathed_char_dim(font_, char_, ascent_, descent_, width_);
60 void MathCharInset::draw(Painter & pain, int x, int y) const
62 //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
63 drawChar(pain, font_, x, y, char_);
67 void MathCharInset::metrics(TextMetricsInfo const &) const
75 void MathCharInset::draw(TextPainter & pain, int x, int y) const
77 lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
78 pain.draw(x, y, char_);
82 void MathCharInset::writeHeader(ostream & os) const
84 if (math_font_name(code_))
85 os << '\\' << math_font_name(code_) << '{';
89 void MathCharInset::writeTrailer(ostream & os) const
91 if (math_font_name(code_))
96 void MathCharInset::writeRaw(ostream & os) const
102 void MathCharInset::write(WriteStream & os) const
104 writeHeader(os.os());
106 writeTrailer(os.os());
110 void MathCharInset::normalize(NormalStream & os) const
112 os << "[char " << char_ << " " << "mathalpha" << "]";
116 bool MathCharInset::isRelOp() const
118 return char_ == '=' || char_ == '<' || char_ == '>';
122 void MathCharInset::handleFont(MathTextCodes t)
124 code_ = (code_ == t) ? LM_TC_VAR : t;
128 void MathCharInset::validate(LaTeXFeatures & features) const
130 // Make sure amssymb is put in preamble if Blackboard Bold or
132 if ((code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK))
133 features.require("amssymb");
137 bool MathCharInset::match(MathInset * p) const
139 MathCharInset const * q = p->asCharInset();
140 return q && char_ == q->char_ && code_ == q->code_;