]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathStackrel.cpp
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / src / mathed / InsetMathStackrel.cpp
1 /**
2  * \file InsetMathStackrel.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 "InsetMathStackrel.h"
14
15 #include "LaTeXFeatures.h"
16 #include "MathData.h"
17 #include "MathStream.h"
18
19 using namespace std;
20
21 namespace lyx {
22
23 InsetMathStackrel::InsetMathStackrel(Buffer * buf) : InsetMathFracBase(buf)
24 {}
25
26
27 Inset * InsetMathStackrel::clone() const
28 {
29         return new InsetMathStackrel(*this);
30 }
31
32
33 void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
34 {
35         Dimension dim1;
36         cell(1).metrics(mi, dim1);
37         FracChanger dummy(mi.base);
38         Dimension dim0;
39         cell(0).metrics(mi, dim0);
40         dim.wid = max(dim0.width(), dim1.width()) + 4;
41         dim.asc = dim1.ascent() + dim0.height() + 4;
42         dim.des = dim1.descent();
43         metricsMarkers(dim);
44 }
45
46
47 void InsetMathStackrel::draw(PainterInfo & pi, int x, int y) const
48 {
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.width() / 2;
53         int yo = y - dim1.ascent() - dim0.descent() - 1;
54         cell(1).draw(pi, m - dim1.width() / 2, y);
55         FracChanger dummy(pi.base);
56         cell(0).draw(pi, m - dim0.width() / 2, yo);
57         drawMarkers(pi, x, y);
58 }
59
60
61 void InsetMathStackrel::write(WriteStream & os) const
62 {
63         MathEnsurer ensurer(os);
64         os << "\\stackrel{" << cell(0) << "}{" << cell(1) << '}';
65 }
66
67
68 void InsetMathStackrel::normalize(NormalStream & os) const
69 {
70         os << "[stackrel " << cell(0) << ' ' << cell(1) << ']';
71 }
72
73
74 void InsetMathStackrel::mathmlize(MathStream & ms) const
75 {
76         ms << "<mover accent='false'>" << cell(1) << cell(0) << "</mover>";
77 }
78
79
80 void InsetMathStackrel::htmlize(HtmlStream & os) const
81 {
82         // at the moment, this is exactly the same as overset
83         os << MTag("span", "class='overset'")
84                  << MTag("span", "class='top'") << cell(0) << ETag("span")
85                  << MTag("span") << cell(1) << ETag("span")
86                  << ETag("span");
87 }
88
89
90 void InsetMathStackrel::validate(LaTeXFeatures & features) const
91 {
92         // from overset
93         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
94                 features.addCSSSnippet(
95                         "span.overset{display: inline-block; vertical-align: bottom; text-align:center;}\n"
96                         "span.overset span {display: block;}\n"
97                         "span.top{font-size: 66%;}");
98
99         InsetMathNest::validate(features);
100 }
101
102 } // namespace lyx