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"
26 InsetMathRoot::InsetMathRoot()
31 Inset * InsetMathRoot::clone() const
33 return new InsetMathRoot(*this);
37 void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
40 InsetMathNest::metrics(mi);
41 Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
42 Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
43 dim.asc = max(dim0.ascent() + 5, dim1.ascent()) + 2;
44 dim.des = max(dim0.descent() - 5, dim1.descent()) + 2;
45 dim.wid = dim0.width() + dim1.width() + 10;
47 // Cache the inset dimension.
52 void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
54 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
55 int const w = dim0.width();
57 cell(0).draw(pi, x, y - 5 - dim0.descent());
59 cell(1).draw(pi, x + w + 8, y);
60 Dimension const dim = dimension(*pi.base.bv);
61 int const a = dim.ascent();
62 int const d = dim.descent();
65 pi.pain.line(x + dim.width(), y - a + 1,
66 x + w + 4, y - a + 1, Color::math);
67 xp[0] = x + w + 4; yp[0] = y - a + 1;
68 xp[1] = x + w; yp[1] = y + d;
69 xp[2] = x + w - 2; yp[2] = y + (d - a)/2 + 2;
70 xp[3] = x + w - 5; yp[3] = y + (d - a)/2 + 4;
71 pi.pain.lines(xp, yp, 4, Color::math);
72 drawMarkers(pi, x, y);
76 void InsetMathRoot::write(WriteStream & os) const
78 os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
82 void InsetMathRoot::normalize(NormalStream & os) const
84 os << "[root " << cell(0) << ' ' << cell(1) << ']';
88 bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const
90 Cursor::idx_type const target = up ? 0 : 1;
91 if (cur.idx() == target)
94 cur.pos() = up ? cur.lastpos() : 0;
99 void InsetMathRoot::maple(MapleStream & os) const
101 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
105 void InsetMathRoot::mathematica(MathematicaStream & os) const
107 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
111 void InsetMathRoot::octave(OctaveStream & os) const
113 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
117 void InsetMathRoot::mathmlize(MathStream & os) const
119 os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");