]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathUnderset.cpp
Merge branch 'master' into biblatex2
[lyx.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 dim1;
37         cell(1).metrics(mi, dim1);
38         Changer dummy = mi.base.changeFrac();
39         Dimension dim0;
40         cell(0).metrics(mi, dim0);
41         dim.wid = max(dim0.width(), dim1.width()) + 4;
42         dim.asc = dim1.ascent();
43         dim.des = dim1.descent() + dim0.height() + 4;
44         metricsMarkers(mi, dim);
45 }
46
47
48 void InsetMathUnderset::draw(PainterInfo & pi, int x, int y) const
49 {
50         Changer dummy2 = pi.base.changeEnsureMath();
51         Dimension const dim = dimension(*pi.base.bv);
52         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
53         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
54         int m  = x + dim.wid / 2;
55         int yo = y + dim1.descent() + dim0.ascent() + 1;
56         cell(1).draw(pi, m - dim1.width() / 2, y);
57         Changer dummy = pi.base.changeFrac();
58         cell(0).draw(pi, m - dim0.width() / 2, yo);
59         drawMarkers(pi, x, y);
60 }
61
62
63 bool InsetMathUnderset::idxFirst(Cursor & cur) const
64 {
65         cur.idx() = 1;
66         cur.pos() = 0;
67         return true;
68 }
69
70
71 bool InsetMathUnderset::idxLast(Cursor & cur) const
72 {
73         cur.idx() = 1;
74         cur.pos() = cur.lastpos();
75         return true;
76 }
77
78
79 bool InsetMathUnderset::idxUpDown(Cursor & cur, bool up) const
80 {
81         idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
82         if (cur.idx() == target)
83                 return false;
84         cur.idx() = target;
85         cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target());
86         return true;
87 }
88
89
90 void InsetMathUnderset::write(WriteStream & os) const
91 {
92         MathEnsurer ensurer(os);
93         if (os.fragile())
94                 os << "\\protect";
95         os << "\\underset{" << cell(0) << "}{" << cell(1) << '}';
96 }
97
98
99 void InsetMathUnderset::normalize(NormalStream & os) const
100 {
101         os << "[underset " << cell(0) << ' ' << cell(1) << ']';
102 }
103
104
105 void InsetMathUnderset::mathmlize(MathStream & ms) const
106 {
107         ms << "<munder accent='false'>" << cell(1) << cell(0) << "</munder>";
108 }
109
110
111 void InsetMathUnderset::htmlize(HtmlStream & os) const
112 {
113         os << MTag("span", "class='underset'")
114                  << MTag("span") << cell(0) << ETag("span")
115                  << MTag("span", "class='bottom'") << cell(1) << ETag("span")
116                  << ETag("span");
117 }
118
119
120 void InsetMathUnderset::validate(LaTeXFeatures & features) const
121 {
122         if (features.runparams().isLaTeX())
123                 features.require("amsmath");
124         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
125                 features.addCSSSnippet(
126                         "span.underset{display: inline-block; vertical-align: top; text-align:center;}\n"
127                         "span.underset span {display: block;}\n"
128                         "span.bottom{font-size: 66%;}");
129
130         InsetMathNest::validate(features);
131 }
132
133
134 } // namespace lyx