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.
17 #pragma implementation
20 #include "math_root.h"
21 #include "support/LOstream.h"
24 MathRootInset::MathRootInset()
25 : MathInset("sqrt", LM_OT_SQRT, 2)
29 MathInset * MathRootInset::Clone() const
31 return new MathRootInset(*this);
35 void MathRootInset::Metrics(MathStyles st)
37 MathInset::Metrics(st);
39 ascent_ = max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
40 descent_ = max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
41 width_ = xcell(0).width() + xcell(1).width() + 10;
45 void MathRootInset::draw(Painter & pain, int x, int y)
49 int const w = xcell(0).width();
50 xcell(0).draw(pain, x, y - 5 - xcell(0).descent()); // the "exponent"
51 xcell(1).draw(pain, x + w + 8, y); // the "base"
52 int const a = ascent();
53 int const d = descent();
56 xp[0] = x + width_; yp[0] = y - a + 1;
57 xp[1] = x + w + 4; yp[1] = y - a + 1;
58 xp[2] = x + w; yp[2] = y + d;
59 xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
60 xp[4] = x; yp[4] = y + (d - a)/2 + 2;
61 pain.lines(xp, yp, 5, LColor::mathline);
65 void MathRootInset::Write(ostream & os, bool fragile) const
68 cell(0).Write(os, fragile);
70 cell(1).Write(os, fragile);
75 void MathRootInset::WriteNormal(ostream & os) const
78 cell(1).WriteNormal(os);
80 cell(0).WriteNormal(os);
84 bool MathRootInset::idxUp(int & idx, int & pos) const
93 bool MathRootInset::idxDown(int & idx, int & pos) const