#include "InsetMathDecoration.h"
+#include "InsetMathChar.h"
#include "MathData.h"
#include "MathParser.h"
#include "MathSupport.h"
#include "MathStream.h"
#include "MetricsInfo.h"
+#include "BufferView.h"
#include "LaTeXFeatures.h"
#include "support/debug.h"
InsetMathDecoration::InsetMathDecoration(Buffer * buf, latexkeys const * key)
- : InsetMathNest(buf, 1), key_(key), dh_(0), dy_(0), dw_(0)
+ : InsetMathNest(buf, 1), key_(key)
{
// lyxerr << " creating deco " << key->name << endl;
}
}
-bool InsetMathDecoration::isScriptable() const
+Limits InsetMathDecoration::defaultLimits(bool /*display*/) const
{
- return mathClass() == MC_OP;
+ if (allowsLimitsChange())
+ return LIMITS;
+ else
+ return NO_LIMITS;
}
cell(0).metrics(mi, dim);
- dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
- dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
+ int const l1 = mi.base.bv->zoomedPixels(1);
+ int const l2 = mathed_char_width(mi.base.font, 'x') - l1;
+ int const l3 = l2;
+
+ dh_ = l2; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
+ dw_ = l3; //mathed_char_width(LM_TC_VAR, mi, 'x');
if (upper()) {
- dy_ = -dim.asc - dh_;
- dim.asc += dh_ + 1;
+ dy_ = -dim.asc - dh_ - l1;
+ dim.asc += dh_ + l1;
} else {
- dy_ = dim.des + 1;
- dim.des += dh_ + 2;
+ dy_ = dim.des + l1;
+ dim.des += dh_ + l2;
}
}
cell(0).draw(pi, x, y);
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
- if (wide())
- mathed_draw_deco(pi, x + 1, y + dy_, dim0.wid, dh_, key_->name);
- else
- mathed_draw_deco(pi, x + 1 + (dim0.wid - dw_) / 2,
- y + dy_, dw_, dh_, key_->name);
+ if (wide()) {
+ mathed_draw_deco(pi, x, y + dy_, dim0.wid, dh_, key_->name);
+ return;
+ }
+ // Lacking the necessary font parameters, in order to properly align
+ // the decoration we have to resort to heuristics for choosing a
+ // suitable value for shift
+ char_type c = (cell(0).empty() || !cell(0)[0]->asCharInset())
+ ? 0 : cell(0)[0]->asCharInset()->getChar();
+ double slope = (c == 0) ? 0.0 : mathed_char_slope(pi.base, c);
+ int kerning = (c == 0) ? 0 : mathed_char_kerning(pi.base.font, c);
+ int shift = (kerning == 0) ? int(dim0.asc * slope) : kerning;
+ mathed_draw_deco(pi, x + (dim0.wid - dw_) / 2 + shift,
+ y + dy_, dw_, dh_, key_->name);
}
-void InsetMathDecoration::write(WriteStream & os) const
+void InsetMathDecoration::write(TeXMathStream & os) const
{
MathEnsurer ensurer(os);
if (os.fragile() && protect())
os << '\\' << key_->name << '{';
ModeSpecifier specifier(os, currentMode());
os << cell(0) << '}';
+ writeLimits(os);
}
namespace {
struct Attributes {
Attributes() : over(false) {}
- Attributes(bool o, string const & t)
- : over(o), tag(t) {}
+ Attributes(bool o, string const & t, string const & entity)
+ : over(o), tag(t), entity(entity) {}
bool over;
string tag;
+ string entity;
};
typedef map<string, Attributes> TranslationMap;
void buildTranslationMap(TranslationMap & 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["overline"] = 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["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["overline"] = 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, "⟷", "⟷");
// this is the macron, again, but it works
- t["underline"] = Attributes(false, "¯");
- t["underrightarrow"] = Attributes(false, "⟶");
- t["undertilde"] = Attributes(false, "∼");
- t["utilde"] = Attributes(false, "∼");
- t["vec"] = Attributes(true, "→");
- t["widehat"] = Attributes(true, "^");
- t["widetilde"] = Attributes(true, "∼");
+ t["underline"] = Attributes(false, "¯", "¯");
+ t["underrightarrow"] = Attributes(false, "⟶", "⟶");
+ t["undertilde"] = Attributes(false, "∼", "∼");
+ t["utilde"] = Attributes(false, "∼", "∼");
+ t["vec"] = Attributes(true, "→", "→");
+ t["widehat"] = Attributes(true, "^", "^");
+ t["widetilde"] = Attributes(true, "∼", "∼");
}
TranslationMap const & translationMap() {
}
} // namespace
-void InsetMathDecoration::mathmlize(MathStream & ms) const
+void InsetMathDecoration::mathmlize(MathMLStream & ms) const
{
TranslationMap const & t = translationMap();
TranslationMap::const_iterator cur = t.find(to_utf8(key_->name));
LASSERT(cur != t.end(), return);
char const * const outag = cur->second.over ? "mover" : "munder";
+ std::string decoration = ms.xmlMode() ? cur->second.entity : cur->second.tag;
ms << MTag(outag)
<< MTag("mrow") << cell(0) << ETag("mrow")
<< "<" << from_ascii(ms.namespacedTag("mo")) << " stretchy=\"true\">"
- << from_ascii(cur->second.tag)
+ << from_ascii(decoration)
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< ETag(outag);
}