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"
|
|
|
|
#include "mathed/support.h"
|
2001-07-13 09:54:32 +00:00
|
|
|
#include "Painter.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
|
|
|
|
2001-02-13 13:28:32 +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
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathFracInset::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return new MathFracInset(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
void MathFracInset::metrics(MathMetricsInfo const & st) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-10-19 11:25:48 +00:00
|
|
|
size_ = st;
|
|
|
|
size_.size = smallerStyleFrac(size_.size);
|
2001-07-26 06:56:43 +00:00
|
|
|
xcell(0).metrics(size_);
|
|
|
|
xcell(1).metrics(size_);
|
2001-06-27 15:33:55 +00:00
|
|
|
width_ = std::max(xcell(0).width(), xcell(1).width()) + 4;
|
2001-06-25 00:06:33 +00:00
|
|
|
ascent_ = xcell(0).height() + 4 + 5;
|
|
|
|
descent_ = xcell(1).height() + 4 - 5;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathFracInset::draw(Painter & pain, int x, int y) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
xo(x);
|
|
|
|
yo(y);
|
|
|
|
int m = x + width() / 2;
|
|
|
|
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
|
|
|
|
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
|
2001-08-17 17:50:00 +00:00
|
|
|
if (!atop_)
|
|
|
|
pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
void MathFracInset::write(MathWriteInfo & 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-07-26 06:56:43 +00:00
|
|
|
void MathFracInset::writeNormal(std::ostream & os) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-08-17 17:50:00 +00:00
|
|
|
if (atop_)
|
|
|
|
os << "[atop ";
|
|
|
|
else
|
|
|
|
os << "[frac ";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(0).writeNormal(os);
|
2001-06-25 00:06:33 +00:00
|
|
|
os << " ";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(1).writeNormal(os);
|
2001-06-25 00:06:33 +00:00
|
|
|
os << "] ";
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|