1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
* File: math_root.C
|
|
|
|
* Purpose: Implementation of the root object
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1999
|
|
|
|
* Description: Root math object
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1999 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_rootinset.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "Painter.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::max;
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathRootInset::MathRootInset()
|
2001-08-03 17:10:22 +00:00
|
|
|
: MathNestInset(2)
|
2001-02-28 11:56:36 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathRootInset::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return new MathRootInset(*this);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
void MathRootInset::metrics(MathMetricsInfo const & mi) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
MathNestInset::metrics(mi);
|
2002-02-16 15:59:55 +00:00
|
|
|
ascent_ = max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
|
|
|
|
descent_ = max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
|
2001-06-25 00:06:33 +00:00
|
|
|
width_ = xcell(0).width() + xcell(1).width() + 10;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathRootInset::draw(Painter & pain, int x, int y) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
int const w = xcell(0).width();
|
2002-02-16 15:59:55 +00:00
|
|
|
// the "exponent"
|
|
|
|
xcell(0).draw(pain, x, y - 5 - xcell(0).descent());
|
|
|
|
// the "base"
|
|
|
|
xcell(1).draw(pain, x + w + 8, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
int const a = ascent();
|
|
|
|
int const d = descent();
|
|
|
|
int xp[5];
|
|
|
|
int yp[5];
|
|
|
|
xp[0] = x + width_; yp[0] = y - a + 1;
|
|
|
|
xp[1] = x + w + 4; yp[1] = y - a + 1;
|
|
|
|
xp[2] = x + w; yp[2] = y + d;
|
|
|
|
xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
|
|
|
|
xp[4] = x; yp[4] = y + (d - a)/2 + 2;
|
2001-12-03 16:24:50 +00:00
|
|
|
pain.lines(xp, yp, 5, LColor::math);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathRootInset::write(WriteStream & os) const
|
2000-03-07 01:14:37 +00:00
|
|
|
{
|
2001-10-19 11:25:48 +00:00
|
|
|
os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
2001-04-27 12:35:55 +00:00
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathRootInset::normalize(NormalStream & os) const
|
2001-04-25 15:43:57 +00:00
|
|
|
{
|
2002-03-21 09:48:46 +00:00
|
|
|
os << "[root " << cell(0) << ' ' << cell(1) << ']';
|
2001-04-25 15:43:57 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
2002-03-21 09:48:46 +00:00
|
|
|
bool MathRootInset::idxUpDown(idx_type & idx, bool up) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-03-21 09:48:46 +00:00
|
|
|
bool target = !up; // up ? 0 : 1;
|
|
|
|
if (idx == target)
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2002-03-21 09:48:46 +00:00
|
|
|
idx = target;
|
2001-06-25 00:06:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-11-07 13:15:59 +00:00
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathRootInset::octavize(OctaveStream & os) const
|
2001-11-07 13:15:59 +00:00
|
|
|
{
|
2001-11-07 17:30:26 +00:00
|
|
|
os << "root(" << cell(1) << ',' << cell(0) <<')';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathRootInset::mathmlize(MathMLStream & os) const
|
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
|
2001-11-07 13:15:59 +00:00
|
|
|
}
|