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"
26 MathRootInset::MathRootInset()
31 MathInset * MathRootInset::clone() const
33 return new MathRootInset(*this);
37 void MathRootInset::metrics(MathMetricsInfo const & mi) const
39 MathNestInset::metrics(mi);
40 ascent_ = max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
41 descent_ = max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
42 width_ = xcell(0).width() + xcell(1).width() + 10;
46 void MathRootInset::draw(Painter & pain, int x, int y) const
48 int const w = xcell(0).width();
50 xcell(0).draw(pain, x, y - 5 - xcell(0).descent());
52 xcell(1).draw(pain, x + w + 8, y);
53 int const a = ascent();
54 int const d = descent();
57 xp[0] = x + width_; yp[0] = y - a + 1;
58 xp[1] = x + w + 4; yp[1] = y - a + 1;
59 xp[2] = x + w; yp[2] = y + d;
60 xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
61 xp[4] = x; yp[4] = y + (d - a)/2 + 2;
62 pain.lines(xp, yp, 5, LColor::math);
66 void MathRootInset::write(WriteStream & os) const
68 os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
72 void MathRootInset::normalize(NormalStream & os) const
74 os << "[root " << cell(0) << ' ' << cell(1) << ']';
78 bool MathRootInset::idxUpDown(idx_type & idx, bool up) const
80 bool target = !up; // up ? 0 : 1;
88 void MathRootInset::octavize(OctaveStream & os) const
90 os << "root(" << cell(1) << ',' << cell(0) <<')';
94 void MathRootInset::mathmlize(MathMLStream & os) const
96 os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");