#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"
}
-Limits InsetMathDecoration::defaultLimits(bool display) const
+Limits InsetMathDecoration::defaultLimits(bool /*display*/) const
{
- if (allowsLimitsChange() && display)
+ 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())
}
} // 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));