]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathEnsureMath.cpp
nullptr
[lyx.git] / src / mathed / InsetMathEnsureMath.cpp
index 149bae7d2cb247fbc5fd8871066f3df866d13d11..7f82345efd8627299f8a6ccf2e36a74ac0437b97 100644 (file)
 
 #include "InsetMathEnsureMath.h"
 
-#include "MathExtern.h"
 #include "MathData.h"
 #include "MathStream.h"
+#include "MathSupport.h"
+
+#include "LaTeXFeatures.h"
+#include "MetricsInfo.h"
 
 #include <ostream>
 
@@ -23,7 +26,7 @@
 namespace lyx {
 
 InsetMathEnsureMath::InsetMathEnsureMath(Buffer * buf)
-       : InsetMathNest(buf, 1)
+       : InsetMathGrid(buf, 1, 1)
 {}
 
 
@@ -35,17 +38,15 @@ Inset * InsetMathEnsureMath::clone() const
 
 void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       FontSetChanger dummy(mi.base, "mathnormal");
+       Changer dummy = mi.base.changeEnsureMath();
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
 }
 
 
 void InsetMathEnsureMath::draw(PainterInfo & pi, int x, int y) const
 {
-       FontSetChanger dummy(pi.base, "mathnormal");
+       Changer dummy = pi.base.changeEnsureMath();
        cell(0).draw(pi, x, y);
-       drawMarkers(pi, x, y);
 }
 
 
@@ -61,16 +62,28 @@ void InsetMathEnsureMath::drawT(TextPainter & pain, int x, int y) const
 }
 
 
-void InsetMathEnsureMath::write(WriteStream & os) const
+void InsetMathEnsureMath::write(TeXMathStream & os) const
 {
        ModeSpecifier specifier(os, MATH_MODE);
        os << "\\ensuremath{" << cell(0) << "}";
 }
 
 
-docstring InsetMathEnsureMath::mathmlize(MathStream & os) const
+void InsetMathEnsureMath::mathmlize(MathMLStream & ms) const
+{
+       SetMode mathmode(ms, false);
+       ms << MTag("mstyle", "class='math'")
+          << cell(0)
+          << ETag("mstyle");
+}
+
+
+void InsetMathEnsureMath::htmlize(HtmlStream & os) const
 {
-       return lyx::mathmlize(cell(0), os);
+       SetHTMLMode mathmode(os, false);
+       os << MTag("span", "class='math'")
+          << cell(0)
+          << ETag("span");
 }
 
 
@@ -80,4 +93,17 @@ void InsetMathEnsureMath::infoize(odocstream & os) const
 }
 
 
+void InsetMathEnsureMath::validate(LaTeXFeatures & features) const
+{
+       // FIXME XHTML
+       // It'd be better to be able to get this from an InsetLayout, but at present
+       // InsetLayouts do not seem really to work for things that aren't InsetTexts.
+       if (features.runparams().math_flavor == OutputParams::MathAsMathML)
+               features.addCSSSnippet("mstyle.math { font-style: italic; }");
+       else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
+               features.addCSSSnippet("span.mathbox { font-style: italic; }");
+
+       InsetMathNest::validate(features);
+}
+
 } // namespace lyx