diff options
author | jian liang <jianliang79@gmail.com> | 2012-02-04 19:53:54 +0800 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-10 00:27:44 +0100 |
commit | c6a1cb701ce1a973d9c950161d72db0e7f9a6b7c (patch) | |
tree | 6a23e945277f71fb586e6de95b3fa526201de788 /src/gui/text | |
parent | cd2a2251d1a739b5d84f2543c280cf399eba47d0 (diff) |
Improvement to font database cleanup
This patch do the following things:
1) Call QFontDatabasePrivate::free() to clean up font database before
destroying the platform integration object. This is to prevent object leak
which is allocated by platform plugin.
2) Allocate FontFile structure for each font registered in windows
platform to prevent double free of FontFile structure.
3) qt_registerFont() will release the old handle of the registered font
and replace it with the new handle. This is to prevent FontFont structure
leak.
Change-Id: Ib5ca20c695e1e365689fd8554f7caff6ee77a0b1
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 10 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase_qpa.cpp | 45 |
2 files changed, 34 insertions, 21 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index e9b7d1a1dd..be8c1c0bb1 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -196,7 +196,7 @@ struct QtFontStyle // bitfield count-- in while condition does not work correctly in mwccsym2 count--; QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration(); - if (integration) { //on shut down there will be some that we don't release. + if (integration) { integration->fontDatabase()->releaseHandle(pixelSizes[count].handle); } } @@ -796,6 +796,14 @@ static QStringList familyList(const QFontDef &req) Q_GLOBAL_STATIC(QFontDatabasePrivate, privateDb) Q_GLOBAL_STATIC_WITH_ARGS(QMutex, fontDatabaseMutex, (QMutex::Recursive)) +// used in qguiapplication.cpp +void qt_cleanupFontDatabase() +{ + QFontDatabasePrivate *db = privateDb(); + if (db) + db->free(); +} + // used in qfontengine_x11.cpp QMutex *qt_fontdatabase_mutex() { diff --git a/src/gui/text/qfontdatabase_qpa.cpp b/src/gui/text/qfontdatabase_qpa.cpp index 266ad4d453..c3d7529c2e 100644 --- a/src/gui/text/qfontdatabase_qpa.cpp +++ b/src/gui/text/qfontdatabase_qpa.cpp @@ -58,28 +58,33 @@ Q_GUI_EXPORT void qt_registerFont(const QString &familyName, const QString &fou const QSupportedWritingSystems &writingSystems, void *handle) { QFontDatabasePrivate *d = privateDb(); - // 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))) { - f->writingSystems[i] = QtFontFamily::Supported; - } else { - f->writingSystems[i] = QtFontFamily::Unsupported; - } +// 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))) { + f->writingSystems[i] = QtFontFamily::Supported; + } else { + f->writingSystems[i] = QtFontFamily::Unsupported; } + } - QtFontFoundry *foundry = f->foundry(foundryname, true); - QtFontStyle *fontStyle = foundry->style(styleKey, QString(), true); - fontStyle->smoothScalable = scalable; - fontStyle->antialiased = antialiased; - QtFontSize *size = fontStyle->pixelSize(pixelSize?pixelSize:SMOOTH_SCALABLE, true); - size->handle = handle; + QtFontFoundry *foundry = f->foundry(foundryname, true); + QtFontStyle *fontStyle = foundry->style(styleKey, QString(), true); + fontStyle->smoothScalable = scalable; + fontStyle->antialiased = antialiased; + QtFontSize *size = fontStyle->pixelSize(pixelSize ? pixelSize : SMOOTH_SCALABLE, true); + if (size->handle) { + QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration(); + if (integration) + integration->fontDatabase()->releaseHandle(size->handle); + } + size->handle = handle; } static QStringList fallbackFamilies(const QString &family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) |