2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_fracinset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
#include "math_fracinset.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"
|
2002-03-19 16:55:58 +00:00
|
|
|
|
#include "textpainter.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "LColor.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
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-08-17 17:50:00 +00:00
|
|
|
|
MathFracInset::MathFracInset(bool atop)
|
|
|
|
|
: atop_(atop)
|
2001-07-09 10:19:50 +00:00
|
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> MathFracInset::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathFracInset(*this));
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-13 18:33:48 +00:00
|
|
|
|
MathFracInset * MathFracInset::asFracInset()
|
|
|
|
|
{
|
|
|
|
|
return atop_ ? 0 : this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-08 16:08:11 +00:00
|
|
|
|
MathFracInset const * MathFracInset::asFracInset() const
|
|
|
|
|
{
|
|
|
|
|
return atop_ ? 0 : this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathFracInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FracChanger dummy(mi.base);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).metrics(mi);
|
|
|
|
|
cell(1).metrics(mi);
|
2004-04-07 16:54:15 +00:00
|
|
|
|
dim.wid = max(cell(0).width(), cell(1).width()) + 2;
|
|
|
|
|
dim.asc = cell(0).height() + 2 + 5;
|
|
|
|
|
dim.des = cell(1).height() + 2 - 5;
|
|
|
|
|
metricsMarkers(dim);
|
|
|
|
|
dim_ = dim;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathFracInset::draw(PainterInfo & pi, int x, int y) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2003-05-28 13:22:36 +00:00
|
|
|
|
int m = x + dim_.wid / 2;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FracChanger dummy(pi.base);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
|
|
|
|
|
cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5);
|
2001-08-17 17:50:00 +00:00
|
|
|
|
if (!atop_)
|
2003-05-28 13:22:36 +00:00
|
|
|
|
pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, LColor::math);
|
2004-04-07 16:54:15 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void MathFracInset::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);
|
|
|
|
|
cell(1).metricsT(mi, dim);
|
|
|
|
|
dim.wid = max(cell(0).width(), cell(1).width());
|
|
|
|
|
dim.asc = cell(0).height() + 1;
|
|
|
|
|
dim.des = cell(1).height();
|
2003-06-02 10:03:27 +00:00
|
|
|
|
//dim = dim_;
|
2002-03-19 16:55:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 06:57:13 +00:00
|
|
|
|
void MathFracInset::drawT(TextPainter & pain, int x, int y) const
|
2002-03-19 16:55:58 +00:00
|
|
|
|
{
|
2003-05-28 13:22:36 +00:00
|
|
|
|
int m = x + dim_.width() / 2;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
|
|
|
|
|
cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
|
2002-03-19 16:55:58 +00:00
|
|
|
|
if (!atop_)
|
2003-05-28 13:22:36 +00:00
|
|
|
|
pain.horizontalLine(x, y, dim_.width());
|
2002-03-19 16:55:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathFracInset::write(WriteStream & os) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2001-10-19 11:25:48 +00:00
|
|
|
|
if (atop_)
|
|
|
|
|
os << '{' << cell(0) << "\\atop " << cell(1) << '}';
|
2002-08-01 15:53:46 +00:00
|
|
|
|
else // it's \\frac
|
|
|
|
|
MathNestInset::write(os);
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
string MathFracInset::name() const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2002-08-01 15:53:46 +00:00
|
|
|
|
return atop_ ? "atop" : "frac";
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathFracInset::maple(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2001-11-13 16:27:06 +00:00
|
|
|
|
os << '(' << cell(0) << ")/(" << cell(1) << ')';
|
2001-11-07 17:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathFracInset::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
os << '(' << cell(0) << ")/(" << cell(1) << ')';
|
|
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathFracInset::octave(OctaveStream & os) const
|
2002-04-25 15:37:10 +00:00
|
|
|
|
{
|
|
|
|
|
os << '(' << cell(0) << ")/(" << cell(1) << ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
|
void MathFracInset::mathmlize(MathMLStream & os) const
|
|
|
|
|
{
|
2001-11-08 12:06:56 +00:00
|
|
|
|
os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|