Get MathML output working for math decorations.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32636 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2009-12-25 23:23:42 +00:00
parent bae47150c6
commit 904129cba6
2 changed files with 64 additions and 0 deletions

View File

@ -22,9 +22,11 @@
#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

View 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;