]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathUnderset.cpp
g-brief loads babel internally. So don't load it ourselves.
[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 #include "support/lassert.h"
23
24 using namespace std;
25
26 namespace lyx {
27
28 Inset * InsetMathUnderset::clone() const
29 {
30         return new InsetMathUnderset(*this);
31 }
32
33
34 void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
35 {
36         Changer dummy2 = mi.base.changeEnsureMath();
37         Dimension dim0;
38         cell(0).metrics(mi, dim0);
39         Changer dummy = mi.base.changeScript();
40         Dimension dim1;
41         cell(1).metrics(mi, dim1);
42         dim.wid = max(dim1.width(), dim0.width()) + 4;
43         dim.asc = dim0.ascent();
44         dim.des = dim0.descent() + dim1.height() + 4;
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 & dim1 = cell(1).dimension(*pi.base.bv);
53         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
54         int m  = x + dim.wid / 2;
55         int yo = y + dim0.descent() + dim1.ascent() + 1;
56         cell(0).draw(pi, m - dim0.width() / 2, y);
57         Changer dummy = pi.base.changeScript();
58         cell(1).draw(pi, m - dim1.width() / 2, yo);
59 }
60
61
62 bool InsetMathUnderset::idxFirst(Cursor & cur) const
63 {
64         LASSERT(&cur.inset() == this, return false);
65         cur.idx() = 0;
66         cur.pos() = 0;
67         return true;
68 }
69
70
71 bool InsetMathUnderset::idxLast(Cursor & cur) const
72 {
73         LASSERT(&cur.inset() == this, return false);
74         cur.idx() = 0;
75         cur.pos() = cur.lastpos();
76         return true;
77 }
78
79
80 void InsetMathUnderset::write(TeXMathStream & os) const
81 {
82         MathEnsurer ensurer(os);
83         if (os.fragile())
84                 os << "\\protect";
85         os << "\\underset{" << cell(1) << "}{" << cell(0) << '}';
86 }
87
88
89 void InsetMathUnderset::normalize(NormalStream & os) const
90 {
91         os << "[underset " << cell(1) << ' ' << cell(0) << ']';
92 }
93
94
95 void InsetMathUnderset::mathmlize(MathMLStream & ms) const
96 {
97         ms << MTag("munder", "accent='false'")
98            << cell(0) << cell(1)
99            << ETag("munder");
100 }
101
102
103 void InsetMathUnderset::htmlize(HtmlStream & os) const
104 {
105         os << MTag("span", "class='underset'")
106            << MTag("span") << cell(1) << ETag("span")
107            << MTag("span", "class='bottom'") << cell(0) << ETag("span")
108            << ETag("span");
109 }
110
111
112 void InsetMathUnderset::validate(LaTeXFeatures & features) const
113 {
114         if (features.runparams().isLaTeX())
115                 features.require("amsmath");
116         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
117                 features.addCSSSnippet(
118                         "span.underset{display: inline-block; vertical-align: top; text-align:center;}\n"
119                         "span.underset span {display: block;}\n"
120                         "span.bottom{font-size: 66%;}");
121
122         InsetMathNest::validate(features);
123 }
124
125
126 } // namespace lyx