3 * Purpose: Implementation of the root object
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1999
6 * Description: Root math object
8 * Copyright: 1999 Alejandro Aguilar Sierra
10 * You are free to use and modify this code under the terms of
11 * the GNU General Public Licence version 2 or later.
15 #pragma implementation
18 #include "math_rootinset.h"
19 #include "math_mathmlstream.h"
20 #include "frontends/Painter.h"
26 MathRootInset::MathRootInset()
31 MathInset * MathRootInset::clone() const
33 return new MathRootInset(*this);
37 void MathRootInset::metrics(MathMetricsInfo & mi) const
39 MathNestInset::metrics(mi);
40 dim_.a = max(cell(0).ascent() + 5, cell(1).ascent()) + 2;
41 dim_.d = max(cell(1).descent() + 5, cell(0).descent()) + 2;
42 dim_.w = cell(0).width() + cell(1).width() + 10;
47 void MathRootInset::draw(MathPainterInfo & pi, int x, int y) const
49 int const w = cell(0).width();
51 cell(0).draw(pi, x, y - 5 - cell(0).descent());
53 cell(1).draw(pi, x + w + 8, y);
54 int const a = ascent();
55 int const d = descent();
58 xp[0] = x + width(); yp[0] = y - a + 1;
59 xp[1] = x + w + 4; yp[1] = y - a + 1;
60 xp[2] = x + w; yp[2] = y + d;
61 xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
62 //xp[4] = x; yp[4] = y + (d - a)/2 + 2;
63 xp[4] = x + w - 5; yp[4] = y + (d - a)/2 + 4;
64 pi.pain.lines(xp, yp, 5, LColor::math);
65 drawMarkers(pi, x, y);
69 void MathRootInset::write(WriteStream & os) const
71 os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
75 void MathRootInset::normalize(NormalStream & os) const
77 os << "[root " << cell(0) << ' ' << cell(1) << ']';
81 bool MathRootInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, int) const
83 bool target = !up; // up ? 0 : 1;
87 pos = target ? 0 : cell(0).size();
92 void MathRootInset::maplize(MapleStream & os) const
94 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
98 void MathRootInset::octavize(OctaveStream & os) const
100 os << "root(" << cell(1) << ',' << cell(0) << ')';
104 void MathRootInset::mathmlize(MathMLStream & os) const
106 os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");