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