* Licence details can be found in the file COPYING.
*
* \author Alejandro Aguilar Sierra
- * \author André Pönitz
+ * \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "InsetMathDecoration.h"
-#include "MathArray.h"
+
+#include "MathData.h"
+#include "MathExtern.h"
#include "MathParser.h"
#include "MathSupport.h"
#include "MathStream.h"
+#include "MetricsInfo.h"
#include "LaTeXFeatures.h"
-#include "debug.h"
-#include "support/std_ostream.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 << std::endl;
+// lyxerr << " creating deco " << key->name << endl;
}
-std::auto_ptr<InsetBase> InsetMathDecoration::doClone() const
+Inset * InsetMathDecoration::clone() const
{
- return std::auto_ptr<InsetBase>(new InsetMathDecoration(*this));
+ return new InsetMathDecoration(*this);
}
}
-bool InsetMathDecoration::ams() const
-{
- return
- key_->name == "overleftrightarrow" ||
- key_->name == "underleftarrow" ||
- key_->name == "underrightarrow" ||
- key_->name == "underleftrightarrow";
-}
-
-
-bool InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
}
metricsMarkers(dim);
- if (dim_ == dim)
- return false;
- dim_ = dim;
- return true;
}
void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
{
cell(0).draw(pi, x + 1, y);
+ Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
if (wide())
- mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
+ mathed_draw_deco(pi, x + 1, y + dy_, dim0.wid, dh_, key_->name);
else
- mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
+ mathed_draw_deco(pi, x + 1 + (dim0.wid - dw_) / 2,
y + dy_, dw_, dh_, key_->name);
drawMarkers(pi, x, y);
setPosCache(pi, x, y);
void InsetMathDecoration::write(WriteStream & os) const
{
+ MathEnsurer ensurer(os);
if (os.fragile() && protect())
os << "\\protect";
os << '\\' << key_->name << '{' << cell(0) << '}';
void InsetMathDecoration::validate(LaTeXFeatures & features) const
{
- if (ams())
- features.require("amsmath");
+ if (!key_->requires.empty())
+ features.require(to_utf8(key_->requires));
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, "´");
+ t["bar"] = Attributes(true, "‾");
+ t["breve"] = Attributes(true, "˘");
+ t["check"] = Attributes(true, "ˇ");
+ t["ddddot"] = Attributes(true, "⃜");
+ t["dddot"] = Attributes(true, "⃛");
+ t["ddot"] = Attributes(true, "¨");
+ t["dot"] = Attributes(true, "˙");
+ t["grave"] = Attributes(true, "`");
+ t["hat"] = Attributes(true, "ˆ");
+ t["mathring"] = Attributes(true, "˚");
+ t["overbrace"] = Attributes(true, "⏞");
+ t["overleftarrow"] = Attributes(true, "⟵");
+ t["overleftrightarrow"] = Attributes(true, "⟷");
+ t["overrightarrow"] = Attributes(true, "⟶");
+ t["tilde"] = Attributes(true, "˜");
+ t["underbar"] = Attributes(false, "_");
+ t["underbrace"] = Attributes(false, "⏟");
+ t["underleftarrow"] = Attributes(false, "⟵");
+ t["underleftrightarrow"] = Attributes(false, "⟷");
+ t["underline"] = Attributes(false, "&;");
+ t["underrightarrow"] = Attributes(false, "⟶");
+ t["vec"] = Attributes(true, "→");
+ t["widehat"] = Attributes(true, "^");
+ t["widetilde"] = Attributes(true, "∼");
+ }
+
+ 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