]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathTFrac.C
Fix bug 2789 (as discussed)
[lyx.git] / src / mathed / InsetMathTFrac.C
1 /**
2  * \file InsetMathDFrac.C
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 "InsetMathTFrac.h"
14
15 #include "MathData.h"
16 #include "MathMLStream.h"
17
18 #include "LaTeXFeatures.h"
19 #include "LColor.h"
20
21 #include "frontends/Painter.h"
22
23
24 using std::string;
25 using std::max;
26 using std::auto_ptr;
27
28
29 InsetMathTFrac::InsetMathTFrac()
30         : InsetMathFrac()
31 {}
32
33
34 auto_ptr<InsetBase> InsetMathTFrac::doClone() const
35 {
36         return auto_ptr<InsetBase>(new InsetMathTFrac(*this));
37 }
38
39
40 void InsetMathTFrac::metrics(MetricsInfo & mi, Dimension & dim) const
41 {
42         StyleChanger dummy(mi.base, LM_ST_SCRIPT);
43         cell(0).metrics(mi);
44         cell(1).metrics(mi);
45         dim_.wid = max(cell(0).width(), cell(1).width()) + 2;
46         dim_.asc = cell(0).height() + 2 + 5;
47         dim_.des = cell(1).height() + 2 - 5;
48         dim = dim_;
49 }
50
51
52 void InsetMathTFrac::draw(PainterInfo & pi, int x, int y) const
53 {
54         StyleChanger dummy(pi.base, LM_ST_SCRIPT);
55         int m = x + dim_.wid / 2;
56         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
57         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
58         pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, LColor::math);
59         setPosCache(pi, x, y);
60 }
61
62
63 string InsetMathTFrac::name() const
64 {
65         return "tfrac";
66 }
67
68
69 void InsetMathTFrac::mathmlize(MathMLStream & os) const
70 {
71         os << MTag("mtfrac") << cell(0) << cell(1) << ETag("mtfrac");
72 }
73
74
75 void InsetMathTFrac::validate(LaTeXFeatures & features) const
76 {
77         features.require("amsmath");
78         InsetMathNest::validate(features);
79 }