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 "math_mathmlstream.h"
17 #include "LaTeXFeatures.h"
20 #include "frontends/Painter.h"
26 char const * latex_mathspace[] = {
27 "!", "negmedspace", "negthickspace", // negative space
28 ",", ":", ";", "quad", "qquad", // positive space
29 "lyxnegspace", "lyxposspace" // LyX special ("unvisible space")
32 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
35 MathSpaceInset::MathSpaceInset(int sp)
40 MathSpaceInset::MathSpaceInset(string const & name)
43 for (int i = 0; i < nSpace; ++i)
44 if (latex_mathspace[i] == name)
49 auto_ptr<InsetBase> MathSpaceInset::doClone() const
51 return auto_ptr<InsetBase>(new MathSpaceInset(*this));
55 int MathSpaceInset::width() const
73 int MathSpaceInset::ascent() const
79 int MathSpaceInset::descent() const
85 void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const
93 void MathSpaceInset::draw(PainterInfo & pi, int x, int y) const
95 // Sadly, HP-UX CC can't handle that kind of initialization.
96 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
97 if (space_ >= nSpace - 2)
104 xp[0] = ++x; yp[0] = y - 3;
105 xp[1] = x; yp[1] = y;
106 xp[2] = x + w - 2; yp[2] = y;
107 xp[3] = x + w - 2; yp[3] = y - 3;
109 pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
113 void MathSpaceInset::incSpace()
115 space_ = (space_ + 1) % (nSpace - 2);
119 void MathSpaceInset::validate(LaTeXFeatures & features) const
121 if (space_ >= 0 && space_< nSpace) {
122 if ((latex_mathspace[space_] == string("negmedspace"))
123 || (latex_mathspace[space_] == string("negthickspace")))
124 features.require("amsmath");
129 void MathSpaceInset::maple(MapleStream & os) const
134 void MathSpaceInset::mathematica(MathematicaStream & os) const
140 void MathSpaceInset::octave(OctaveStream & os) const
146 void MathSpaceInset::normalize(NormalStream & os) const
148 os << "[space " << int(space_) << "] ";
152 void MathSpaceInset::write(WriteStream & os) const
154 if (space_ >= 0 && space_ < nSpace) {
155 os << '\\' << latex_mathspace[space_];
156 os.pendingSpace(true);