2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathRoot.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
* 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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pö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
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathRoot.h"
|
2010-03-31 20:31:04 +00:00
|
|
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
#include "frontends/Painter.h"
|
2001-10-22 15:37:49 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathRoot::InsetMathRoot(Buffer * buf)
|
|
|
|
: InsetMathNest(buf, 2)
|
2001-02-28 11:56:36 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathRoot::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathRoot(*this);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathNest::metrics(mi);
|
2007-09-24 13:52:04 +00:00
|
|
|
Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
|
|
|
|
Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
|
|
|
|
dim.asc = max(dim0.ascent() + 5, dim1.ascent()) + 2;
|
|
|
|
dim.des = max(dim0.descent() - 5, dim1.descent()) + 2;
|
|
|
|
dim.wid = dim0.width() + dim1.width() + 10;
|
2004-01-30 11:41:12 +00:00
|
|
|
metricsMarkers(dim);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
|
|
|
int const w = dim0.width();
|
2002-02-16 15:59:55 +00:00
|
|
|
// the "exponent"
|
2007-09-24 13:52:04 +00:00
|
|
|
cell(0).draw(pi, x, y - 5 - dim0.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);
|
2007-09-23 22:39:49 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
int const a = dim.ascent();
|
|
|
|
int const d = dim.descent();
|
2007-05-19 10:52:47 +00:00
|
|
|
int xp[4];
|
|
|
|
int yp[4];
|
2007-09-23 22:39:49 +00:00
|
|
|
pi.pain.line(x + dim.width(), y - a + 1,
|
2010-04-28 13:19:09 +00:00
|
|
|
x + w + 4, y - a + 1, pi.base.font.color());
|
2007-05-19 10:52:47 +00:00
|
|
|
xp[0] = x + w + 4; yp[0] = y - a + 1;
|
|
|
|
xp[1] = x + w; yp[1] = y + d;
|
|
|
|
xp[2] = x + w - 2; yp[2] = y + (d - a)/2 + 2;
|
|
|
|
xp[3] = x + w - 5; yp[3] = y + (d - a)/2 + 4;
|
2010-04-28 13:19:09 +00:00
|
|
|
pi.pain.lines(xp, yp, 4, pi.base.font.color());
|
2002-07-30 13:56:02 +00:00
|
|
|
drawMarkers(pi, x, y);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathRoot::write(WriteStream & os) const
|
2000-03-07 01:14:37 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
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
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathRoot::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
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor::idx_type const target = up ? 0 : 1;
|
2004-01-15 17:34:44 +00:00
|
|
|
if (cur.idx() == target)
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
cur.idx() = target;
|
|
|
|
cur.pos() = up ? cur.lastpos() : 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-11-07 13:15:59 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathRoot::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-07 03:28:53 +00:00
|
|
|
void InsetMathRoot::mathematica(MathematicaStream & os) const
|
|
|
|
{
|
|
|
|
os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathRoot::octave(OctaveStream & os) const
|
2001-11-07 13:15:59 +00:00
|
|
|
{
|
2007-01-07 03:28:53 +00:00
|
|
|
os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 15:46:39 +00:00
|
|
|
void InsetMathRoot::mathmlize(MathStream & os) const
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2009-12-31 15:46:39 +00:00
|
|
|
os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
|
2001-11-07 13:15:59 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2010-03-31 20:31:04 +00:00
|
|
|
void InsetMathRoot::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
os << MTag("span", "class='root'")
|
|
|
|
<< MTag("sup") << cell(0) << ETag("sup")
|
|
|
|
<< from_ascii("√")
|
|
|
|
<< MTag("span", "class='rootof'") << cell(1) << ETag("span")
|
|
|
|
<< ETag("span");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathRoot::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
2011-12-06 22:17:13 +00:00
|
|
|
features.addCSSSnippet(
|
2010-03-31 20:31:04 +00:00
|
|
|
"span.rootof{border-top: thin solid black;}\n"
|
2011-12-06 22:17:13 +00:00
|
|
|
"span.root sup{font-size: 75%;}");
|
2010-03-31 21:24:16 +00:00
|
|
|
InsetMathNest::validate(features);
|
2010-03-31 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|