From f059feb9c60af798f0492256027ccb970972ab08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Andriot?= Date: Tue, 16 Sep 2014 03:35:37 +0200 Subject: [PATCH] Fix dpi detection when using xft2 --- src/kernel/qfontdatabase_x11.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/kernel/qfontdatabase_x11.cpp b/src/kernel/qfontdatabase_x11.cpp index 286bd08e..bb555ed3 100644 --- a/src/kernel/qfontdatabase_x11.cpp +++ b/src/kernel/qfontdatabase_x11.cpp @@ -1513,13 +1513,25 @@ static double addPatternProps(XftPattern *pattern, const TQtFontStyle::Key &key, convert the pixel size to a point size and request that. */ double size_value = request.pixelSize; + double dpi = TQPaintDevice::x11AppDpiY(fp->screen); double scale = 1.; if ( size_value > MAXFONTSIZE_XFT ) { scale = (double)size_value/(double)MAXFONTSIZE_XFT; size_value = MAXFONTSIZE_XFT; } - size_value = size_value*72./TQPaintDevice::x11AppDpiY(fp->screen); +#ifdef QT_XFT2 + /* + 2006-12-28 If QT is not compiled against xft1, there is no need + for the workaround above (confirmed). Thus, in addition, add + font pixelsize to the pattern to avoid fontconfig making wrong + guesses. Also provide a DPI value for fontconfig so it never + attempts to fallback to its default. + */ + XftPatternAddDouble(pattern, XFT_PIXEL_SIZE, size_value); + XftPatternAddDouble(pattern, XFT_DPI, dpi); +#endif + size_value = size_value*72./dpi; XftPatternAddDouble( pattern, XFT_SIZE, size_value ); #ifdef XFT_MATRIX @@ -1877,6 +1889,11 @@ static TQFontEngine *loadFontConfigFont(const TQFontPrivate *fp, const TQFontDef FcResult result; FcFontSet *fs = 0; FcPattern *fsp = 0; + + // Properly conform to fontconfig API. We need to call FcDefaultSubstitute() + // before FcFontSort()/FcFontMatch(). + FcDefaultSubstitute(pattern); + if( use_fontsort ) { fs = FcFontSort(0, pattern, FcFalse, 0, &result); if (!fs)