]> git.lyx.org Git - features.git/blobdiff - src/mathed/InsetMathDecoration.cpp
Introduce a return value for mathmlize(). We will need this to be able
[features.git] / src / mathed / InsetMathDecoration.cpp
index 026b3da672d8b8b0dce1e42e853b0fc38eea48b4..825b212c9de8970c59640982ade338e02b241a50 100644 (file)
@@ -14,6 +14,7 @@
 #include "InsetMathDecoration.h"
 
 #include "MathData.h"
+#include "MathExtern.h"
 #include "MathParser.h"
 #include "MathSupport.h"
 #include "MathStream.h"
 #include "LaTeXFeatures.h"
 
 #include "support/debug.h"
+#include "support/lassert.h"
 
 #include <ostream>
 
+using namespace std;
 
 namespace lyx {
 
 
-InsetMathDecoration::InsetMathDecoration(latexkeys const * key)
-       : InsetMathNest(1), key_(key)
+InsetMathDecoration::InsetMathDecoration(Buffer * buf, latexkeys const * key)
+       : InsetMathNest(buf, 1), key_(key)
 {
 //     lyxerr << " creating deco " << key->name << endl;
 }
@@ -155,5 +158,67 @@ void InsetMathDecoration::validate(LaTeXFeatures & features) const
        InsetMathNest::validate(features);
 }
 
+namespace {
+       struct Attributes {
+               Attributes() {}
+               Attributes(bool o, string t)
+                       : over(o), tag(t) {}
+               bool over;
+               string tag;
+       };
+
+       typedef map<string, Attributes> Translator;
+
+       void buildTranslator(Translator & t) {
+               // the decorations we need to support are listed in lib/symbols
+               t["acute"] = Attributes(true, "&acute;");
+               t["bar"]   = Attributes(true, "&OverBar;");
+               t["breve"] = Attributes(true, "&breve;");
+               t["check"] = Attributes(true, "&caron;");
+               t["ddddot"] = Attributes(true, "&DotDot;");
+               t["dddot"] = Attributes(true, "&TripleDot;");
+               t["ddot"] = Attributes(true, "&Dot;");
+               t["dot"] = Attributes(true, "&dot;");
+               t["grave"] = Attributes(true, "&grave;");
+               t["hat"] = Attributes(true, "&circ;");
+               t["mathring"] = Attributes(true, "&ring;");
+               t["overbrace"] = Attributes(true, "&OverBrace;");
+               t["overleftarrow"] = Attributes(true, "&xlarr;");
+               t["overleftrightarrow"] = Attributes(true, "&xharr;");
+               t["overrightarrow"] = Attributes(true, "&xrarr;");
+               t["tilde"] = Attributes(true, "&tilde;");
+               t["underbar"] = Attributes(false, "&UnderBar;");
+               t["underbrace"] = Attributes(false, "&UnderBrace;");
+               t["underleftarrow"] = Attributes(false, "&xlarr;");
+               t["underleftrightarrow"] = Attributes(false, "&xharr;");
+               t["underline"] = Attributes(false, "&;");
+               t["underrightarrow"] = Attributes(false, "&xrarr;");
+               t["vec"] = Attributes(true, "&rarr;");
+               t["widehat"] = Attributes(true, "&Hat;");
+               t["widetilde"] = Attributes(true, "&Tilde;");
+       }
+
+       Translator const & translator() {
+               static Translator t;
+               if (t.empty())
+                       buildTranslator(t);
+               return t;
+       }
+}
+
+docstring InsetMathDecoration::mathmlize(MathStream & os) const
+{
+       Translator const & t = translator();
+       Translator::const_iterator cur = t.find(to_utf8(key_->name));
+       LASSERT(cur != t.end(), return docstring());
+       char const * const outag = cur->second.over ? "mover" : "munder";
+       os << MTag(outag) << MTag("mrow");
+       docstring const rv = lyx::mathmlize(cell(0), os);
+       os << ETag("mrow")
+                << from_ascii("<mo stretchy=\"true\">" + cur->second.tag + "</mo>")
+                << ETag(outag);
+       return rv;
+}
+
 
 } // namespace lyx