]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathFont.cpp
Use SetMode() to manage text and math mode.
[lyx.git] / src / mathed / InsetMathFont.cpp
index bfeeeff3977120bc30636c6f8b59481b614047aa..5909c14c9bd630e8d153b8814fcc3ec8b4f1198c 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 #include <config.h>
 
 #include "InsetMathFont.h"
+
+#include "LaTeXFeatures.h"
 #include "MathData.h"
 #include "MathStream.h"
 #include "MathParser.h"
-#include "LaTeXFeatures.h"
-#include "support/std_ostream.h"
+#include "MetricsInfo.h"
 
+#include <ostream>
 
-namespace lyx {
-
-using std::auto_ptr;
 
+namespace lyx {
 
-InsetMathFont::InsetMathFont(latexkeys const * key)
-       : InsetMathNest(1), key_(key)
+InsetMathFont::InsetMathFont(Buffer * buf, latexkeys const * key)
+       : InsetMathNest(buf, 1), key_(key)
 {}
 
 
-auto_ptr<Inset> InsetMathFont::doClone() const
+Inset * InsetMathFont::clone() const
 {
-       return auto_ptr<Inset>(new InsetMathFont(*this));
+       return new InsetMathFont(*this);
 }
 
 
@@ -44,15 +44,19 @@ InsetMath::mode_type InsetMathFont::currentMode() const
 }
 
 
-bool InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
+bool InsetMathFont::lockedMode() const
+{
+       if (key_->extra == "forcetext")
+               return true;
+       return false;
+}
+
+
+void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        FontSetChanger dummy(mi.base, key_->name);
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       if (dim_ == dim)
-               return false;
-       dim_ = dim;
-       return true;
 }
 
 
@@ -67,7 +71,9 @@ void InsetMathFont::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
 {
-       cell(0).metricsT(mi, dim_);
+       // FIXME: BROKEN!
+       Dimension dim;
+       cell(0).metricsT(mi, dim);
 }
 
 
@@ -90,10 +96,56 @@ void InsetMathFont::validate(LaTeXFeatures & features) const
        // Fraktur used:
        if (key_->name == "mathfrak" || key_->name == "mathbb")
                features.require("amssymb");
-       if (key_->name == "text")
-               features.require("amsmath");
+       if (key_->name == "text" || key_->name == "textnormal"
+           || (key_->name.length() == 6 && key_->name.substr(0, 4) == "text"))
+               features.require("amstext");
        if (key_->name == "textipa")
                features.require("tipa");
+       if (key_->name == "ce" || key_->name == "cf")
+               features.require("mhchem");
+}
+
+
+// The fonts we want to support are listed in lib/symbols
+void InsetMathFont::mathmlize(MathStream & os) const
+{
+       // FIXME These are not quite right, because they do not nest
+       // correctly. A proper fix would presumably involve tracking
+       // the fonts already in effect.
+       std::string variant;
+       docstring const & tag = key_->name;
+       if (tag == "mathnormal" || tag == "mathrm"
+           || tag == "text" || tag == "textnormal"
+           || tag == "textrm" || tag == "textup"
+           || tag == "textmd")
+               variant = "normal";
+       else if (tag == "frak" || tag == "mathfrak")
+               variant = "fraktur";
+       else if (tag == "mathbb" || tag == "mathbf"
+                || tag == "textbf")
+               variant = "bold";
+       else if (tag == "mathcal")
+               variant == "script";
+       else if (tag == "mathit" || tag == "textsl"
+                || tag == "emph")
+               variant = "italic";
+       else if (tag == "mathsf" || tag == "textit"
+                || tag == "textsf")
+               variant = "sans-serif";
+       else if (tag == "mathtt" || tag == "texttt")
+               variant = "monospace";
+       // no support at present for textipa, textsc, noun
+       
+       // FIXME We need some kind of "mode tracker", so we can
+       // just output verbatim text in some cases.
+       docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4);
+       bool const textmode = (beg == "text");
+       if (!variant.empty()) {
+               os << "<mstyle mathvariant='" << from_utf8(variant) << "'>";
+               SetMode sm(os, textmode);
+               os << cell(0);
+               os << "</mstyle>";
+       }
 }