]> git.lyx.org Git - features.git/blob - src/mathed/InsetMathUnderset.cpp
Change cell numbers so that 0 is the main cell
[features.git] / src / mathed / InsetMathUnderset.cpp
1 /**
2  * \file InsetMathUnderset.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 "InsetMathUnderset.h"
14
15 #include "MathData.h"
16 #include "MathStream.h"
17
18 #include "Cursor.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
21
22
23 using namespace std;
24
25 namespace lyx {
26
27 Inset * InsetMathUnderset::clone() const
28 {
29         return new InsetMathUnderset(*this);
30 }
31
32
33 void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
34 {
35         Changer dummy2 = mi.base.changeEnsureMath();
36         Dimension dim0;
37         cell(0).metrics(mi, dim0);
38         Changer dummy = mi.base.changeFrac();
39         Dimension dim1;
40         cell(1).metrics(mi, dim1);
41         dim.wid = max(dim1.width(), dim0.width()) + 4;
42         dim.asc = dim0.ascent();
43         dim.des = dim0.descent() + dim1.height() + 4;
44 }
45
46
47 void InsetMathUnderset::draw(PainterInfo & pi, int x, int y) const
48 {
49         Changer dummy2 = pi.base.changeEnsureMath();
50         Dimension const dim = dimension(*pi.base.bv);
51         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
52         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
53         int m  = x + dim.wid / 2;
54         int yo = y + dim0.descent() + dim1.ascent() + 1;
55         cell(0).draw(pi, m - dim0.width() / 2, y);
56         Changer dummy = pi.base.changeFrac();
57         cell(1).draw(pi, m - dim1.width() / 2, yo);
58 }
59
60
61 void InsetMathUnderset::write(WriteStream & os) const
62 {
63         MathEnsurer ensurer(os);
64         if (os.fragile())
65                 os << "\\protect";
66         os << "\\underset{" << cell(1) << "}{" << cell(0) << '}';
67 }
68
69
70 void InsetMathUnderset::normalize(NormalStream & os) const
71 {
72         os << "[underset " << cell(1) << ' ' << cell(0) << ']';
73 }
74
75
76 void InsetMathUnderset::mathmlize(MathStream & ms) const
77 {
78         ms << "<munder accent='false'>" << cell(0) << cell(1) << "</munder>";
79 }
80
81
82 void InsetMathUnderset::htmlize(HtmlStream & os) const
83 {
84         os << MTag("span", "class='underset'")
85                  << MTag("span") << cell(1) << ETag("span")
86                  << MTag("span", "class='bottom'") << cell(0) << ETag("span")
87                  << ETag("span");
88 }
89
90
91 void InsetMathUnderset::validate(LaTeXFeatures & features) const
92 {
93         if (features.runparams().isLaTeX())
94                 features.require("amsmath");
95         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
96                 features.addCSSSnippet(
97                         "span.underset{display: inline-block; vertical-align: top; text-align:center;}\n"
98                         "span.underset span {display: block;}\n"
99                         "span.bottom{font-size: 66%;}");
100
101         InsetMathNest::validate(features);
102 }
103
104
105 } // namespace lyx