diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 233bc04924..99c17435dc 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -2726,7 +2726,7 @@ bool QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs, QPoint offset; QImage *alphaMap = fontEngine->lockedAlphaMapForGlyph(glyphs[i], spp, neededFormat, s->matrix, &offset); - if (alphaMap == 0) + if (alphaMap == 0 || alphaMap->isNull()) continue; alphaPenBlt(alphaMap->bits(), alphaMap->bytesPerLine(), alphaMap->depth(), diff --git a/src/gui/text/qfontdatabase_qpa.cpp b/src/gui/text/qfontdatabase_qpa.cpp index 3a578e746f..fbee077ba7 100644 --- a/src/gui/text/qfontdatabase_qpa.cpp +++ b/src/gui/text/qfontdatabase_qpa.cpp @@ -53,16 +53,18 @@ QT_BEGIN_NAMESPACE Q_GUI_EXPORT void qt_registerFont(const QString &familyName, const QString &foundryname, int weight, - QFont::Style style, int stretch, bool antialiased, bool scalable, int pixelSize, + QFont::Style style, int stretch, bool antialiased, + bool scalable, int pixelSize, bool fixedPitch, const QSupportedWritingSystems &writingSystems, void *handle) { QFontDatabasePrivate *d = privateDb(); - // qDebug() << "Adding font" << familyname << weight << italic << pixelSize << file << fileIndex << antialiased; + // qDebug() << "Adding font" << familyName << weight << style << pixelSize << antialiased; QtFontStyle::Key styleKey; styleKey.style = style; styleKey.weight = weight; styleKey.stretch = stretch; QtFontFamily *f = d->family(familyName, true); + f->fixedPitch = fixedPitch; for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) { if (writingSystems.supported(QFontDatabase::WritingSystem(i))) { @@ -106,10 +108,12 @@ static QStringList fallbackFamilies(const QString &family, const QFont::Style &s static void initializeDb() { static int initialized = false; + QFontDatabasePrivate *db = privateDb(); - if (!initialized) { + if (!initialized || db->reregisterAppFonts) { //init by asking for the platformfontdb for the first time :) QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase(); + db->reregisterAppFonts = false; initialized = true; } } diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 4f18aa3efd..fabd8c3634 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -1281,7 +1281,11 @@ glyph_metrics_t QFontEngineBox::boundingBox(glyph_t) return glyph_metrics_t(0, -_size, _size, _size, _size, 0); } - +QFontEngine *QFontEngineBox::cloneWithSize(qreal pixelSize) const +{ + QFontEngineBox *fe = new QFontEngineBox(pixelSize); + return fe; +} QFixed QFontEngineBox::ascent() const { diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index f74302c054..2bec69c467 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -379,6 +379,7 @@ public: virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs); virtual glyph_metrics_t boundingBox(glyph_t glyph); + virtual QFontEngine *cloneWithSize(qreal pixelSize) const; virtual QFixed ascent() const; virtual QFixed descent() const; diff --git a/src/gui/text/qplatformfontdatabase_qpa.cpp b/src/gui/text/qplatformfontdatabase_qpa.cpp index 7ad838561b..cedf481898 100644 --- a/src/gui/text/qplatformfontdatabase_qpa.cpp +++ b/src/gui/text/qplatformfontdatabase_qpa.cpp @@ -48,8 +48,9 @@ QT_BEGIN_NAMESPACE extern void qt_registerFont(const QString &familyname, const QString &foundryname, int weight, - QFont::Style style, int stretch, bool antialiased,bool scalable, int pixelSize, - const QSupportedWritingSystems &writingSystems, void *hanlde); + QFont::Style style, int stretch, bool antialiased, + bool scalable, int pixelSize, bool fixedPitch, + const QSupportedWritingSystems &writingSystems, void *hanlde); /*! \fn void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *handle) @@ -88,7 +89,7 @@ void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void * } } QFont::Stretch stretch = QFont::Unstretched; - registerFont(fontName,QString(),fontWeight,fontStyle,stretch,true,false,pixelSize,writingSystems,handle); + registerFont(fontName,QString(),fontWeight,fontStyle,stretch,true,false,pixelSize,false,writingSystems,handle); } } else { qDebug() << "header verification of QPF2 font failed. maybe it is corrupt?"; @@ -122,12 +123,16 @@ void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void * \sa registerQPF2Font() */ void QPlatformFontDatabase::registerFont(const QString &familyname, const QString &foundryname, QFont::Weight weight, - QFont::Style style, QFont::Stretch stretch, bool antialiased, bool scalable, int pixelSize, + QFont::Style style, QFont::Stretch stretch, bool antialiased, + bool scalable, int pixelSize, bool fixedPitch, const QSupportedWritingSystems &writingSystems, void *usrPtr) { if (scalable) pixelSize = 0; - qt_registerFont(familyname,foundryname,weight,style,stretch,antialiased,scalable,pixelSize,writingSystems,usrPtr); + + qt_registerFont(familyname, foundryname, weight, style, + stretch, antialiased, scalable, pixelSize, + fixedPitch, writingSystems, usrPtr); } class QWritingSystemsPrivate diff --git a/src/gui/text/qplatformfontdatabase_qpa.h b/src/gui/text/qplatformfontdatabase_qpa.h index d34d602e43..ad94b108da 100644 --- a/src/gui/text/qplatformfontdatabase_qpa.h +++ b/src/gui/text/qplatformfontdatabase_qpa.h @@ -103,7 +103,8 @@ public: //callback static void registerQPF2Font(const QByteArray &dataArray, void *handle); static void registerFont(const QString &familyname, const QString &foundryname, QFont::Weight weight, - QFont::Style style, QFont::Stretch stretch, bool antialiased, bool scalable, int pixelSize, + QFont::Style style, QFont::Stretch stretch, bool antialiased, + bool scalable, int pixelSize, bool fixedPitch, const QSupportedWritingSystems &writingSystems, void *handle); }; diff --git a/src/platformsupport/fontdatabases/basicunix/qbasicunixfontdatabase.cpp b/src/platformsupport/fontdatabases/basicunix/qbasicunixfontdatabase.cpp index 1086a98d85..bca40591f6 100644 --- a/src/platformsupport/fontdatabases/basicunix/qbasicunixfontdatabase.cpp +++ b/src/platformsupport/fontdatabases/basicunix/qbasicunixfontdatabase.cpp @@ -354,6 +354,8 @@ QStringList QBasicUnixFontDatabase::addTTFile(const QByteArray &fontData, const if (face->style_flags & FT_STYLE_FLAG_BOLD) weight = QFont::Bold; + bool fixedPitch = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH); + QSupportedWritingSystems writingSystems; // detect symbol fonts for (int i = 0; i < face->num_charmaps; ++i) { @@ -415,7 +417,7 @@ QStringList QBasicUnixFontDatabase::addTTFile(const QByteArray &fontData, const QFont::Stretch stretch = QFont::Unstretched; - registerFont(family,QString(),weight,style,stretch,true,true,0,writingSystems,fontFile); + registerFont(family,QString(),weight,style,stretch,true,true,0,fixedPitch,writingSystems,fontFile); families.append(family); diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp index d5e1fd1de7..e566cee4f4 100644 --- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp +++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp @@ -57,6 +57,11 @@ #include FT_TRUETYPE_TABLES_H #include +#include FT_FREETYPE_H + +#if FC_VERSION >= 20402 +#include +#endif #define SimplifiedChineseCsbBit 18 #define TraditionalChineseCsbBit 20 @@ -444,8 +449,9 @@ void QFontconfigDatabase::populateFontDatabase() FcPatternGetDouble (fonts->fonts[i], FC_PIXEL_SIZE, 0, &pixel_size); } + bool fixedPitch = spacing_value >= FC_MONO; QFont::Stretch stretch = QFont::Unstretched; - QPlatformFontDatabase::registerFont(familyName,QLatin1String((const char *)foundry_value),weight,style,stretch,antialias,scalable,pixel_size,writingSystems,fontFile); + QPlatformFontDatabase::registerFont(familyName,QLatin1String((const char *)foundry_value),weight,style,stretch,antialias,scalable,pixel_size,fixedPitch,writingSystems,fontFile); // qDebug() << familyName << (const char *)foundry_value << weight << style << &writingSystems << scalable << true << pixel_size; } @@ -470,9 +476,9 @@ void QFontconfigDatabase::populateFontDatabase() QString familyQtName = QString::fromLatin1(f->qtname); while (f->qtname) { - registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleNormal,QFont::Unstretched,true,true,0,ws,0); - registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleItalic,QFont::Unstretched,true,true,0,ws,0); - registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleOblique,QFont::Unstretched,true,true,0,ws,0); + registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleNormal,QFont::Unstretched,true,true,0,f->fixed,ws,0); + registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleItalic,QFont::Unstretched,true,true,0,f->fixed,ws,0); + registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleOblique,QFont::Unstretched,true,true,0,f->fixed,ws,0); ++f; } @@ -583,3 +589,72 @@ QStringList QFontconfigDatabase::fallbacksForFamily(const QString family, const return fallbackFamilies; } + +static FcPattern *queryFont(const FcChar8 *file, const QByteArray &data, int id, FcBlanks *blanks, int *count) +{ +#if FC_VERSION < 20402 + Q_UNUSED(data) + return FcFreeTypeQuery(file, id, blanks, count); +#else + if (data.isEmpty()) + return FcFreeTypeQuery(file, id, blanks, count); + + extern FT_Library qt_getFreetype(); + FT_Library lib = qt_getFreetype(); + + FcPattern *pattern = 0; + + FT_Face face; + if (!FT_New_Memory_Face(lib, (const FT_Byte *)data.constData(), data.size(), id, &face)) { + *count = face->num_faces; + + pattern = FcFreeTypeQueryFace(face, file, id, blanks); + + FT_Done_Face(face); + } + + return pattern; +#endif +} + +QStringList QFontconfigDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) +{ + QStringList families; + FcFontSet *set = FcConfigGetFonts(0, FcSetApplication); + if (!set) { + FcConfigAppFontAddFile(0, (const FcChar8 *)":/non-existent"); + set = FcConfigGetFonts(0, FcSetApplication); // try again + if (!set) + return families; + } + + int id = 0; + FcBlanks *blanks = FcConfigGetBlanks(0); + int count = 0; + + FcPattern *pattern = 0; + do { + pattern = queryFont((const FcChar8 *)QFile::encodeName(fileName).constData(), + fontData, id, blanks, &count); + if (!pattern) + return families; + + FcPatternDel(pattern, FC_FILE); + QByteArray cs = fileName.toUtf8(); + FcPatternAddString(pattern, FC_FILE, (const FcChar8 *) cs.constData()); + + FcChar8 *fam = 0; + if (FcPatternGetString(pattern, FC_FAMILY, 0, &fam) == FcResultMatch) { + QString family = QString::fromUtf8(reinterpret_cast(fam)); + families << family; + } + + if (!FcFontSetAdd(set, pattern)) + return families; + + ++id; + } while (pattern && id < count); + + return families; +} + diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase_p.h b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase_p.h index 5a5e4b670f..eec510722a 100644 --- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase_p.h +++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase_p.h @@ -51,6 +51,7 @@ public: void populateFontDatabase(); QFontEngine *fontEngine(const QFontDef &fontDef, QUnicodeTables::Script script, void *handle); QStringList fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const; + QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName); }; #endif // QFONTCONFIGDATABASE_H diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index 7da4e07161..b96ae6f3da 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -348,8 +348,6 @@ static bool addFontToDatabase(QString familyName, const QString &scriptName, const QFont::Weight weight = weightFromInteger(tm->tmWeight); const QFont::Stretch stretch = QFont::Unstretched; - Q_UNUSED(fixed) - if (QWindowsContext::verboseFonts > 2) { QDebug nospace = qDebug().nospace(); nospace << __FUNCTION__ << familyName << scriptName @@ -394,17 +392,17 @@ static bool addFontToDatabase(QString familyName, const QString &scriptName, } QPlatformFontDatabase::registerFont(familyName, foundryName, weight, - style, stretch, antialias, scalable, size, writingSystems, 0); + style, stretch, antialias, scalable, size, fixed, writingSystems, 0); // add fonts windows can generate for us: if (weight <= QFont::DemiBold) QPlatformFontDatabase::registerFont(familyName, foundryName, QFont::Bold, - style, stretch, antialias, scalable, size, writingSystems, 0); + style, stretch, antialias, scalable, size, fixed, writingSystems, 0); if (style != QFont::StyleItalic) QPlatformFontDatabase::registerFont(familyName, foundryName, weight, - QFont::StyleItalic, stretch, antialias, scalable, size, writingSystems, 0); + QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); if (weight <= QFont::DemiBold && style != QFont::StyleItalic) QPlatformFontDatabase::registerFont(familyName, foundryName, QFont::Bold, - QFont::StyleItalic, stretch, antialias, scalable, size, writingSystems, 0); + QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); return true; } diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index 5e3aacf37e..7914ecb00c 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -144,6 +144,8 @@ void tst_QFontDatabase::fixedPitch_data() #ifndef Q_WS_MAC QTest::newRow( "Script" ) << QString( "Script" ) << false; QTest::newRow( "Lucida Console" ) << QString( "Lucida Console" ) << true; + QTest::newRow( "DejaVu Sans" ) << QString( "DejaVu Sans" ) << false; + QTest::newRow( "DejaVu Sans Mono" ) << QString( "DejaVu Sans Mono" ) << true; #else QTest::newRow( "Menlo" ) << QString( "Menlo" ) << true; QTest::newRow( "Monaco" ) << QString( "Monaco" ) << true; @@ -162,13 +164,6 @@ void tst_QFontDatabase::fixedPitch() if (!fdb.families().contains(font)) QSKIP( "Font not installed", SkipSingle); -#ifdef Q_WS_QPA - if (fixedPitch) { - // fixedPitch() never returns true on qpa - QEXPECT_FAIL("", "QTBUG-20754 fails on qpa", Abort); - } -#endif - QCOMPARE(fdb.isFixedPitch(font), fixedPitch); QFont qfont(font); @@ -238,10 +233,6 @@ void tst_QFontDatabase::addAppFont() QFontDatabase db; -#ifdef Q_WS_QPA - QEXPECT_FAIL("memory font", "QTBUG-20754 fails on qpa", Abort); -#endif - const QStringList oldFamilies = db.families(); QVERIFY(!oldFamilies.isEmpty()); @@ -275,10 +266,6 @@ void tst_QFontDatabase::addAppFont() const QStringList addedFamilies = QFontDatabase::applicationFontFamilies(id); QVERIFY(!addedFamilies.isEmpty()); -#ifdef Q_WS_QPA - QEXPECT_FAIL("font file", "QTBUG-20754 fails on qpa", Abort); -#endif - const QStringList newFamilies = db.families(); QVERIFY(!newFamilies.isEmpty()); QVERIFY(newFamilies.count() >= oldFamilies.count()); diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index 982cfc11d9..20ff8b7d8f 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -276,21 +276,11 @@ void tst_QFontMetrics::inFontUcs4() QFont font("QtTestUcs4"); { QFontMetrics fm(font); - -#ifdef Q_WS_QPA - QEXPECT_FAIL("", "QTBUG-20759 fails for qpa", Continue); -#endif - QVERIFY(fm.inFontUcs4(0x1D7FF)); } { QFontMetricsF fm(font); - -#ifdef Q_WS_QPA - QEXPECT_FAIL("", "QTBUG-20759 fails for qpa", Continue); -#endif - QVERIFY(fm.inFontUcs4(0x1D7FF)); } @@ -311,11 +301,6 @@ void tst_QFontMetrics::lineWidth() const QFontMetrics bigFontMetrics(bigFont); QVERIFY(smallFontMetrics.lineWidth() >= 1); - -#ifdef Q_WS_QPA - QEXPECT_FAIL("", "QTBUG-20759 fails for qpa", Continue); -#endif - QVERIFY(smallFontMetrics.lineWidth() < bigFontMetrics.lineWidth()); } diff --git a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp index e84915428f..4db01c91a2 100644 --- a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp +++ b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp @@ -97,10 +97,6 @@ void tst_QGlyphRun::initTestCase() m_testFont = QFont("QtsSpecialTestFont"); -#ifdef Q_WS_QPA - QEXPECT_FAIL("", "QTBUG-20760 fails on qpa", Abort); -#endif - QCOMPARE(QFontInfo(m_testFont).family(), QString::fromLatin1("QtsSpecialTestFont")); m_testFont_ok = true; diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp index 1c18f2f1e8..5404b0f587 100644 --- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp @@ -111,16 +111,6 @@ Q_DECLARE_METATYPE(QFontDatabase::WritingSystem) void tst_QRawFont::init() { -#ifdef Q_WS_QPA - // Loading fonts from a QByteArray seems unimplemented for all qpa plugins at time of writing; - // almost all testfunctions fail on qpa due to this, except these few: - const QByteArray func = QTest::currentTestFunction(); - if (func != "invalidRawFont" - && func != "explicitRawFontNotAvailableInSystem" - && func != "fromFont" - && func != "textLayout") - QEXPECT_FAIL("", "QTBUG-20976 fails on qpa", Abort); -#endif } void tst_QRawFont::invalidRawFont() @@ -308,9 +298,6 @@ void tst_QRawFont::textLayout() QString familyName = QString::fromLatin1("QtBidiTestFont"); QFont font(familyName); font.setPixelSize(18.0); -#ifdef Q_WS_QPA - QEXPECT_FAIL("", "QTBUG-20976 fails on qpa", Abort); -#endif QCOMPARE(QFontInfo(font).family(), familyName); QTextLayout layout(QLatin1String("Foobar")); @@ -628,10 +615,6 @@ void tst_QRawFont::fromFont() QRawFont rawFont = QRawFont::fromFont(font, writingSystem); QVERIFY(rawFont.isValid()); -#ifdef Q_WS_QPA - QEXPECT_FAIL("", "QTBUG-20976 fails on qpa", Abort); -#endif - QCOMPARE(rawFont.familyName(), familyName); QCOMPARE(rawFont.pixelSize(), 26.0); diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp index 79cbd692ea..4bd50008db 100644 --- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp @@ -232,6 +232,7 @@ void tst_QStaticText::prepareToCorrectData() { QTransform transform; transform.scale(2.0, 2.0); + transform.translate(100, 10); transform.rotate(90, Qt::ZAxis); QPixmap imageDrawText(1000, 1000); @@ -258,10 +259,6 @@ void tst_QStaticText::prepareToCorrectData() imageDrawStaticText.save("prepareToCorrectData_imageDrawStaticText.png"); #endif -#ifdef Q_WS_QPA - QEXPECT_FAIL("", "QTBUG-20977 fails on qpa", Abort); -#endif - QVERIFY(imageDrawText.toImage() != m_whiteSquare); if (!supportsTransformations()) @@ -396,7 +393,7 @@ bool tst_QStaticText::supportsTransformations() const QPaintEngine::Type type = engine->type(); if (type == QPaintEngine::OpenGL -#if !defined(Q_WS_WIN) && !defined(Q_WS_X11) && !defined(Q_WS_MAC) +#if !defined(Q_WS_WIN) && !defined(Q_WS_X11) && !defined(Q_WS_MAC) && !defined(Q_WS_QPA) || type == QPaintEngine::Raster #endif )