]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
ea37bf58d588cb4ee966a610dd083ecbf245b8ac
[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 int MathCharInset::ascent() const
50 {
51         return mathed_char_ascent(code_, mi_, char_);
52 }
53
54
55 int MathCharInset::descent() const
56 {
57         return mathed_char_descent(code_, mi_, char_);
58 }
59
60
61 int MathCharInset::width() const
62 {
63         return mathed_char_width(code_, mi_, char_);
64 }
65
66
67 void MathCharInset::metrics(MathMetricsInfo const & mi) const
68 {
69         mi_ = mi;
70 }
71
72
73 void MathCharInset::draw(Painter & pain, int x, int y) const
74
75         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
76         drawChar(pain, code_, mi_, x, y, char_);
77 }
78
79
80 void MathCharInset::writeHeader(std::ostream & os) const
81 {
82         if (math_font_name(code_))
83                 os << '\\' << math_font_name(code_) << '{';
84 }
85
86
87 void MathCharInset::writeTrailer(std::ostream & os) const
88 {
89         if (math_font_name(code_))
90                 os << '}';
91 }
92
93
94 void MathCharInset::writeRaw(std::ostream & os) const
95 {
96         os << char_;
97 }
98
99
100 void MathCharInset::write(WriteStream & os) const
101 {
102         writeHeader(os.os());
103         writeRaw(os.os());
104         writeTrailer(os.os());
105 }
106
107
108 void MathCharInset::normalize(NormalStream & os) const
109 {
110         os << "[char " << char_ << " " << "mathalpha" << "]";
111 }
112
113
114 bool MathCharInset::isRelOp() const
115 {
116         return char_ == '=' || char_ == '<' || char_ == '>';
117 }
118
119
120 void MathCharInset::handleFont(MathTextCodes t)
121 {
122         code_ = (code_ == t) ? LM_TC_VAR : t;
123 }
124
125
126 void MathCharInset::validate(LaTeXFeatures & features) const
127 {
128         // Make sure amssymb is put in preamble if Blackboard Bold or
129         // Fraktur used:
130         if ( (code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK) )
131                 features.require("amssymb");
132 }
133
134
135 bool MathCharInset::match(MathInset * p) const
136 {
137         MathCharInset const * q = p->asCharInset();
138         return q && char_ == q->char_ && code_ == q->code_;
139 }