2 * \file InsetMathRoot.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "InsetMathRoot.h"
16 #include "MathStream.h"
20 #include "frontends/Painter.h"
30 InsetMathRoot::InsetMathRoot()
35 auto_ptr<Inset> InsetMathRoot::doClone() const
37 return auto_ptr<Inset>(new InsetMathRoot(*this));
41 bool InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
43 InsetMathNest::metrics(mi);
44 dim.asc = max(cell(0).ascent() + 5, cell(1).ascent()) + 2;
45 dim.des = max(cell(0).descent() - 5, cell(1).descent()) + 2;
46 dim.wid = cell(0).width() + cell(1).width() + 10;
55 void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
57 int const w = cell(0).width();
59 cell(0).draw(pi, x, y - 5 - cell(0).descent());
61 cell(1).draw(pi, x + w + 8, y);
62 int const a = dim_.ascent();
63 int const d = dim_.descent();
66 pi.pain.line(x + dim_.width(), y - a + 1,
67 x + w + 4, y - a + 1, Color::math);
68 xp[0] = x + w + 4; yp[0] = y - a + 1;
69 xp[1] = x + w; yp[1] = y + d;
70 xp[2] = x + w - 2; yp[2] = y + (d - a)/2 + 2;
71 xp[3] = x + w - 5; yp[3] = y + (d - a)/2 + 4;
72 pi.pain.lines(xp, yp, 4, Color::math);
73 drawMarkers(pi, x, y);
77 void InsetMathRoot::write(WriteStream & os) const
79 os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
83 void InsetMathRoot::normalize(NormalStream & os) const
85 os << "[root " << cell(0) << ' ' << cell(1) << ']';
89 bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const
91 Cursor::idx_type const target = up ? 0 : 1;
92 if (cur.idx() == target)
95 cur.pos() = up ? cur.lastpos() : 0;
100 void InsetMathRoot::maple(MapleStream & os) const
102 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
106 void InsetMathRoot::mathematica(MathematicaStream & os) const
108 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
112 void InsetMathRoot::octave(OctaveStream & os) const
114 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
118 void InsetMathRoot::mathmlize(MathStream & os) const
120 os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");