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"
25 char const * latex_mathspace[] = {
26 "!", "negmedspace", "negthickspace", // negative space
27 ",", ":", ";", "quad", "qquad", // positive space
28 "lyxnegspace", "lyxposspace" // LyX special ("unvisible space")
31 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
34 MathSpaceInset::MathSpaceInset(int sp)
39 MathSpaceInset::MathSpaceInset(string const & name)
42 for (int i = 0; i < nSpace; ++i)
43 if (latex_mathspace[i] == name)
48 auto_ptr<InsetBase> MathSpaceInset::clone() const
50 return auto_ptr<InsetBase>(new MathSpaceInset(*this));
54 void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const
57 case 0: dim.wid = 6; break;
58 case 1: dim.wid = 8; break;
59 case 2: dim.wid = 10; break;
60 case 3: dim.wid = 6; break;
61 case 4: dim.wid = 8; break;
62 case 5: dim.wid = 10; break;
63 case 6: dim.wid = 20; break;
64 case 7: dim.wid = 40; break;
65 case 8: dim.wid = -2; break;
66 case 9: dim.wid = 2; break;
74 void MathSpaceInset::draw(PainterInfo & pi, int x, int y) const
77 // Sadly, HP-UX CC can't handle that kind of initialization.
78 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
79 if (space_ >= nSpace - 2)
85 xp[0] = ++x; yp[0] = y - 3;
87 xp[2] = x + pi.width - 2; yp[2] = y;
88 xp[3] = x + pi.width - 2; yp[3] = y - 3;
90 pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
94 void MathSpaceInset::incSpace()
96 space_ = (space_ + 1) % (nSpace - 2);
100 void MathSpaceInset::validate(LaTeXFeatures & features) const
102 if (space_ >= 0 && space_< nSpace) {
103 if ((latex_mathspace[space_] == "negmedspace")
104 || (latex_mathspace[space_] == "negthickspace"))
105 features.require("amsmath");
110 void MathSpaceInset::maple(MapleStream & os) const
115 void MathSpaceInset::mathematica(MathematicaStream & os) const
121 void MathSpaceInset::octave(OctaveStream & os) const
127 void MathSpaceInset::normalize(NormalStream & os) const
129 os << "[space " << int(space_) << "] ";
133 void MathSpaceInset::write(WriteStream & os) const
135 if (space_ >= 0 && space_ < nSpace) {
136 os << '\\' << latex_mathspace[space_];
137 os.pendingSpace(true);