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
22 #include "math_root.h"
23 #include "support/LOstream.h"
26 MathRootInset::MathRootInset()
27 : MathInset("sqrt", LM_OT_SQRT, 2)
31 MathInset * MathRootInset::clone() const
33 return new MathRootInset(*this);
37 void MathRootInset::Metrics(MathStyles st)
39 MathInset::Metrics(st);
41 ascent_ = std::max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
42 descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
43 width_ = xcell(0).width() + xcell(1).width() + 10;
47 void MathRootInset::draw(Painter & pain, int x, int y)
51 int const w = xcell(0).width();
52 xcell(0).draw(pain, x, y - 5 - xcell(0).descent()); // the "exponent"
53 xcell(1).draw(pain, x + w + 8, y); // the "base"
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 pain.lines(xp, yp, 5, LColor::mathline);
67 void MathRootInset::Write(std::ostream & os, bool fragile) const
70 cell(0).Write(os, fragile);
72 cell(1).Write(os, fragile);
77 void MathRootInset::WriteNormal(std::ostream & os) const
80 cell(1).WriteNormal(os);
82 cell(0).WriteNormal(os);
86 bool MathRootInset::idxUp(int & idx, int & pos) const
95 bool MathRootInset::idxDown(int & idx, int & pos) const