#include "InsetMathDecoration.h"
-#include "BufferView.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);
int const l1 = mi.base.bv->zoomedPixels(1);
- int const l2 = 2 * l1;
- int const l3 = 3 * l1;
+ 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');
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);
}