]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBinom.cpp
Fix RTL inset painting.
[lyx.git] / src / mathed / InsetMathBinom.cpp
1 /**
2  * \file InsetMathBinom.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathBinom.h"
14 #include "MathData.h"
15 #include "MathSupport.h"
16 #include "MathStream.h"
17
18
19 namespace lyx {
20
21 InsetMathBinom::InsetMathBinom(bool choose)
22         : choose_(choose)
23 {}
24
25
26 Inset * InsetMathBinom::clone() const
27 {
28         return new InsetMathBinom(*this);
29 }
30
31
32 int InsetMathBinom::dw() const
33 {
34         int w = dim_.height() / 5;
35         if (w > 15)
36                 w = 15;
37         if (w < 6)
38                 w = 6;
39         return w;
40 }
41
42
43 void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
44 {
45         ScriptChanger dummy(mi.base);
46         cell(0).metrics(mi);
47         cell(1).metrics(mi);
48         dim.asc = cell(0).height() + 4 + 5;
49         dim.des = cell(1).height() + 4 - 5;
50         dim.wid = std::max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
51         metricsMarkers2(dim);
52         dim_ = dim;
53 }
54
55
56 void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
57 {
58         int m = x + dim_.width() / 2;
59         ScriptChanger dummy(pi.base);
60         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
61         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 3 - 5);
62         mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), from_ascii("("));
63         mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
64                 dw(), dim_.height(), from_ascii(")"));
65         drawMarkers2(pi, x, y);
66 }
67
68
69 bool InsetMathBinom::extraBraces() const
70 {
71         return choose_;
72 }
73
74
75 void InsetMathBinom::write(WriteStream & os) const
76 {
77         if (choose_)
78                 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
79         else
80                 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
81 }
82
83
84 void InsetMathBinom::normalize(NormalStream & os) const
85 {
86         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
87 }
88
89
90 } // namespace lyx