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