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