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