display of $int...$ under QT5

Enrico Forestieri forenr at lyx.org
Wed Sep 2 08:33:03 UTC 2020


On Wed, Sep 02, 2020 at 09:45:58AM +0200, Enrico Forestieri wrote:
> On Wed, Sep 02, 2020 at 07:45:44AM +0200, Cor Blom wrote:
> > Op 01-09-2020 om 22:21 schreef Enrico Forestieri:
> > > We already have an elegant solution. We rely on Qt to do the right thing
> > > with QFontDatabase::addApplicationFont(), but on linux it does not work
> > > right, contrarily to Windows (and I think MacOS) where it works well.
> > > In this case it should suffice to directly add the lyx font directory
> > > to the fontconfig paths. The fonts ditributed with lyx are a superset
> > > of the texlive ones and could also replace them. However, this is not
> > > necessary because we can find our fonts by requesting the style "LyX",
> > > provided that fontconfig can find them.
> > 
> > I think I know why it does not work. The lyx fonts are installed in
> > /usr/share/lyx/fonts and it looks to me this is kind of hardcoded, because
> > "lyx -dbg font" only gives OK for me when the fonts are in that directory.
> > 
> > Fontconfig, however, does not look into that directory. So "fc-match -v
> > "esint10: style=lyx" | grep file:" only give me the correct result when the
> > lyx fonts are in /usr/share/fonts.

This is to be expected, because the fonts should be seen only by lyx. This
is how QFontDatabase::addApplicationFont() should work. It is the fact that
you don't see some glyphs that indicates the failure.

However, it would be interesting if you could report the result of the
attached patch. This is a patch for lyx 2.3, the corresponding patch for
the development version 2.4 can be found as an attachment to another email
in this thread. It should show which font file lyx uses for math fonts.
You will have to configure lyx using LIBS=-lfontconfig, i.e.,

configure [your usual options here] LIBS=-lfontconfig

After building lyx, create a new document and then a math inset.
You should then see all used font files printed in the terminal.

If you do not add /usr/share/lyx/fonts to the fontconfig directories
(make sure that "fc-match -v 'esint10: style=lyx' | grep file:" does
not return the "correct" result) and no fonts in /usr/share/lyx/fonts
are spotted, we can be sure that QFontDatabase::addApplicationFont()
does not work.

-- 
Enrico
-------------- next part --------------
diff --git a/src/frontends/qt4/GuiFontLoader.cpp b/src/frontends/qt/4GuiFontLoader.cpp
index 82dafbffd7..366f015faf 100644
--- a/src/frontends/qt4/GuiFontLoader.cpp
+++ b/src/frontends/qt4/GuiFontLoader.cpp
@@ -182,6 +182,37 @@ static bool isChosenFont(QFont & font, QString const & family,
 }
 
 
+#if defined Q_WS_X11 || defined(QPA_XCB)
+#include <fontconfig/fontconfig.h>
+static void print_font_file(QString const & fam_name, QString const & sty_name)
+{
+	FcConfig * config = NULL;
+	QString const family_and_style = sty_name.isEmpty() ? fam_name
+		: fam_name + QLatin1String(": style=") + sty_name;
+	FcPattern * pat = FcNameParse(reinterpret_cast<FcChar8 const *>(family_and_style.toLocal8Bit().data()));
+	FcConfigSubstitute(config, pat, FcMatchPattern);
+	FcDefaultSubstitute(pat);
+	FcResult res;
+	FcPattern * font = FcFontMatch(config, pat, &res);
+	if (font) {
+		FcChar8 * file = NULL;
+		FcChar8 * family = NULL;
+		FcChar8 * style = NULL;
+		if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch &&
+		    FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch &&
+		    FcPatternGetString(font, FC_STYLE, 0, &style) == FcResultMatch) {
+			lyxerr << "Filename: " << reinterpret_cast<char *>(file)
+			       << " (family " << reinterpret_cast<char *>(family)
+			       << ", style " << reinterpret_cast<char *>(style)
+			       << ")" << endl;
+		}
+		FcPatternDestroy(font);
+	}
+	FcPatternDestroy(pat);
+}
+#endif
+
+
 QFont symbolFont(QString const & family, bool * ok)
 {
 	LYXERR(Debug::FONT, "Looking for font family " << family << " ... ");
@@ -196,6 +227,9 @@ QFont symbolFont(QString const & family, bool * ok)
 	if (isChosenFont(font, family, "LyX")) {
 		LYXERR(Debug::FONT, "lyx!");
 		*ok = true;
+#if defined Q_WS_X11 || defined(QPA_XCB)
+		print_font_file(family, "LyX");
+#endif
 		return font;
 	}
 
@@ -206,6 +240,9 @@ QFont symbolFont(QString const & family, bool * ok)
 	if (isChosenFont(font, family, QString())) {
 		LYXERR(Debug::FONT, "normal!");
 		*ok = true;
+#if defined Q_WS_X11 || defined(QPA_XCB)
+		print_font_file(family, QString());
+#endif
 		return font;
 	}
 
@@ -215,6 +252,9 @@ QFont symbolFont(QString const & family, bool * ok)
 	if (isChosenFont(font, upper, QString())) {
 		LYXERR(Debug::FONT, "upper!");
 		*ok = true;
+#if defined Q_WS_X11 || defined(QPA_XCB)
+		print_font_file(upper, QString());
+#endif
 		return font;
 	}
 
@@ -227,6 +267,9 @@ QFont symbolFont(QString const & family, bool * ok)
 	if (isChosenFont(font, family, QString())) {
 		LYXERR(Debug::FONT, "raw version!");
 		*ok = true;
+#if defined Q_WS_X11 || defined(QPA_XCB)
+		print_font_file(family, QString());
+#endif
 		return font;
 	}
 


More information about the lyx-devel mailing list