From 0b3e69167cb0eab323e4fe430c5d75fff9c45f3d Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Fri, 24 Jul 2020 12:32:24 +0200 Subject: [PATCH] Fix placement of limits with integral signs 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 | 13 +++++++++++-- src/mathed/InsetMathChar.cpp | 4 +--- src/mathed/InsetMathSymbol.cpp | 11 ++++------- src/mathed/MathSupport.cpp | 5 +++-- src/mathed/MathSupport.h | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/frontends/qt/GuiFontMetrics.cpp b/src/frontends/qt/GuiFontMetrics.cpp index acc804460d..efd8463453 100644 --- a/src/frontends/qt/GuiFontMetrics.cpp +++ b/src/frontends/qt/GuiFontMetrics.cpp @@ -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 ? diff --git a/src/mathed/InsetMathChar.cpp b/src/mathed/InsetMathChar.cpp index 36bdeaa2ba..d5ef8dc1f5 100644 --- a/src/mathed/InsetMathChar.cpp +++ b/src/mathed/InsetMathChar.cpp @@ -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_); diff --git a/src/mathed/InsetMathSymbol.cpp b/src/mathed/InsetMathSymbol.cpp index 276fab9ddc..471ee75460 100644 --- a/src/mathed/InsetMathSymbol.cpp +++ b/src/mathed/InsetMathSymbol.cpp @@ -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; diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp index 12f8a842f6..45ca429681 100644 --- a/src/mathed/MathSupport.cpp +++ b/src/mathed/MathSupport.cpp @@ -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()); } diff --git a/src/mathed/MathSupport.h b/src/mathed/MathSupport.h index fa7b2fe0ea..9fde420ce2 100644 --- a/src/mathed/MathSupport.h +++ b/src/mathed/MathSupport.h @@ -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); -- 2.39.5