2001-02-26 12:53:35 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_fracinset.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/Painter.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2002-03-19 16:55:58 +00:00
|
|
|
#include "textpainter.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::max;
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathFracInset::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return 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-05-30 07:09:54 +00:00
|
|
|
void MathFracInset::metrics(MathMetricsInfo & mi) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
MathFracChanger dummy(mi.base);
|
|
|
|
xcell(0).metrics(mi);
|
|
|
|
xcell(1).metrics(mi);
|
2002-03-21 17:42:56 +00:00
|
|
|
width_ = max(xcell(0).width(), xcell(1).width()) + 2;
|
2002-01-03 13:02:43 +00:00
|
|
|
ascent_ = xcell(0).height() + 2 + 5;
|
2002-03-21 17:42:56 +00:00
|
|
|
descent_ = xcell(1).height() + 2 - 5;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathFracInset::draw(MathPainterInfo & pi, int x, int y) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
int m = x + width() / 2;
|
2002-05-30 07:09:54 +00:00
|
|
|
MathFracChanger dummy(pi.base);
|
|
|
|
xcell(0).draw(pi, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
|
|
|
|
xcell(1).draw(pi, m - xcell(1).width() / 2, y + xcell(1).ascent() + 2 - 5);
|
2001-08-17 17:50:00 +00:00
|
|
|
if (!atop_)
|
2002-05-30 07:09:54 +00:00
|
|
|
pi.pain.line(x, y - 5, x + width(), y - 5, LColor::math);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 06:57:13 +00:00
|
|
|
void MathFracInset::metricsT(TextMetricsInfo const & mi) const
|
2002-03-19 16:55:58 +00:00
|
|
|
{
|
2002-03-21 06:57:13 +00:00
|
|
|
xcell(0).metricsT(mi);
|
|
|
|
xcell(1).metricsT(mi);
|
2002-03-19 16:55:58 +00:00
|
|
|
width_ = max(xcell(0).width(), xcell(1).width());
|
|
|
|
ascent_ = xcell(0).height() + 1;
|
|
|
|
descent_ = xcell(1).height();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int m = x + width() / 2;
|
2002-03-21 06:57:13 +00:00
|
|
|
xcell(0).drawT(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 1);
|
|
|
|
xcell(1).drawT(pain, m - xcell(1).width() / 2, y + xcell(1).ascent());
|
2002-03-19 16:55:58 +00:00
|
|
|
if (!atop_)
|
|
|
|
pain.horizontalLine(x, y, width());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) << '}';
|
|
|
|
else
|
|
|
|
os << "\\frac{" << cell(0) << "}{" << cell(1) << '}';
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathFracInset::normalize(NormalStream & os) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2002-03-21 17:42:56 +00:00
|
|
|
if (atop_)
|
2001-08-17 17:50:00 +00:00
|
|
|
os << "[atop ";
|
|
|
|
else
|
|
|
|
os << "[frac ";
|
2001-11-09 08:35:57 +00:00
|
|
|
os << cell(0) << ' ' << cell(1) << ']';
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathFracInset::maplize(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-07-01 11:17:14 +00:00
|
|
|
void MathFracInset::mathematicize(MathematicaStream & os) const
|
|
|
|
{
|
|
|
|
os << '(' << cell(0) << ")/(" << cell(1) << ')';
|
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
2002-04-25 15:37:10 +00:00
|
|
|
void MathFracInset::octavize(OctaveStream & os) const
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|