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/plugins | |
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/plugins')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp index f397e9cb92..8455e9e6d0 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp @@ -100,6 +100,14 @@ static inline QFont::Weight weightFromInteger(long weight) return QFont::Black; } +static FontFile * createFontFile(const QString &fileName, int index) +{ + FontFile *fontFile = new FontFile; + fontFile->fileName = fileName; + fontFile->indexValue = index; + return fontFile; +} + static bool addFontToDatabase(QString familyName, const QString &scriptName, const TEXTMETRIC *textmetric, const FONTSIGNATURE *signature, @@ -212,23 +220,22 @@ static bool addFontToDatabase(QString familyName, const QString &scriptName, if (!QDir::isAbsolutePath(value)) value.prepend(QString::fromLocal8Bit(qgetenv("windir") + "\\Fonts\\")); - // Pointer is deleted in QBasicFontDatabase::releaseHandle(void *handle) - FontFile *fontFile = new FontFile; - fontFile->fileName = value; - fontFile->indexValue = index; + QPlatformFontDatabase::registerFont(faceName, foundryName, weight, style, stretch, + antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); - QPlatformFontDatabase::registerFont(faceName, foundryName, weight, - style, stretch, antialias, scalable, size, fixed, writingSystems, fontFile); // add fonts windows can generate for us: if (weight <= QFont::DemiBold) - QPlatformFontDatabase::registerFont(faceName, foundryName, QFont::Bold, - style, stretch, antialias, scalable, size, fixed, writingSystems, fontFile); + QPlatformFontDatabase::registerFont(faceName, foundryName, QFont::Bold, style, stretch, + antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); + if (style != QFont::StyleItalic) - QPlatformFontDatabase::registerFont(faceName, foundryName, weight, - QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, fontFile); + QPlatformFontDatabase::registerFont(faceName, foundryName, weight, QFont::StyleItalic, stretch, + antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); + if (weight <= QFont::DemiBold && style != QFont::StyleItalic) - QPlatformFontDatabase::registerFont(faceName, foundryName, QFont::Bold, - QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, fontFile); + QPlatformFontDatabase::registerFont(faceName, foundryName, QFont::Bold, QFont::StyleItalic, stretch, + antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); + return true; } |