]> git.lyx.org Git - lyx.git/blob - src/mathed/math_spaceinset.C
architectural changes to tex2lyx
[lyx.git] / src / mathed / math_spaceinset.C
1 #include "math_spaceinset.h"
2 #include "math_data.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 using std::auto_ptr;
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 auto_ptr<InsetBase> MathSpaceInset::clone() const
37 {
38         return auto_ptr<InsetBase>(new MathSpaceInset(*this));
39 }
40
41
42 void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const
43 {
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 }
60
61
62 void MathSpaceInset::draw(PainterInfo & pi, int x, int y) const
63 {
64
65 // Sadly, HP-UX CC can't handle that kind of initialization.
66 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
67         if (space_ >= nSpace - 2)
68                 return;
69
70         int xp[4];
71         int yp[4];
72
73         xp[0] = ++x;               yp[0] = y - 3;
74         xp[1] = x;                 yp[1] = y;
75         xp[2] = x + pi.width - 2;  yp[2] = y;
76         xp[3] = x + pi.width - 2;  yp[3] = y - 3;
77
78         pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
79 }
80
81
82 void MathSpaceInset::incSpace()
83 {
84         space_ = (space_ + 1) % (nSpace - 2);
85 }
86
87
88 void MathSpaceInset::validate(LaTeXFeatures & features) const
89 {
90         if (space_ >= 0 && space_< nSpace) {
91                 if ((latex_mathspace[space_] == "negmedspace")
92                  || (latex_mathspace[space_] == "negthickspace"))
93                         features.require("amsmath");
94         }
95 }
96
97
98 void MathSpaceInset::maple(MapleStream & os) const
99 {
100         os << ' ';
101 }
102
103 void MathSpaceInset::mathematica(MathematicaStream & os) const
104 {
105         os << ' ';
106 }
107
108
109 void MathSpaceInset::octave(OctaveStream & os) const
110 {
111         os << ' ';
112 }
113
114
115 void MathSpaceInset::normalize(NormalStream & os) const
116 {
117         os << "[space " << int(space_) << "] ";
118 }
119
120
121 void MathSpaceInset::write(WriteStream & os) const
122 {
123         if (space_ >= 0 && space_ < nSpace) {
124                 os << '\\' << latex_mathspace[space_];
125                 os.pendingSpace(true);
126         }
127 }