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 int MathSpaceInset::width() const
72 int MathSpaceInset::ascent() const
78 int MathSpaceInset::descent() const
84 void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const
92 void MathSpaceInset::draw(PainterInfo & pi, int x, int y) const
94 // Sadly, HP-UX CC can't handle that kind of initialization.
95 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
96 if (space_ >= nSpace - 2)
103 xp[0] = ++x; yp[0] = y - 3;
104 xp[1] = x; yp[1] = y;
105 xp[2] = x + w - 2; yp[2] = y;
106 xp[3] = x + w - 2; yp[3] = y - 3;
108 pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
112 void MathSpaceInset::incSpace()
114 space_ = (space_ + 1) % (nSpace - 2);
118 void MathSpaceInset::validate(LaTeXFeatures & features) const
120 if (space_ >= 0 && space_< nSpace) {
121 if ((latex_mathspace[space_] == "negmedspace")
122 || (latex_mathspace[space_] == "negthickspace"))
123 features.require("amsmath");
128 void MathSpaceInset::maple(MapleStream & os) const
133 void MathSpaceInset::mathematica(MathematicaStream & os) const
139 void MathSpaceInset::octave(OctaveStream & os) const
145 void MathSpaceInset::normalize(NormalStream & os) const
147 os << "[space " << int(space_) << "] ";
151 void MathSpaceInset::write(WriteStream & os) const
153 if (space_ >= 0 && space_ < nSpace) {
154 os << '\\' << latex_mathspace[space_];
155 os.pendingSpace(true);