]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
whichFont down to 9%...
[lyx.git] / src / mathed / math_charinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include <cctype>
8
9 #include "math_charinset.h"
10 #include "LColor.h"
11 #include "Painter.h"
12 #include "support/LOstream.h"
13 #include "math_support.h"
14 #include "math_parser.h"
15 #include "debug.h"
16 #include "math_mathmlstream.h"
17 #include "LaTeXFeatures.h"
18
19
20 MathCharInset::MathCharInset(char c)
21         : char_(c), code_(nativeCode(c))
22 {
23 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
24 }
25
26
27 MathCharInset::MathCharInset(char c, MathTextCodes t)
28         : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
29 {
30 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
31 }
32
33
34 MathTextCodes MathCharInset::nativeCode(char c)
35 {
36         if (isalpha(c))
37                 return LM_TC_VAR;
38         //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
39         return LM_TC_CONST;
40 }
41
42
43 MathInset * MathCharInset::clone() const
44 {   
45         return new MathCharInset(*this);
46 }
47
48
49 void MathCharInset::metrics(MathMetricsInfo const & mi) const
50 {
51         mi_ = mi;
52         ascent_  = mathed_char_ascent(code_, mi_, char_);
53         descent_ = mathed_char_descent(code_, mi_, char_);
54         width_   = mathed_char_width(code_, mi_, char_);
55 }
56
57
58 void MathCharInset::draw(Painter & pain, int x, int y) const
59
60         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
61         drawChar(pain, code_, mi_, x, y, char_);
62 }
63
64
65 void MathCharInset::writeHeader(std::ostream & os) const
66 {
67         if (math_font_name(code_))
68                 os << '\\' << math_font_name(code_) << '{';
69 }
70
71
72 void MathCharInset::writeTrailer(std::ostream & os) const
73 {
74         if (math_font_name(code_))
75                 os << '}';
76 }
77
78
79 void MathCharInset::writeRaw(std::ostream & os) const
80 {
81         os << char_;
82 }
83
84
85 void MathCharInset::write(WriteStream & os) const
86 {
87         writeHeader(os.os());
88         writeRaw(os.os());
89         writeTrailer(os.os());
90 }
91
92
93 void MathCharInset::normalize(NormalStream & os) const
94 {
95         os << "[char " << char_ << " " << "mathalpha" << "]";
96 }
97
98
99 bool MathCharInset::isRelOp() const
100 {
101         return char_ == '=' || char_ == '<' || char_ == '>';
102 }
103
104
105 void MathCharInset::handleFont(MathTextCodes t)
106 {
107         code_ = (code_ == t) ? LM_TC_VAR : t;
108 }
109
110
111 void MathCharInset::validate(LaTeXFeatures & features) const
112 {
113         // Make sure amssymb is put in preamble if Blackboard Bold or
114         // Fraktur used:
115         if ( (code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK) )
116                 features.require("amssymb");
117 }
118
119
120 bool MathCharInset::match(MathInset * p) const
121 {
122         MathCharInset const * q = p->asCharInset();
123         return q && char_ == q->char_ && code_ == q->code_;
124 }