]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathEnsureMath.cpp
Sort the language nesting mess with polyglossia
[lyx.git] / src / mathed / InsetMathEnsureMath.cpp
1 /**
2  * \file InsetMathEnsureMath.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  * \author Enrico Forestieri
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetMathEnsureMath.h"
15
16 #include "MathData.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
22
23 #include <ostream>
24
25
26 namespace lyx {
27
28 InsetMathEnsureMath::InsetMathEnsureMath(Buffer * buf)
29         : InsetMathNest(buf, 1)
30 {}
31
32
33 Inset * InsetMathEnsureMath::clone() const
34 {
35         return new InsetMathEnsureMath(*this);
36 }
37
38
39 void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const
40 {
41         bool really_change_font = isTextFont(mi.base.fontname);
42         Changer dummy = mi.base.changeFontSet("mathnormal", really_change_font);
43         cell(0).metrics(mi, dim);
44         metricsMarkers(dim);
45 }
46
47
48 void InsetMathEnsureMath::draw(PainterInfo & pi, int x, int y) const
49 {
50         bool really_change_font = isTextFont(pi.base.fontname);
51         Changer dummy = pi.base.changeFontSet("mathnormal", really_change_font);
52         cell(0).draw(pi, x, y);
53         drawMarkers(pi, x, y);
54 }
55
56
57 void InsetMathEnsureMath::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
58 {
59         cell(0).metricsT(mi, dim);
60 }
61
62
63 void InsetMathEnsureMath::drawT(TextPainter & pain, int x, int y) const
64 {
65         cell(0).drawT(pain, x, y);
66 }
67
68
69 void InsetMathEnsureMath::write(WriteStream & os) const
70 {
71         ModeSpecifier specifier(os, MATH_MODE);
72         os << "\\ensuremath{" << cell(0) << "}";
73 }
74
75
76 void InsetMathEnsureMath::mathmlize(MathStream & os) const
77 {
78         SetMode mathmode(os, false);
79         os << MTag("mstyle", "class='math'")
80            << cell(0)
81            << ETag("mstyle");
82 }
83
84
85 void InsetMathEnsureMath::htmlize(HtmlStream & os) const
86 {
87         SetHTMLMode mathmode(os, false);
88         os << MTag("span", "class='math'")
89            << cell(0)
90            << ETag("span");
91 }
92
93
94 void InsetMathEnsureMath::infoize(odocstream & os) const
95 {
96         os << "EnsureMath";
97 }
98
99
100 void InsetMathEnsureMath::validate(LaTeXFeatures & features) const
101 {
102         // FIXME XHTML
103         // It'd be better to be able to get this from an InsetLayout, but at present
104         // InsetLayouts do not seem really to work for things that aren't InsetTexts.
105         if (features.runparams().math_flavor == OutputParams::MathAsMathML)
106                 features.addCSSSnippet("mstyle.math { font-style: italic; }");
107         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
108                 features.addCSSSnippet("span.mathbox { font-style: italic; }");
109
110         InsetMathNest::validate(features);
111 }
112
113 } // namespace lyx