QWindowsFontDatabase: port local QSets to QDuplicateTracker
Apart from a more fitting, minimal, API, QDuplicateTracker also transparently uses C++17 pmr::monotonic_buffer_resource to avoid, or at least reduce, memory allocations. Change-Id: I155f5518190c5f8f6d21fbec3fcecd6bcc7ff852 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
0edda211f9
commit
09fba5cf36
@ -51,6 +51,7 @@
|
|||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QtEndian>
|
#include <QtCore/QtEndian>
|
||||||
|
#include <QtCore/private/qduplicatetracker_p.h>
|
||||||
#include <QtCore/private/qsystemlibrary_p.h>
|
#include <QtCore/private/qsystemlibrary_p.h>
|
||||||
#include <QtCore/private/qwinregistry_p.h>
|
#include <QtCore/private/qwinregistry_p.h>
|
||||||
|
|
||||||
@ -499,7 +500,7 @@ namespace {
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
QString populatedFontFamily;
|
QString populatedFontFamily;
|
||||||
QSet<FontAndStyle> foundFontAndStyles;
|
QDuplicateTracker<FontAndStyle> foundFontAndStyles;
|
||||||
QWindowsFontDatabase *windowsFontDatabase;
|
QWindowsFontDatabase *windowsFontDatabase;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -642,10 +643,8 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t
|
|||||||
signature = &reinterpret_cast<const NEWTEXTMETRICEX *>(textmetric)->ntmFontSig;
|
signature = &reinterpret_cast<const NEWTEXTMETRICEX *>(textmetric)->ntmFontSig;
|
||||||
// We get a callback for each script-type supported, but we register them all
|
// We get a callback for each script-type supported, but we register them all
|
||||||
// at once using the signature, so we only need one call to addFontToDatabase().
|
// at once using the signature, so we only need one call to addFontToDatabase().
|
||||||
FontAndStyle fontAndStyle = {familyName, styleName};
|
if (sfp->foundFontAndStyles.hasSeen({familyName, styleName}))
|
||||||
if (sfp->foundFontAndStyles.contains(fontAndStyle))
|
|
||||||
return 1;
|
return 1;
|
||||||
sfp->foundFontAndStyles.insert(fontAndStyle);
|
|
||||||
}
|
}
|
||||||
addFontToDatabase(familyName, styleName, *logFont, textmetric, signature, type, sfp);
|
addFontToDatabase(familyName, styleName, *logFont, textmetric, signature, type, sfp);
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@
|
|||||||
#if QT_CONFIG(regularexpression)
|
#if QT_CONFIG(regularexpression)
|
||||||
#include <QtCore/QRegularExpression>
|
#include <QtCore/QRegularExpression>
|
||||||
#endif
|
#endif
|
||||||
|
#include <QtCore/private/qduplicatetracker_p.h>
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QFontDatabase>
|
#include <QtGui/QFontDatabase>
|
||||||
|
|
||||||
@ -318,11 +320,9 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t
|
|||||||
signature = &reinterpret_cast<const NEWTEXTMETRICEX *>(textmetric)->ntmFontSig;
|
signature = &reinterpret_cast<const NEWTEXTMETRICEX *>(textmetric)->ntmFontSig;
|
||||||
// We get a callback for each script-type supported, but we register them all
|
// We get a callback for each script-type supported, but we register them all
|
||||||
// at once using the signature, so we only need one call to addFontToDatabase().
|
// at once using the signature, so we only need one call to addFontToDatabase().
|
||||||
QSet<FontAndStyle> *foundFontAndStyles = reinterpret_cast<QSet<FontAndStyle> *>(lparam);
|
auto foundFontAndStyles = reinterpret_cast<QDuplicateTracker<FontAndStyle> *>(lparam);
|
||||||
FontAndStyle fontAndStyle = {faceName, styleName};
|
if (foundFontAndStyles->hasSeen({faceName, styleName}))
|
||||||
if (foundFontAndStyles->contains(fontAndStyle))
|
|
||||||
return 1;
|
return 1;
|
||||||
foundFontAndStyles->insert(fontAndStyle);
|
|
||||||
}
|
}
|
||||||
addFontToDatabase(faceName, styleName, fullName, *logFont, textmetric, signature, type);
|
addFontToDatabase(faceName, styleName, fullName, *logFont, textmetric, signature, type);
|
||||||
|
|
||||||
@ -352,7 +352,7 @@ void QWindowsFontDatabaseFT::populateFamily(const QString &familyName)
|
|||||||
lf.lfFaceName[familyName.size()] = 0;
|
lf.lfFaceName[familyName.size()] = 0;
|
||||||
lf.lfCharSet = DEFAULT_CHARSET;
|
lf.lfCharSet = DEFAULT_CHARSET;
|
||||||
lf.lfPitchAndFamily = 0;
|
lf.lfPitchAndFamily = 0;
|
||||||
QSet<FontAndStyle> foundFontAndStyles;
|
QDuplicateTracker<FontAndStyle> foundFontAndStyles;
|
||||||
EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast<intptr_t>(&foundFontAndStyles), 0);
|
EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast<intptr_t>(&foundFontAndStyles), 0);
|
||||||
ReleaseDC(0, dummy);
|
ReleaseDC(0, dummy);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user