Le 17/01/2017 à 18:01, Enrico Forestieri a écrit :
Hello Enroci,

Hi JMcra :)

:)

I often do this typo, but usually I manage to correct it in time.

Yes, but I would propose to do that in addition. Nonetheless, my feeling
is that this issue is caused by the assumptions of Qt about a given font.
For example, it refuses to draw the glyph of a character whose codepoint
corresponds to a soft hyphen, irrespective of the actual font, and other
such amenities.

I am not completely sure what this styleName thing does. Is it mac/windows only? Is it Qt 4.8+ only? Will the bug exist on other systems with your patch applied?

But I see that you introduced this thing in f496ec3 and I presume that you understand it!

Concerning master, applying your patch breaks \neq, presumably because Guillaume worked around the problem manually.

Here is what I came up with. Is it what you had in mind, or should the || in the test become a && ?

You can see that the \kern in the definition of \not is gone, and this is definitely a good thing.

JMarc


diff --git a/lib/symbols b/lib/symbols
index 82a6d13..2318d74 100644
--- a/lib/symbols
+++ b/lib/symbols
@@ -314,7 +314,7 @@ spadesuit          cmsy        127 170 mathord  ♠
 lyxnot             cmsy         54  47 mathrel  /           hiddensymbol
 iffont cmsy
 # kerning is slightly imperfect so that one can see when \not is selected
-\def\not{\lyxnot\mathrel{\kern-11mu}}
+\def\not{\lyxnot}
 else
 \def\not{\kern4mu\lyxnot\kern-19mu}
 endif
diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp
index a0fa699..2f598f4 100644
--- a/src/frontends/qt4/GuiFontMetrics.cpp
+++ b/src/frontends/qt4/GuiFontMetrics.cpp
@@ -182,17 +182,28 @@ int GuiFontMetrics::width(docstring const & s) const
 	int * pw = strwidth_cache_[s];
 	if (pw)
 		return *pw;
-	// For some reason QMetrics::width returns a wrong value with Qt5
-	// int w = metrics_.width(toqstr(s));
 	PROFILE_CACHE_MISS(width)
 #endif
-	QTextLayout tl;
-	tl.setText(toqstr(s));
-	tl.setFont(font_);
-	tl.beginLayout();
-	QTextLine line = tl.createLine();
-	tl.endLayout();
-	int w = int(line.naturalTextWidth());
+	/* For some reason QMetrics::width returns a wrong value with Qt5
+	 * with some arabic text. OTOH, QTextLayout is broken for single
+	 * characters with null width (like \not in mathed).
+	*/
+	int w = 0;
+	if (s.length() == 1
+#if QT_VERSION >= 0x040800
+	    || font_.styleName() == "LyX"
+#endif
+	    )
+		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