]> git.lyx.org Git - lyx.git/commitdiff
Fix placement of limits with integral signs
authorEnrico Forestieri <forenr@lyx.org>
Fri, 24 Jul 2020 10:32:24 +0000 (12:32 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 24 Jul 2020 10:32:24 +0000 (12:32 +0200)
Since be836909c52 the positioning of super- and subscripts
for symbol fonts has been broken because the metrics of the
font of the environment (rather than those of the symbol itself)
were used.

src/frontends/qt/GuiFontMetrics.cpp
src/mathed/InsetMathChar.cpp
src/mathed/InsetMathSymbol.cpp
src/mathed/MathSupport.cpp
src/mathed/MathSupport.h

index acc804460d800c04f3acaf4f6d514845008345cf..efd84634539961b0750a0ca15bbb1cf526b47ef6 100644 (file)
@@ -226,8 +226,17 @@ int GuiFontMetrics::width(docstring const & s) const
      *   for text strings, it does not give a good result with some
      *   characters like the \int (gyph 4) of esint.
 
-        * Also, as a safety measure, always use QFontMetrics::width with
-        * our math fonts.
+        * The metrics of some of our math fonts (eg. esint) are such that
+        * QTextLine::horizontalAdvance leads, more or less, in the middle
+        * of a symbol. This is the horizontal position where a subscript
+        * should be drawn, so that the superscript has to be moved rightward.
+        * This is done when the kerning() method of the math insets returns
+        * a positive value. The problem with this choice is that navigating
+        * a formula becomes weird. For example, a selection extends only over
+        * about half of the symbol. In order to avoid this, with our math
+        * fonts we use QTextLine::naturalTextWidth, so that a superscript can
+        * be drawn right after the symbol, and move the subscript leftward by
+        * recording a negative value for the kerning.
        */
        int w = 0;
        // is the string a single character from a math font ?
index 36bdeaa2ba436f685c6f50af6d47e585d8dc7656..d5ef8dc1f5030bfcac2a6bb6f8f11161bdddf7aa 100644 (file)
@@ -113,9 +113,7 @@ void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
        if (isMathFont(f) && subst_) {
                // If the char has a substitute, draw the replacement symbol
                // instead, but only in math mode.
-               mathedSymbolDim(mi.base, dim, subst_);
-               kerning_ = mathed_char_kerning(mi.base.font, *subst_->draw.rbegin());
-               return;
+               kerning_ = mathedSymbolDim(mi.base, dim, subst_);
        } else if (!slanted(char_) && f == "mathnormal") {
                Changer dummy = mi.base.font.changeShape(UP_SHAPE);
                dim = theFontMetrics(mi.base.font).dimension(char_);
index 276fab9ddcc8918836bdc3ab9725f5105fae1132..471ee75460a5648b3d2849bbc6a02db8308325d8 100644 (file)
@@ -68,14 +68,11 @@ Limits InsetMathSymbol::defaultLimits() const
 
 void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       mathedSymbolDim(mi.base, dim, sym_);
+       // set dim
+       // FIXME: this should depend on BufferView
+       // set negative kerning_ so that a subscript is moved leftward
+       kerning_ = -mathedSymbolDim(mi.base, dim, sym_);
        if (sym_->draw != sym_->name) {
-               // set dim
-               // FIXME: this should depend on BufferView
-               // set kerning_
-               kerning_ = mathed_char_kerning(mi.base.font,
-                                              mathedSymbol(mi.base, sym_).back());
-
                // align character vertically
                // FIXME: this should depend on BufferView
                h_ = 0;
index 12f8a842f6aa7fcc70973c92db30523ae73ac421..45ca4296816d4161b34c2284fa595c1073df39b0 100644 (file)
@@ -680,9 +680,9 @@ docstring const &  mathedSymbol(MetricsBase & mb, latexkeys const * sym)
 }
 
 
-void mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
+int mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
 {
-       LASSERT((bool)sym, return);
+       LASSERT((bool)sym, return 0);
        //lyxerr << "metrics: symbol: '" << sym->name
        //      << "' in font: '" << sym->inset
        //      << "' drawn as: '" << sym->draw
@@ -694,6 +694,7 @@ void mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
        std::string const font = italic_upcase_greek ? "cmm" : sym->inset;
        Changer dummy = mb.changeFontSet(font);
        mathed_string_dim(mb.font, mathedSymbol(mb, sym), dim);
+       return mathed_char_kerning(mb.font, mathedSymbol(mb, sym).back());
 }
 
 
index fa7b2fe0ea1d93d905b4954e9e4f4bbd5a71aa2b..9fde420ce2bd9e02d39a9c63eca02173a34d947d 100644 (file)
@@ -57,7 +57,7 @@ int mathed_string_width(FontInfo const &, docstring const & s);
 
 docstring const & mathedSymbol(MetricsBase & mb, latexkeys const * sym);
 
-void mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym);
+int mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym);
 
 void mathedSymbolDraw(PainterInfo & pi, int x, int y, latexkeys const * sym);