On Thu, Jan 19, 2017 at 03:28:25PM -0500, Richard Heck wrote:
> On 01/19/2017 02:35 PM, Enrico Forestieri wrote:
> >
> > In conclusion, your patch textwidth2.diff is the right thing to do
> > in master. For stable we have to make a decision. The alternatives are:
> >
> > 1) The patch I posted earlier (textwidth.diff), amended to account
> >    for single chars. This restores the previous behavior, where \not
> >    only works properly with mathrel operators.
> >
> > 2) The not1.diff patch. This is essentially equivalent to 1) but avoids
> >    the \kern in the definition of \not.
> >
> > 3) The not2.diff patch. This makes \ne, \neq, and \notin work again
> >    and fixes the usage of \not with other non-mathrel characters,
> >    while breaking it for \not=, \not\in and other mathrel operators.
> >
> > I would suggest to choose either 1) or 2), which simply restore the
> > previous behavior.
> 
> Either of those would be fine with me.

As I don't see what we gain from 2), I think 1) is the way to go. I attach
here the amended patch.

-- 
Enrico
diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp
index f17ac37..83b2a1f 100644
--- a/src/frontends/qt4/GuiFontMetrics.cpp
+++ b/src/frontends/qt4/GuiFontMetrics.cpp
@@ -178,16 +178,27 @@ int GuiFontMetrics::width(docstring const & s) const
 	int * pw = strwidth_cache_[s];
 	if (pw)
 		return *pw;
+#endif
 	// For some reason QMetrics::width returns a wrong value with Qt5
-	// int w = metrics_.width(toqstr(s));
+	// with some arabic text. OTOH, QTextLayout is broken for single
+	// characters with null width (like \not in mathed). Also, as a
+	// safety measure, always use QMetrics::width with our math fonts.
+	int w = 0;
+	if (s.length() == 1
+#if QT_VERSION >= 0x040800
+	    || font_.styleName() == "LyX"
 #endif
-	QTextLayout tl;
-	tl.setText(toqstr(s));
-	tl.setFont(font_);
-	tl.beginLayout();
-	QTextLine line = tl.createLine();
-	tl.endLayout();
-	int w = int(line.naturalTextWidth());
+	   )
+		w = metrics_.width(toqstr(s));
+	else {
+		QTextLayout tl;
+		tl.setText(toqstr(s));
+		tl.setFont(font_);
+		tl.beginLayout();
+		QTextLine line = tl.createLine();
+		tl.endLayout();
+		w = int(line.naturalTextWidth());
+	}
 #ifdef CACHE_METRICS_WIDTH
 	strwidth_cache_.insert(s, new int(w), s.size() * sizeof(char_type));
 #endif

Reply via email to