]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathOverset.cpp
Cell in delimiter inset should not be tight
[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.changeScript();
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 }
44
45
46 void InsetMathOverset::draw(PainterInfo & pi, int x, int y) const
47 {
48         Changer dummy2 = pi.base.changeEnsureMath();
49         Dimension const dim = dimension(*pi.base.bv);
50         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
51         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
52         int m  = x + dim.wid / 2;
53         int yo = y - dim1.asc - dim0.des - 1;
54         cell(1).draw(pi, m - dim1.wid / 2, y);
55         Changer dummy = pi.base.changeScript();
56         cell(0).draw(pi, m - dim0.width() / 2, yo);
57 }
58
59
60 bool InsetMathOverset::idxFirst(Cursor & cur) const
61 {
62         cur.idx() = 1;
63         cur.pos() = 0;
64         return true;
65 }
66
67
68 bool InsetMathOverset::idxLast(Cursor & cur) const
69 {
70         cur.idx() = 1;
71         cur.pos() = cur.lastpos();
72         return true;
73 }
74
75
76 void InsetMathOverset::write(WriteStream & os) const
77 {
78         MathEnsurer ensurer(os);
79         if (os.fragile())
80                 os << "\\protect";
81         os << "\\overset{" << cell(0) << "}{" << cell(1) << '}';
82 }
83
84
85 void InsetMathOverset::normalize(NormalStream & os) const
86 {
87         os << "[overset " << cell(0) << ' ' << cell(1) << ']';
88 }
89
90
91 void InsetMathOverset::mathmlize(MathStream & ms) const
92 {
93         ms << "<mover accent='false'>" << cell(1) << cell(0) << "</mover>";
94 }
95
96
97 void InsetMathOverset::htmlize(HtmlStream & os) const
98 {
99         os << MTag("span", "class='overset'")
100                  << MTag("span", "class='top'") << cell(0) << ETag("span")
101                  << MTag("span") << cell(1) << ETag("span")
102                  << ETag("span");
103 }
104
105
106 void InsetMathOverset::validate(LaTeXFeatures & features) const
107 {
108         if (features.runparams().isLaTeX())
109                 features.require("amsmath");
110         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
111                 features.addCSSSnippet(
112                         "span.overset{display: inline-block; vertical-align: bottom; text-align:center;}\n"
113                         "span.overset span {display: block;}\n"
114                         "span.top{font-size: 66%;}");
115
116         InsetMathNest::validate(features);
117 }
118
119
120 } // namespace lyx