2 * \file math_spaceinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "math_spaceinset.h"
14 #include "math_data.h"
15 #include "frontends/Painter.h"
16 #include "math_mathmlstream.h"
17 #include "LaTeXFeatures.h"
23 char const * latex_mathspace[] = {
24 "!", "negmedspace", "negthickspace", // negative space
25 ",", ":", ";", "quad", "qquad", // positive space
26 "lyxnegspace", "lyxposspace" // LyX special ("unvisible space")
29 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
32 MathSpaceInset::MathSpaceInset(int sp)
37 MathSpaceInset::MathSpaceInset(string const & name)
40 for (int i = 0; i < nSpace; ++i)
41 if (latex_mathspace[i] == name)
46 auto_ptr<InsetBase> MathSpaceInset::clone() const
48 return auto_ptr<InsetBase>(new MathSpaceInset(*this));
52 void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const
55 case 0: dim.wid = 6; break;
56 case 1: dim.wid = 8; break;
57 case 2: dim.wid = 10; break;
58 case 3: dim.wid = 6; break;
59 case 4: dim.wid = 8; break;
60 case 5: dim.wid = 10; break;
61 case 6: dim.wid = 20; break;
62 case 7: dim.wid = 40; break;
63 case 8: dim.wid = -2; break;
64 case 9: dim.wid = 2; break;
72 void MathSpaceInset::draw(PainterInfo & pi, int x, int y) const
75 // Sadly, HP-UX CC can't handle that kind of initialization.
76 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
77 if (space_ >= nSpace - 2)
83 xp[0] = ++x; yp[0] = y - 3;
85 xp[2] = x + pi.width - 2; yp[2] = y;
86 xp[3] = x + pi.width - 2; yp[3] = y - 3;
88 pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
92 void MathSpaceInset::incSpace()
94 space_ = (space_ + 1) % (nSpace - 2);
98 void MathSpaceInset::validate(LaTeXFeatures & features) const
100 if (space_ >= 0 && space_< nSpace) {
101 if ((latex_mathspace[space_] == "negmedspace")
102 || (latex_mathspace[space_] == "negthickspace"))
103 features.require("amsmath");
108 void MathSpaceInset::maple(MapleStream & os) const
113 void MathSpaceInset::mathematica(MathematicaStream & os) const
119 void MathSpaceInset::octave(OctaveStream & os) const
125 void MathSpaceInset::normalize(NormalStream & os) const
127 os << "[space " << int(space_) << "] ";
131 void MathSpaceInset::write(WriteStream & os) const
133 if (space_ >= 0 && space_ < nSpace) {
134 os << '\\' << latex_mathspace[space_];
135 os.pendingSpace(true);