From ef8cd7f2e68d6d34d70c3a12e82a67ed16b92b72 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 20 May 2010 14:33:37 +0200 Subject: Fix crash when using fonts in non-gui QApplication XLFD requires a DISPLAY connection to work. We would get crashes in a QApplication with GUI disabled when: 1. Not using FontConfig, or 2. Falling back to XLFD for bitmap fonts that require scaling. The patch disables paths to loadXlfd() when GUI is disabled. This means that in XLFD, we will always get a box font, which is the same behavior as when using fonts outside the main thread. There doesn't seem to be any way around this. With FontConfig, we will use the font it returns, even if it's a slightly wrong size. Main consequence will be for using bitmap fonts for printing on a highres printer in a non-gui application. Again, there does not seem to be any way around this. NOTE: I've also added a catch to avoid going into loadXlfd() in the fallback if we're not on the main thread, since this was missing. Task-number: QTBUG-10448 Reviewed-by: Trond --- src/gui/text/qfontdatabase_x11.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp index 3b2e4e9..a7aa2ce 100644 --- a/src/gui/text/qfontdatabase_x11.cpp +++ b/src/gui/text/qfontdatabase_x11.cpp @@ -78,6 +78,9 @@ QT_BEGIN_NAMESPACE extern double qt_pointSize(double pixelSize, int dpi); extern double qt_pixelSize(double pointSize, int dpi); +// from qapplication.cpp +extern bool qt_is_gui_used; + static inline void capitalize (char *s) { bool space = true; @@ -1938,7 +1941,7 @@ void QFontDatabase::load(const QFontPrivate *d, int script) } else if (X11->has_fontconfig) { fe = loadFc(d, script, req); - if (fe != 0 && fe->fontDef.pixelSize != req.pixelSize) { + if (fe != 0 && fe->fontDef.pixelSize != req.pixelSize && mainThread && qt_is_gui_used) { QFontEngine *xlfdFontEngine = loadXlfd(d->screen, script, req); if (xlfdFontEngine->fontDef.family == fe->fontDef.family) { delete fe; @@ -1950,7 +1953,7 @@ void QFontDatabase::load(const QFontPrivate *d, int script) #endif - } else if (mainThread) { + } else if (mainThread && qt_is_gui_used) { fe = loadXlfd(d->screen, script, req); } if (!fe) { -- cgit v0.12