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_root.h"
19 #include "support/LOstream.h"
22 MathRootInset::MathRootInset()
27 MathInset * MathRootInset::clone() const
29 return new MathRootInset(*this);
33 void MathRootInset::Metrics(MathStyles st, int, int)
35 MathInset::Metrics(st);
37 ascent_ = std::max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
38 descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
39 width_ = xcell(0).width() + xcell(1).width() + 10;
43 void MathRootInset::draw(Painter & pain, int x, int y)
47 int const w = xcell(0).width();
48 xcell(0).draw(pain, x, y - 5 - xcell(0).descent()); // the "exponent"
49 xcell(1).draw(pain, x + w + 8, y); // the "base"
50 int const a = ascent();
51 int const d = descent();
54 xp[0] = x + width_; yp[0] = y - a + 1;
55 xp[1] = x + w + 4; yp[1] = y - a + 1;
56 xp[2] = x + w; yp[2] = y + d;
57 xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
58 xp[4] = x; yp[4] = y + (d - a)/2 + 2;
59 pain.lines(xp, yp, 5, LColor::mathline);
63 void MathRootInset::Write(std::ostream & os, bool fragile) const
66 cell(0).Write(os, fragile);
68 cell(1).Write(os, fragile);
73 void MathRootInset::WriteNormal(std::ostream & os) const
76 cell(1).WriteNormal(os);
78 cell(0).WriteNormal(os);
82 bool MathRootInset::idxUp(int & idx, int & pos) const
91 bool MathRootInset::idxDown(int & idx, int & pos) const