mirror of https://github.com/qt/qtbase.git
QWindowsFontDatabase: replace a QPair with a dedicated struct
Pairs are easy to use, but they have no semantics attached: Two QPair<QString, QString> compare equal, e.g., even though one is used as a FontAndStyle and the other as, say, a type/subtype. It also carries no information for the reader of the code. So, write a minimal struct with equality and qHash() instead. Change-Id: I9514c9b7d6c2cc6a4831f9ca83ca2ee466d91553 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
e0fc998e87
commit
bd465695c3
|
@ -496,7 +496,7 @@ namespace {
|
|||
{}
|
||||
|
||||
QString populatedFontFamily;
|
||||
QSet<QPair<QString,QString> > foundFontAndStyles;
|
||||
QSet<FontAndStyle> foundFontAndStyles;
|
||||
QWindowsFontDatabase *windowsFontDatabase;
|
||||
};
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t
|
|||
signature = &reinterpret_cast<const NEWTEXTMETRICEX *>(textmetric)->ntmFontSig;
|
||||
// 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().
|
||||
QPair<QString,QString> fontAndStyle(familyName, styleName);
|
||||
FontAndStyle fontAndStyle = {familyName, styleName};
|
||||
if (sfp->foundFontAndStyles.contains(fontAndStyle))
|
||||
return 1;
|
||||
sfp->foundFontAndStyles.insert(fontAndStyle);
|
||||
|
|
|
@ -318,8 +318,8 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t
|
|||
signature = &reinterpret_cast<const NEWTEXTMETRICEX *>(textmetric)->ntmFontSig;
|
||||
// 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().
|
||||
QSet<QPair<QString,QString>> *foundFontAndStyles = reinterpret_cast<QSet<QPair<QString,QString>> *>(lparam);
|
||||
QPair<QString,QString> fontAndStyle(faceName, styleName);
|
||||
QSet<FontAndStyle> *foundFontAndStyles = reinterpret_cast<QSet<FontAndStyle> *>(lparam);
|
||||
FontAndStyle fontAndStyle = {faceName, styleName};
|
||||
if (foundFontAndStyles->contains(fontAndStyle))
|
||||
return 1;
|
||||
foundFontAndStyles->insert(fontAndStyle);
|
||||
|
@ -352,7 +352,7 @@ void QWindowsFontDatabaseFT::populateFamily(const QString &familyName)
|
|||
lf.lfFaceName[familyName.size()] = 0;
|
||||
lf.lfCharSet = DEFAULT_CHARSET;
|
||||
lf.lfPitchAndFamily = 0;
|
||||
QSet<QPair<QString,QString>> foundFontAndStyles;
|
||||
QSet<FontAndStyle> foundFontAndStyles;
|
||||
EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast<intptr_t>(&foundFontAndStyles), 0);
|
||||
ReleaseDC(0, dummy);
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include <qpa/qplatformfontdatabase.h>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QLoggingCategory>
|
||||
#include <QtCore/qhashfunctions.h>
|
||||
#include <QtCore/qt_windows.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -154,6 +155,20 @@ bool qt_localizedName(const QString &name);
|
|||
QString qt_getEnglishName(const QString &familyName, bool includeStyle = false);
|
||||
QFontNames qt_getCanonicalFontNames(const LOGFONT &lf);
|
||||
|
||||
struct FontAndStyle {
|
||||
QString font;
|
||||
QString style;
|
||||
|
||||
friend inline bool operator==(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
|
||||
{ return lhs.font == rhs.font && lhs.style == rhs.style; }
|
||||
friend inline bool operator!=(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
|
||||
{ return !operator==(lhs, rhs); }
|
||||
};
|
||||
inline size_t qHash(const FontAndStyle &key, size_t seed) noexcept
|
||||
{
|
||||
return qHashMulti(seed, key.font, key.style);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSFONTDATABASE_H
|
||||
|
|
Loading…
Reference in New Issue