2001-12-18 03:16:46 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-08-13 15:26:41 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_binominset.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-08-13 15:26:41 +00:00
|
|
|
#include "support/LOstream.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-08-13 15:26:41 +00:00
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::max;
|
|
|
|
|
|
|
|
|
2002-07-04 11:00:51 +00:00
|
|
|
MathBinomInset::MathBinomInset(bool choose)
|
|
|
|
: choose_(choose)
|
2001-08-13 15:26:41 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * MathBinomInset::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2001-08-13 15:26:41 +00:00
|
|
|
return new MathBinomInset(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathBinomInset::dw() const
|
|
|
|
{
|
|
|
|
int w = height()/5;
|
|
|
|
if (w > 15)
|
|
|
|
w = 15;
|
|
|
|
if (w < 6)
|
|
|
|
w = 6;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathBinomInset::metrics(MathMetricsInfo & mi) const
|
2001-08-13 15:26:41 +00:00
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
MathScriptChanger(mi.base);
|
2001-10-22 15:37:49 +00:00
|
|
|
xcell(0).metrics(mi);
|
|
|
|
xcell(1).metrics(mi);
|
2001-08-13 15:26:41 +00:00
|
|
|
ascent_ = xcell(0).height() + 4 + 5;
|
2002-03-21 17:42:56 +00:00
|
|
|
descent_ = xcell(1).height() + 4 - 5;
|
|
|
|
width_ = max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4;
|
2001-08-13 15:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathBinomInset::draw(MathPainterInfo & pi, int x, int y) const
|
2001-08-13 15:26:41 +00:00
|
|
|
{
|
|
|
|
int m = x + width() / 2;
|
2002-05-30 07:09:54 +00:00
|
|
|
MathScriptChanger(pi.base);
|
|
|
|
xcell(0).draw(pi, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
|
|
|
|
xcell(1).draw(pi, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
|
|
|
|
mathed_draw_deco(pi, x, y - ascent_, dw(), height(), "(");
|
|
|
|
mathed_draw_deco(pi, x + width() - dw(), y - ascent_, dw(), height(), ")");
|
2001-08-13 15:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathBinomInset::write(WriteStream & os) const
|
2001-08-13 15:26:41 +00:00
|
|
|
{
|
2002-07-04 11:00:51 +00:00
|
|
|
if (choose_)
|
|
|
|
os << '{' << cell(0) << " \\choose " << cell(1) << '}';
|
|
|
|
else
|
|
|
|
os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
|
2001-08-13 15:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathBinomInset::normalize(NormalStream & os) const
|
2001-08-13 15:26:41 +00:00
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
os << "[binom " << cell(0) << ' ' << cell(1) << ']';
|
2001-08-13 15:26:41 +00:00
|
|
|
}
|