summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-04-29 22:45:14 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-05-07 07:48:43 +0000
commit6afdbfdaafcc4d24e08357dfea96b85787efb1f7 (patch)
treef75fc26e4dff8d035f3c285daf5d8cd5dafd8044
parentc57520e491f420dc83d44ce5382c403192ce4836 (diff)
Use "monospace" as fallback system FixedFont in KDE theme; logging
Also de-duplicate the "monospace" string in qgenericunixthemes.cpp, and add tst_QFontDatabase::systemFixedFont() to verify that QFontDatabase::systemFont(QFontDatabase::FixedFont) really returns a monospace font across platforms. Replace commented-out qDebug()s with qt.text.font.match and qt.text.font.db logging categories to troubleshoot when the test fails (among other uses). Add qt.qpa.fonts logging category to unix themes to show default system and fixed fonts (font engines on other platforms are already using this category). Fixes: QTBUG-54623 Change-Id: I2aa62b8c783d9ddb591a5e06e8df85c4af5bcb0c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--src/gui/text/qfontdatabase.cpp52
-rw-r--r--src/platformsupport/themes/genericunix/qgenericunixthemes.cpp12
-rw-r--r--tests/auto/gui/text/qfontdatabase/BLACKLIST3
-rw-r--r--tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp13
4 files changed, 45 insertions, 35 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 196eebb353..008ddad5cd 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qfontdatabase.h"
-#include "qdebug.h"
+#include "qloggingcategory.h"
#include "qalgorithms.h"
#include "qguiapplication.h"
#include "qvarlengtharray.h" // here or earlier - workaround for VC++6
@@ -59,25 +59,13 @@
#include <stdlib.h>
#include <algorithm>
-
-// #define QFONTDATABASE_DEBUG
-#ifdef QFONTDATABASE_DEBUG
-# define FD_DEBUG qDebug
-#else
-# define FD_DEBUG if (false) qDebug
-#endif
-
-// #define FONT_MATCH_DEBUG
-#ifdef FONT_MATCH_DEBUG
-# define FM_DEBUG qDebug
-#else
-# define FM_DEBUG if (false) qDebug
-#endif
-
#include <qtgui_tracepoints_p.h>
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcFontDb, "qt.text.font.db")
+Q_LOGGING_CATEGORY(lcFontMatch, "qt.text.font.match")
+
#define SMOOTH_SCALABLE 0xffff
#if defined(QT_BUILD_INTERNAL)
@@ -744,7 +732,7 @@ void qt_registerFont(const QString &familyName, const QString &stylename,
const QSupportedWritingSystems &writingSystems, void *handle)
{
QFontDatabasePrivate *d = privateDb();
-// qDebug() << "Adding font" << familyName << weight << style << pixelSize << antialiased;
+ qCDebug(lcFontDb) << "Adding font" << familyName << weight << style << pixelSize << "aa" << antialiased << "fixed" << fixedPitch;
QtFontStyle::Key styleKey;
styleKey.style = style;
styleKey.weight = weight;
@@ -1079,7 +1067,7 @@ static QtFontStyle *bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &st
}
}
- FM_DEBUG( " best style has distance 0x%x", dist );
+ qCDebug(lcFontMatch, " best style has distance 0x%x", dist );
return foundry->styles[best];
}
@@ -1098,20 +1086,20 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
desc->size = 0;
- FM_DEBUG(" REMARK: looking for best foundry for family '%s' [%d]", family->name.toLatin1().constData(), family->count);
+ qCDebug(lcFontMatch, " REMARK: looking for best foundry for family '%s' [%d]", family->name.toLatin1().constData(), family->count);
for (int x = 0; x < family->count; ++x) {
QtFontFoundry *foundry = family->foundries[x];
if (!foundry_name.isEmpty() && foundry->name.compare(foundry_name, Qt::CaseInsensitive) != 0)
continue;
- FM_DEBUG(" looking for matching style in foundry '%s' %d",
+ qCDebug(lcFontMatch, " looking for matching style in foundry '%s' %d",
foundry->name.isEmpty() ? "-- none --" : foundry->name.toLatin1().constData(), foundry->count);
QtFontStyle *style = bestStyle(foundry, styleKey, styleName);
if (!style->smoothScalable && (styleStrategy & QFont::ForceOutline)) {
- FM_DEBUG(" ForceOutline set, but not smoothly scalable");
+ qCDebug(lcFontMatch, " ForceOutline set, but not smoothly scalable");
continue;
}
@@ -1122,7 +1110,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
if (!(styleStrategy & QFont::ForceOutline)) {
size = style->pixelSize(pixelSize);
if (size) {
- FM_DEBUG(" found exact size match (%d pixels)", size->pixelSize);
+ qCDebug(lcFontMatch, " found exact size match (%d pixels)", size->pixelSize);
px = size->pixelSize;
}
}
@@ -1131,7 +1119,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
if (!size && style->smoothScalable && ! (styleStrategy & QFont::PreferBitmap)) {
size = style->pixelSize(SMOOTH_SCALABLE);
if (size) {
- FM_DEBUG(" found smoothly scalable font (%d pixels)", pixelSize);
+ qCDebug(lcFontMatch, " found smoothly scalable font (%d pixels)", pixelSize);
px = pixelSize;
}
}
@@ -1140,7 +1128,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
if (!size && style->bitmapScalable && (styleStrategy & QFont::PreferMatch)) {
size = style->pixelSize(0);
if (size) {
- FM_DEBUG(" found bitmap scalable font (%d pixels)", pixelSize);
+ qCDebug(lcFontMatch, " found bitmap scalable font (%d pixels)", pixelSize);
px = pixelSize;
}
}
@@ -1164,12 +1152,12 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
if (d < distance) {
distance = d;
size = style->pixelSizes + x;
- FM_DEBUG(" best size so far: %3d (%d)", size->pixelSize, pixelSize);
+ qCDebug(lcFontMatch, " best size so far: %3d (%d)", size->pixelSize, pixelSize);
}
}
if (!size) {
- FM_DEBUG(" no size supports the script we want");
+ qCDebug(lcFontMatch, " no size supports the script we want");
continue;
}
@@ -1204,7 +1192,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
this_score += qAbs(px - pixelSize);
if (this_score < score) {
- FM_DEBUG(" found a match: score %x best score so far %x",
+ qCDebug(lcFontMatch, " found a match: score %x best score so far %x",
this_score, score);
score = this_score;
@@ -1212,7 +1200,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
desc->style = style;
desc->size = size;
} else {
- FM_DEBUG(" score %x no better than best %x", this_score, score);
+ qCDebug(lcFontMatch, " score %x no better than best %x", this_score, score);
}
}
@@ -1245,7 +1233,7 @@ static int match(int script, const QFontDef &request,
char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p';
- FM_DEBUG("QFontDatabase::match\n"
+ qCDebug(lcFontMatch, "QFontDatabase::match\n"
" request:\n"
" family: %s [%s], script: %d\n"
" weight: %d, style: %d\n"
@@ -2683,7 +2671,7 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
QFontCache::Key key(request, script, multi ? 1 : 0);
engine = fontCache->findEngine(key);
if (engine) {
- FM_DEBUG("Cache hit level 1");
+ qCDebug(lcFontMatch, "Cache hit level 1");
return engine;
}
@@ -2713,7 +2701,7 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
else
blackListed.append(index);
} else {
- FM_DEBUG(" NO MATCH FOUND\n");
+ qCDebug(lcFontMatch, " NO MATCH FOUND\n");
}
if (!engine) {
@@ -2757,7 +2745,7 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
if (!engine)
engine = new QFontEngineBox(request.pixelSize);
- FM_DEBUG("returning box engine");
+ qCDebug(lcFontMatch, "returning box engine");
}
return engine;
diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
index 1003812767..6db25a90da 100644
--- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
+++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
@@ -76,6 +76,7 @@
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(qLcTray)
+Q_LOGGING_CATEGORY(lcQpaFonts, "qt.qpa.fonts")
ResourceHelper::ResourceHelper()
{
@@ -96,6 +97,7 @@ const char *QGenericUnixTheme::name = "generic";
// Default system font, corresponding to the value returned by 4.8 for
// XRender/FontConfig which we can now assume as default.
static const char defaultSystemFontNameC[] = "Sans Serif";
+static const char defaultFixedFontNameC[] = "monospace";
enum { defaultSystemFontSize = 9 };
#if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON)
@@ -136,9 +138,10 @@ public:
QGenericUnixThemePrivate()
: QPlatformThemePrivate()
, systemFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize)
- , fixedFont(QStringLiteral("monospace"), systemFont.pointSize())
+ , fixedFont(QLatin1String(defaultFixedFontNameC), systemFont.pointSize())
{
fixedFont.setStyleHint(QFont::TypeWriter);
+ qCDebug(lcQpaFonts) << "default fonts: system" << systemFont << "fixed" << fixedFont;
}
const QFont systemFont;
@@ -390,7 +393,7 @@ void QKdeThemePrivate::refresh()
if (QFont *fixedFont = kdeFont(readKdeSetting(QStringLiteral("fixed"), kdeDirs, kdeVersion, kdeSettings))) {
resources.fonts[QPlatformTheme::FixedFont] = fixedFont;
} else {
- fixedFont = new QFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize);
+ fixedFont = new QFont(QLatin1String(defaultFixedFontNameC), defaultSystemFontSize);
fixedFont->setStyleHint(QFont::TypeWriter);
resources.fonts[QPlatformTheme::FixedFont] = fixedFont;
}
@@ -403,6 +406,8 @@ void QKdeThemePrivate::refresh()
if (QFont *toolBarFont = kdeFont(readKdeSetting(QStringLiteral("toolBarFont"), kdeDirs, kdeVersion, kdeSettings)))
resources.fonts[QPlatformTheme::ToolButtonFont] = toolBarFont;
+ qCDebug(lcQpaFonts) << "default fonts: system" << resources.fonts[QPlatformTheme::SystemFont]
+ << "fixed" << resources.fonts[QPlatformTheme::FixedFont];
qDeleteAll(kdeSettings);
}
@@ -716,8 +721,9 @@ public:
QString fontName = gtkFontName.left(split);
systemFont = new QFont(fontName, size);
- fixedFont = new QFont(QLatin1String("monospace"), systemFont->pointSize());
+ fixedFont = new QFont(QLatin1String(defaultFixedFontNameC), systemFont->pointSize());
fixedFont->setStyleHint(QFont::TypeWriter);
+ qCDebug(lcQpaFonts) << "default fonts: system" << systemFont << "fixed" << fixedFont;
}
mutable QFont *systemFont;
diff --git a/tests/auto/gui/text/qfontdatabase/BLACKLIST b/tests/auto/gui/text/qfontdatabase/BLACKLIST
new file mode 100644
index 0000000000..7f479e4b0e
--- /dev/null
+++ b/tests/auto/gui/text/qfontdatabase/BLACKLIST
@@ -0,0 +1,3 @@
+[systemFixedFont] # QTBUG-54623
+winrt
+b2qt
diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
index 68664cdd2f..064e37f73c 100644
--- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
+++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
@@ -35,6 +35,8 @@
#include <private/qrawfont_p.h>
#include <qpa/qplatformfontdatabase.h>
+Q_LOGGING_CATEGORY(lcTests, "qt.text.tests")
+
class tst_QFontDatabase : public QObject
{
Q_OBJECT
@@ -49,6 +51,7 @@ private slots:
void fixedPitch_data();
void fixedPitch();
+ void systemFixedFont();
#ifdef Q_OS_MAC
void trickyFonts_data();
@@ -156,6 +159,16 @@ void tst_QFontDatabase::fixedPitch()
QCOMPARE(fi.fixedPitch(), fixedPitch);
}
+void tst_QFontDatabase::systemFixedFont() // QTBUG-54623
+{
+ QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
+ QFontInfo fontInfo(font);
+ bool fdbSaysFixed = QFontDatabase().isFixedPitch(fontInfo.family(), fontInfo.styleName());
+ qCDebug(lcTests) << "system fixed font is" << font << "really fixed?" << fdbSaysFixed << fontInfo.fixedPitch();
+ QVERIFY(fdbSaysFixed);
+ QVERIFY(fontInfo.fixedPitch());
+}
+
#ifdef Q_OS_MAC
void tst_QFontDatabase::trickyFonts_data()
{