]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
first shot at preview. It crashes. Don't know why. To see it work a bit, change
[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_, ascent_, descent_, width_);
66         } else {
67                 mathed_char_dim(mi.base.font, char_, ascent_, descent_, width_);
68         }
69         if (isBinaryOp(char_))
70                 width_ += 2 * font_metrics::width(' ', mi.base.font);
71 #else
72         whichFont(font_, code_, mi);
73         mathed_char_dim(font_, char_, ascent_, descent_, width_);
74         if (isBinaryOp(char_, code_))
75                 width_ += 2 * font_metrics::width(' ', font_);
76 #endif
77 }
78
79
80 void MathCharInset::draw(MathPainterInfo & pi, int x, int y) const
81 {
82         //lyxerr << "drawing '" << char_ << "' font: " << pi.base.fontname << endl;
83         if (isBinaryOp(char_))
84                 x += font_metrics::width(' ', pi.base.font);
85 #if 1
86         if (slanted(char_) && pi.base.fontname == "mathnormal") {
87                 MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
88                 pi.draw(x, y, char_);
89         } else {
90                 pi.draw(x, y, char_);
91         }
92 #else
93         drawChar(pain, font_, x, y, char_);
94 #endif
95 }
96
97
98 void MathCharInset::metricsT(TextMetricsInfo const &) const
99 {
100         width_   = 1;
101         ascent_  = 1;
102         descent_ = 0;
103 }
104
105
106 void MathCharInset::drawT(TextPainter & pain, int x, int y) const
107 {
108         //lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
109         pain.draw(x, y, char_);
110 }
111
112
113 void MathCharInset::write(WriteStream & os) const
114 {
115         os << char_;
116 }
117
118
119 void MathCharInset::normalize(NormalStream & os) const
120 {
121         os << "[char " << char_ << " " << "mathalpha" << "]";
122 }
123
124
125 void MathCharInset::octavize(OctaveStream & os) const
126 {
127         os << char_;
128 }
129
130
131 bool MathCharInset::isRelOp() const
132 {
133         return char_ == '=' || char_ == '<' || char_ == '>';
134 }
135
136
137 bool MathCharInset::match(MathInset * p) const
138 {
139         MathCharInset const * q = p->asCharInset();
140         return q && char_ == q->char_;
141 }