]> git.lyx.org Git - lyx.git/blob - src/mathed/math_spaceinset.C
preview as preview can...
[lyx.git] / src / mathed / math_spaceinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_spaceinset.h"
6 #include "math_support.h"
7 #include "LColor.h"
8 #include "frontends/Painter.h"
9 #include "math_mathmlstream.h"
10
11
12
13 char const * latex_mathspace[] = {
14         "!", ",", ";", ":", "quad", "qquad", "lyxnegspace", "lyxposspace"
15 };
16
17
18
19
20 MathSpaceInset::MathSpaceInset(int sp)
21         : space_(sp)
22 {}
23
24
25 MathSpaceInset::MathSpaceInset(string const & name)
26         : space_(1)
27 {
28         for (int i = 0; i < 8; ++i) 
29                 if (latex_mathspace[i] == name) 
30                         space_ = i;
31 }
32
33
34
35 MathInset * MathSpaceInset::clone() const
36 {
37         return new MathSpaceInset(*this);
38 }
39
40
41 void MathSpaceInset::metrics(MathMetricsInfo &) const
42 {
43         switch (space_) {
44                 case 0: width_ = 6; break;
45                 case 1: width_ = 6; break;
46                 case 2: width_ = 8; break;
47                 case 3: width_ = 10; break;
48                 case 4: width_ = 20; break;
49                 case 5: width_ = 40; break;
50                 case 6: width_ = -2; break;
51                 case 7: width_ =  2; break;
52                 default: width_ = 6; break;
53         }
54         ascent_  = 4;
55         descent_ = 0;
56 }
57
58
59 void MathSpaceInset::draw(MathPainterInfo & pain, int x, int y) const
60 {
61
62 // Sadly, HP-UX CC can't handle that kind of initialization.
63 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
64         if (space_ > 6)
65                 return;
66
67         int xp[4];
68         int yp[4];
69
70         xp[0] = ++x;             yp[0] = y - 3;
71         xp[1] = x;                   yp[1] = y;
72         xp[2] = x + width_ - 2;  yp[2] = y;
73         xp[3] = x + width_ - 2;  yp[3] = y - 3;
74
75         pain.pain.lines(xp, yp, 4, space_ ? LColor::latex : LColor::math);
76 }
77
78
79 void MathSpaceInset::incSpace()
80 {
81         space_ = (space_ + 1) % 6;
82 }
83
84
85 void MathSpaceInset::maplize(MapleStream & os) const
86 {
87         os << ' ';
88 }
89
90
91 void MathSpaceInset::octavize(OctaveStream & os) const
92 {
93         os << ' ';
94 }
95
96
97 void MathSpaceInset::normalize(NormalStream & os) const
98 {
99         os << "[space " << space_ << "] ";
100 }
101
102
103 void MathSpaceInset::write(WriteStream & os) const
104 {
105         if (space_ >= 0 && space_ < 8)
106                 os << '\\' << latex_mathspace[space_] << ' ';
107 }