On Thu, Jul 23, 2020 at 11:12:44AM +0200, Jean-Marc Lasgouttes wrote:
> Le 23/07/2020 à 00:26, Enrico Forestieri a écrit :
> > On Wed, Jul 22, 2020 at 11:14:05PM +0200, Enrico Forestieri wrote:
> > > 
> > > So, the question is why in current master the metrics of the wrong
> > > font are used? I don't have an answer.
> > 
> > The culprit turns out to be be836909c52 and the attached patch fixes
> > this issue for me.
> 
> So, you mean that the code should use the font of the symbol and not the
> font of the environment? That makes perfect sense...
> 
> Congrats, Enrico.
> 
> Instead of returning the font of the symbol (which is a weird side effect),
> it would be possible to introduce mathedSymbolFont(). Or to move this
> mathedSymbolXX stuff to members of latexkeys.

Here is an alternative patch. Please check whether the change in
InsetMathSymbol.cpp is compatible with the corresponding change
at e8ee0100.

-- 
Enrico
diff --git a/src/frontends/qt/GuiFontMetrics.cpp 
b/src/frontends/qt/GuiFontMetrics.cpp
index acc804460d..a9b23e9178 100644
--- a/src/frontends/qt/GuiFontMetrics.cpp
+++ b/src/frontends/qt/GuiFontMetrics.cpp
@@ -244,10 +244,7 @@ int GuiFontMetrics::width(docstring const & s) const
                tl.beginLayout();
                QTextLine line = tl.createLine();
                tl.endLayout();
-               if (math_char)
-                       w = iround(line.naturalTextWidth());
-               else
-                       w = iround(line.horizontalAdvance());
+               w = iround(line.horizontalAdvance());
        }
        strwidth_cache_.insert(s, w, s.size() * sizeof(char_type));
        return w;
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..f2e545434b 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 kerning_
+       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);
 
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to