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