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.

-- 
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..96decb8fe5 100644
--- a/src/mathed/InsetMathChar.cpp
+++ b/src/mathed/InsetMathChar.cpp
@@ -113,7 +113,8 @@ 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_);
+		string const & font = mathedSymbolDim(mi.base, dim, subst_);
+		Changer dummy = mi.base.changeFontSet(font);
 		kerning_ = mathed_char_kerning(mi.base.font, *subst_->draw.rbegin());
 		return;
 	} else if (!slanted(char_) && f == "mathnormal") {
diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp
index 90d507cfbe..f561be1c0b 100644
--- a/src/mathed/InsetMathFrac.cpp
+++ b/src/mathed/InsetMathFrac.cpp
@@ -219,7 +219,8 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
 		Changer dummy2 = mi.base.changeScript();
 		if (latexkeys const * slash = slash_symbol()) {
 			Dimension dimslash;
-			mathedSymbolDim(mi.base, dimslash, slash);
+			string const & font = mathedSymbolDim(mi.base, dimslash, slash);
+			Changer dummy = mi.base.changeFontSet(font);
 			dim.wid += dimslash.wid - mathed_mu(mi.base.font, 3.0);
 			dim.asc = max(dim.asc, dimslash.asc);
 			dim.des = max(dim.des, dimslash.des);
@@ -307,7 +308,8 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
 			int mkern = mathed_mu(pi.base.font, 2.0);
 			mathedSymbolDraw(pi, xx + 1 + dim0.wid - mkern, y, slash);
 			Dimension dimslash;
-			mathedSymbolDim(pi.base, dimslash, slash);
+			string const & font = mathedSymbolDim(pi.base, dimslash, slash);
+			Changer dummy = pi.base.changeFontSet(font);
 			xx += dimslash.wid - mathed_mu(pi.base.font, 3.0);
 		}
 		cell(1).draw(pi, xx + 1 + dim0.wid, y);
diff --git a/src/mathed/InsetMathSymbol.cpp b/src/mathed/InsetMathSymbol.cpp
index 276fab9ddc..54d3efcf6a 100644
--- a/src/mathed/InsetMathSymbol.cpp
+++ b/src/mathed/InsetMathSymbol.cpp
@@ -68,11 +68,12 @@ Limits InsetMathSymbol::defaultLimits() const
 
 void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-	mathedSymbolDim(mi.base, dim, sym_);
+	string const & font = mathedSymbolDim(mi.base, dim, sym_);
 	if (sym_->draw != sym_->name) {
 		// set dim
 		// FIXME: this should depend on BufferView
 		// set kerning_
+		Changer dummy = mi.base.changeFontSet(font);
 		kerning_ = mathed_char_kerning(mi.base.font,
 		                               mathedSymbol(mi.base, sym_).back());
 
diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp
index 12f8a842f6..cd5a9414aa 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)
+string mathedSymbolDim(MetricsBase & mb, Dimension & dim, latexkeys const * sym)
 {
-	LASSERT((bool)sym, return);
+	LASSERT((bool)sym, return "cmm");
 	//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 font;
 }
 
 
diff --git a/src/mathed/MathSupport.h b/src/mathed/MathSupport.h
index fa7b2fe0ea..877c191efb 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);
+std::string 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