2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathSqrt.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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathSqrt.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"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "TextPainter.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
#include "frontends/Painter.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathSqrt::InsetMathSqrt(Buffer * buf)
|
|
|
|
: InsetMathNest(buf, 1)
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathSqrt::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathSqrt(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
cell(0).metrics(mi, dim);
|
|
|
|
dim.asc += 4;
|
|
|
|
dim.des += 2;
|
|
|
|
dim.wid += 12;
|
|
|
|
metricsMarkers(dim);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).draw(pi, x + 10, 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[3];
|
|
|
|
int yp[3];
|
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 + 8, y - a + 1, pi.base.font.color());
|
2007-05-19 10:52:47 +00:00
|
|
|
xp[0] = x + 8; yp[0] = y - a + 1;
|
|
|
|
xp[1] = x + 5; yp[1] = y + d - 1;
|
|
|
|
xp[2] = x; yp[2] = y + (d - a)/2;
|
2010-04-28 13:19:09 +00:00
|
|
|
pi.pain.lines(xp, yp, 3, pi.base.font.color());
|
2002-07-30 13:56:02 +00:00
|
|
|
drawMarkers(pi, x, y);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-03-19 16:55:58 +00:00
|
|
|
{
|
2003-05-28 13:22:36 +00:00
|
|
|
cell(0).metricsT(mi, dim);
|
|
|
|
dim.asc += 1;
|
|
|
|
dim.wid += 2;
|
2002-03-19 16:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-03 11:00:18 +00:00
|
|
|
void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
/*
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).drawT(pain, x + 2, y);
|
2007-09-24 13:52:04 +00:00
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
|
|
|
pain.horizontalLine(x + 2, y - dim0.ascent(), dim0.width(), '_');
|
|
|
|
pain.verticalLine (x + 1, y - dim0.ascent() + 1, dim0.height());
|
|
|
|
pain.draw(x, y + dim0.descent(), '\\');
|
|
|
|
*/
|
2002-03-19 16:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSqrt::write(WriteStream & os) const
|
2001-02-28 11:56:36 +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) << '}';
|
2001-02-28 11:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSqrt::normalize(NormalStream & os) const
|
2001-04-25 15:43:57 +00:00
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
os << "[sqrt " << cell(0) << ']';
|
2001-04-25 15:43:57 +00:00
|
|
|
}
|
2001-11-07 10:21:51 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSqrt::maple(MapleStream & os) const
|
2001-11-07 10:21:51 +00:00
|
|
|
{
|
2001-11-07 17:30:26 +00:00
|
|
|
os << "sqrt(" << cell(0) << ')';
|
|
|
|
}
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSqrt::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
{
|
|
|
|
os << "Sqrt[" << cell(0) << ']';
|
|
|
|
}
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSqrt::octave(OctaveStream & os) const
|
2002-04-25 05:58:55 +00:00
|
|
|
{
|
|
|
|
os << "sqrt(" << cell(0) << ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 15:46:39 +00:00
|
|
|
void InsetMathSqrt::mathmlize(MathStream & os) const
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2009-12-31 15:46:39 +00:00
|
|
|
os << MTag("msqrt") << cell(0) << ETag("msqrt");
|
2001-11-07 10:21:51 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2010-03-31 20:31:04 +00:00
|
|
|
void InsetMathSqrt::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
os << MTag("span", "class='sqrt'")
|
|
|
|
<< from_ascii("√")
|
|
|
|
<< MTag("span", "class='sqrtof'") << cell(0) << ETag("span")
|
|
|
|
<< ETag("span");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathSqrt::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
|
|
|
features.addPreambleSnippet("<style type=\"text/css\">\n"
|
|
|
|
"span.sqrtof{border-top: thin solid black;}\n"
|
|
|
|
"</style>");
|
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
|