1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
* File: math_root.C
|
2002-03-21 17:42:56 +00:00
|
|
|
* Purpose: Implementation of the root object
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
1999-09-27 18:44:28 +00:00
|
|
|
* 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"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/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
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathRootInset::metrics(MathMetricsInfo & mi) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
MathNestInset::metrics(mi);
|
2002-08-02 14:29:42 +00:00
|
|
|
dim_.a = max(cell(0).ascent() + 5, cell(1).ascent()) + 2;
|
|
|
|
dim_.d = max(cell(1).descent() + 5, cell(0).descent()) + 2;
|
|
|
|
dim_.w = cell(0).width() + cell(1).width() + 10;
|
2002-07-30 13:56:02 +00:00
|
|
|
metricsMarkers();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-26 13:13:20 +00:00
|
|
|
void MathRootInset::draw(MathPainterInfo & pi, int x, int y) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
int const w = cell(0).width();
|
2002-02-16 15:59:55 +00:00
|
|
|
// the "exponent"
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).draw(pi, x, y - 5 - cell(0).descent());
|
2002-02-16 15:59:55 +00:00
|
|
|
// the "base"
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(1).draw(pi, 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];
|
2002-07-11 11:27:24 +00:00
|
|
|
xp[0] = x + width(); yp[0] = y - a + 1;
|
2001-06-25 00:06:33 +00:00
|
|
|
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;
|
2002-08-05 08:44:08 +00:00
|
|
|
//xp[4] = x; yp[4] = y + (d - a)/2 + 2;
|
|
|
|
xp[4] = x + w - 5; yp[4] = y + (d - a)/2 + 4;
|
2002-07-26 13:13:20 +00:00
|
|
|
pi.pain.lines(xp, yp, 5, LColor::math);
|
2002-07-30 13:56:02 +00:00
|
|
|
drawMarkers(pi, x, y);
|
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-07-30 13:56:02 +00:00
|
|
|
bool MathRootInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, int) 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;
|
2002-07-30 13:56:02 +00:00
|
|
|
pos = target ? 0 : cell(0).size();
|
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
|
|
|
}
|