]> git.lyx.org Git - features.git/commitdiff
Get MathML output working for math decorations.
authorRichard Heck <rgheck@comcast.net>
Fri, 25 Dec 2009 23:23:42 +0000 (23:23 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 25 Dec 2009 23:23:42 +0000 (23:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32636 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/InsetMathDecoration.cpp
src/mathed/InsetMathDecoration.h

index 0ece491a7d8b94e4a2d44e55e0ca6d7f9385551f..629a440abf32cafbab88c5fb5bc9d8b4aa74d4f3 100644 (file)
 #include "LaTeXFeatures.h"
 
 #include "support/debug.h"
+#include "support/lassert.h"
 
 #include <ostream>
 
+using namespace std;
 
 namespace lyx {
 
@@ -155,5 +157,65 @@ 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;
+       }
+}
+
+void InsetMathDecoration::mathmlize(MathStream & os) const
+{
+       Translator const & t = translator();
+       Translator::const_iterator cur = t.find(to_utf8(key_->name));
+       LASSERT(cur != t.end(), return);
+       char const * const outag = cur->second.over ? "mover" : "munder";
+       os << MTag(outag)
+                << MTag("mrow") << cell(0) << ETag("mrow")
+                << from_ascii("<mo stretchy=\"true\">" + cur->second.tag + "</mo>")
+                << ETag(outag);
+}
+
 
 } // namespace lyx
index a8106d4889ff4aea770fc82e744be9077f8e00b6..22c9f9bed35379aa4671860ae7cc195e90fe8cfe 100644 (file)
@@ -41,6 +41,8 @@ public:
        void validate(LaTeXFeatures & features) const;
        ///
        InsetCode lyxCode() const { return MATH_DECORATION_CODE; }
+       ///
+       void mathmlize(MathStream &) const;
 
 private:
        virtual Inset * clone() const;