]> git.lyx.org Git - lyx.git/blob - src/mathed/math_spaceinset.C
Prepare mathed for unified two-stage drawing
[lyx.git] / src / mathed / math_spaceinset.C
1
2 #include "math_spaceinset.h"
3 #include "math_support.h"
4 #include "LColor.h"
5 #include "frontends/Painter.h"
6 #include "math_mathmlstream.h"
7 #include "LaTeXFeatures.h"
8 #include "debug.h"
9
10
11 char const * latex_mathspace[] = {
12         "!", "negmedspace", "negthickspace",  // negative space
13         ",", ":", ";", "quad", "qquad",       // positive space
14         "lyxnegspace", "lyxposspace"          // LyX special ("unvisible space")
15 };
16
17 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
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 < nSpace; ++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 Dimension MathSpaceInset::metrics(MetricsInfo &) const
42 {
43         Dimension dim;
44         switch (space_) {
45                 case 0: dim.wid = 6; break;
46                 case 1: dim.wid = 8; break;
47                 case 2: dim.wid = 10; break;
48                 case 3: dim.wid = 6; break;
49                 case 4: dim.wid = 8; break;
50                 case 5: dim.wid = 10; break;
51                 case 6: dim.wid = 20; break;
52                 case 7: dim.wid = 40; break;
53                 case 8: dim.wid = -2; break;
54                 case 9: dim.wid =  2; break;
55                 default: dim.wid = 6;
56         }
57         dim.asc = 4;
58         dim.des = 0;
59         return dim;
60 }
61
62
63 void MathSpaceInset::draw(PainterInfo & 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 + pi.width - 2;  yp[2] = y;
77         xp[3] = x + pi.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::validate(LaTeXFeatures & features) const
90 {
91         if (space_ >= 0 && space_< nSpace) {
92                 if ((latex_mathspace[space_] == "negmedspace")
93                  || (latex_mathspace[space_] == "negthickspace"))
94                         features.require("amsmath");
95         }
96 }
97
98
99 void MathSpaceInset::maple(MapleStream & os) const
100 {
101         os << ' ';
102 }
103
104 void MathSpaceInset::mathematica(MathematicaStream & os) const
105 {
106         os << ' ';
107 }
108
109
110 void MathSpaceInset::octave(OctaveStream & os) const
111 {
112         os << ' ';
113 }
114
115
116 void MathSpaceInset::normalize(NormalStream & os) const
117 {
118         os << "[space " << int(space_) << "] ";
119 }
120
121
122 void MathSpaceInset::write(WriteStream & os) const
123 {
124         if (space_ >= 0 && space_ < nSpace) {
125                 os << '\\' << latex_mathspace[space_];
126                 os.pendingSpace(true);
127         }
128 }