]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathDecoration.cpp
We only support gcc >= 4.9.
[lyx.git] / src / mathed / InsetMathDecoration.cpp
index 0349c69ee5f158a04997a38b5cb10cbccf272a3f..cc4ba162796b8adaf48782f7bc9ec5cb4986749a 100644 (file)
 
 #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"
@@ -64,6 +66,15 @@ MathClass InsetMathDecoration::mathClass() const
 }
 
 
+Limits InsetMathDecoration::defaultLimits(bool /*display*/) const
+{
+       if (allowsLimitsChange())
+               return LIMITS;
+       else
+               return NO_LIMITS;
+}
+
+
 bool InsetMathDecoration::protect() const
 {
        return
@@ -110,15 +121,19 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
 
        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;
        }
 }
 
@@ -129,15 +144,24 @@ 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);
 }
 
 
-void InsetMathDecoration::write(WriteStream & os) const
+void InsetMathDecoration::write(TeXMathStream & os) const
 {
        MathEnsurer ensurer(os);
        if (os.fragile() && protect())
@@ -214,7 +238,7 @@ namespace {
        }
 } // 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));