2 * \file InsetMathBinom.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathBinom.h"
15 #include "MathSupport.h"
16 #include "MathStream.h"
21 InsetMathBinom::InsetMathBinom(bool choose)
26 Inset * InsetMathBinom::clone() const
28 return new InsetMathBinom(*this);
32 int InsetMathBinom::dw(int height) const
43 void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
45 ScriptChanger dummy(mi.base);
47 cell(0).metrics(mi, dim0);
48 cell(1).metrics(mi, dim1);
49 dim.asc = dim0.height() + 4 + 5;
50 dim.des = dim1.height() + 4 - 5;
51 dim.wid = std::max(dim0.width(), dim1.wid) + 2 * dw(dim.height()) + 4;
53 // Cache the inset dimension.
58 void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
60 Dimension const dim = dimension(*pi.base.bv);
61 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
62 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
63 int m = x + dim.width() / 2;
64 ScriptChanger dummy(pi.base);
65 cell(0).draw(pi, m - dim0.width() / 2, y - dim0.des - 3 - 5);
66 cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5);
67 mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("("));
68 mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(),
69 dw(dim.height()), dim.height(), from_ascii(")"));
70 drawMarkers2(pi, x, y);
74 bool InsetMathBinom::extraBraces() const
80 void InsetMathBinom::write(WriteStream & os) const
83 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
85 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
89 void InsetMathBinom::normalize(NormalStream & os) const
91 os << "[binom " << cell(0) << ' ' << cell(1) << ']';