2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_rootinset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
|
#include <config.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-17 07:38:41 +00:00
|
|
|
|
#include "math_rootinset.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_data.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "LColor.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;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> MathRootInset::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathRootInset(*this));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathRootInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
|
MathNestInset::metrics(mi);
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.asc = max(cell(0).ascent() + 5, cell(1).ascent()) + 2;
|
|
|
|
|
dim_.des = max(cell(1).descent() + 5, cell(0).descent()) + 2;
|
|
|
|
|
dim_.wid = cell(0).width() + cell(1).width() + 10;
|
2003-05-28 13:22:36 +00:00
|
|
|
|
metricsMarkers(1);
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim = dim_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathRootInset::draw(PainterInfo & 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);
|
2003-05-28 13:22:36 +00:00
|
|
|
|
int const a = dim_.ascent();
|
|
|
|
|
int const d = dim_.descent();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
int xp[5];
|
|
|
|
|
int yp[5];
|
2003-05-28 13:22:36 +00:00
|
|
|
|
xp[0] = x + dim_.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;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathRootInset::maple(MapleStream & os) const
|
2002-10-28 17:15:19 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
|
2002-10-28 17:15:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathRootInset::octave(OctaveStream & os) const
|
2001-11-07 13:15:59 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "root(" << cell(1) << ',' << cell(0) << ')';
|
2001-11-07 17:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|