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