]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
a bit more const correctness
[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 "frontends/Painter.h"
10 #include "frontends/font_metrics.h"
11 #include "support/LOstream.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
25 #ifndef CXX_GLOBAL_CSTD
26 using std::strchr;
27 using std::isalpha;
28 #endif
29
30
31 namespace {
32
33         bool isBinaryOp(char c)
34         {
35                 return strchr("+-<>=/*", c);
36         }
37
38
39         bool slanted(char c)
40         {
41                 //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
42                 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
43         }
44
45 }
46
47
48 MathCharInset::MathCharInset(char c)
49         : char_(c)
50 {}
51
52
53
54 MathInset * MathCharInset::clone() const
55 {
56         return new MathCharInset(*this);
57 }
58
59
60 void MathCharInset::metrics(MathMetricsInfo & mi) const
61 {
62 #if 1
63         if (slanted(char_) && mi.base.fontname == "mathnormal") {
64                 MathShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE);
65                 mathed_char_dim(mi.base.font, char_, dim_);
66         } else {
67                 mathed_char_dim(mi.base.font, char_, dim_);
68         }
69         if (isBinaryOp(char_))
70                 dim_.w += 2 * font_metrics::width(' ', mi.base.font);
71 #else
72         whichFont(font_, code_, mi);
73         mathed_char_dim(font_, char_, dim_);
74         if (isBinaryOp(char_, code_))
75                 width_ += 2 * font_metrics::width(' ', font_);
76         lyxerr << "MathCharInset::metrics: " << dim_ << "\n";
77 #endif
78 }
79
80
81 void MathCharInset::draw(MathPainterInfo & pi, int x, int y) const
82 {
83         //lyxerr << "drawing '" << char_ << "' font: " << pi.base.fontname << endl;
84         if (isBinaryOp(char_))
85                 x += font_metrics::width(' ', pi.base.font);
86 #if 1
87         if (slanted(char_) && pi.base.fontname == "mathnormal") {
88                 MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
89                 pi.draw(x, y, char_);
90         } else {
91                 pi.draw(x, y, char_);
92         }
93 #else
94         drawChar(pain, font_, x, y, char_);
95 #endif
96 }
97
98
99 void MathCharInset::metricsT(TextMetricsInfo const &) const
100 {
101         dim_.w = 1;
102         dim_.a = 1;
103         dim_.d = 0;
104 }
105
106
107 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
108 {
109         //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
110         pain.draw(x, y, char_);
111 }
112
113
114 void MathCharInset::write(WriteStream & os) const
115 {
116         os << char_;
117 }
118
119
120 void MathCharInset::normalize(NormalStream & os) const
121 {
122         os << "[char " << char_ << " " << "mathalpha" << "]";
123 }
124
125
126 void MathCharInset::octavize(OctaveStream & os) const
127 {
128         os << char_;
129 }
130
131
132 bool MathCharInset::isRelOp() const
133 {
134         return char_ == '=' || char_ == '<' || char_ == '>';
135 }
136
137
138 bool MathCharInset::match(MathInset const * p) const
139 {
140         MathCharInset const * q = p->asCharInset();
141         return q && char_ == q->char_;
142 }