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