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