]> git.lyx.org Git - lyx.git/blob - src/mathed/math_binominset.C
several smallish changes/bugfixes/left overs from Porto
[lyx.git] / src / mathed / math_binominset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_binominset.h"
8 #include "math_support.h"
9 #include "support/LOstream.h"
10 #include "math_mathmlstream.h"
11
12
13 using std::max;
14
15
16 MathBinomInset::MathBinomInset()
17 {}
18
19
20 MathInset * MathBinomInset::clone() const
21 {
22         return new MathBinomInset(*this);
23 }
24
25
26 int MathBinomInset::dw() const
27 {
28         int w = height()/5;
29         if (w > 15)
30                 w = 15;
31         if (w < 6)
32                 w = 6;
33         return w;
34 }
35
36
37 void MathBinomInset::metrics(MathMetricsInfo & mi) const
38 {
39         MathScriptChanger(mi.base);
40         xcell(0).metrics(mi);
41         xcell(1).metrics(mi);
42         ascent_  = xcell(0).height() + 4 + 5;
43         descent_ = xcell(1).height() + 4 - 5;
44         width_   = max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4;
45 }
46
47
48 void MathBinomInset::draw(MathPainterInfo & pi, int x, int y) const
49 {
50         int m = x + width() / 2;
51         MathScriptChanger(pi.base);
52         xcell(0).draw(pi, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
53         xcell(1).draw(pi, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
54         mathed_draw_deco(pi, x, y - ascent_, dw(), height(), "(");
55         mathed_draw_deco(pi, x + width() - dw(), y - ascent_,   dw(), height(), ")");
56 }
57
58
59 void MathBinomInset::write(WriteStream & os) const
60 {
61         os << '{' << cell(0) << " \\choose " << cell(1) << '}';
62 }
63
64
65 void MathBinomInset::normalize(NormalStream & os) const
66 {
67         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
68 }