]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathDecoration.cpp
We only support gcc >= 4.9.
[lyx.git] / src / mathed / InsetMathDecoration.cpp
index adf5656984685d47d03ed5b49e08ab80e87fb91a..cc4ba162796b8adaf48782f7bc9ec5cb4986749a 100644 (file)
 
 #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"
@@ -65,9 +66,9 @@ MathClass InsetMathDecoration::mathClass() const
 }
 
 
-Limits InsetMathDecoration::defaultLimits(bool display) const
+Limits InsetMathDecoration::defaultLimits(bool /*display*/) const
 {
-       if (allowsLimitsChange() && display)
+       if (allowsLimitsChange())
                return LIMITS;
        else
                return NO_LIMITS;
@@ -121,8 +122,8 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
        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');
@@ -143,11 +144,20 @@ void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
 
        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);
 }