Only call addFontToDatabase once per family,style
We get a call to storeFont for each supported script-type of a font, but we use the font signature to register all the supported types at once, and can thus save ~3/4 calls to addFontToDatabase. Change-Id: I9d06252fb7f805e7babac58d82fa412ec4e0e36a Fixes: QTBUG-59360 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>bb10
parent
ff447717a2
commit
835c3e94f6
|
|
@ -1118,7 +1118,7 @@ static bool addFontToDatabase(QString familyName,
|
|||
}
|
||||
|
||||
static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *textmetric,
|
||||
DWORD type, LPARAM)
|
||||
DWORD type, LPARAM lparam)
|
||||
{
|
||||
const ENUMLOGFONTEX *f = reinterpret_cast<const ENUMLOGFONTEX *>(logFont);
|
||||
const QString familyName = QString::fromWCharArray(f->elfLogFont.lfFaceName);
|
||||
|
|
@ -1128,8 +1128,16 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t
|
|||
// to the documentation is identical to a TEXTMETRIC except for the last four
|
||||
// members, which we don't use anyway
|
||||
const FONTSIGNATURE *signature = nullptr;
|
||||
if (type & TRUETYPE_FONTTYPE)
|
||||
if (type & TRUETYPE_FONTTYPE) {
|
||||
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(familyName, styleName);
|
||||
if (foundFontAndStyles->contains(fontAndStyle))
|
||||
return 1;
|
||||
foundFontAndStyles->insert(fontAndStyle);
|
||||
}
|
||||
addFontToDatabase(familyName, styleName, *logFont, textmetric, signature, type);
|
||||
|
||||
// keep on enumerating
|
||||
|
|
@ -1149,7 +1157,8 @@ void QWindowsFontDatabase::populateFamily(const QString &familyName)
|
|||
familyName.toWCharArray(lf.lfFaceName);
|
||||
lf.lfFaceName[familyName.size()] = 0;
|
||||
lf.lfPitchAndFamily = 0;
|
||||
EnumFontFamiliesEx(dummy, &lf, storeFont, 0, 0);
|
||||
QSet<QPair<QString,QString>> foundFontAndStyles;
|
||||
EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast<intptr_t>(&foundFontAndStyles), 0);
|
||||
ReleaseDC(0, dummy);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ static bool addFontToDatabase(QString familyName,
|
|||
}
|
||||
|
||||
static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *textmetric,
|
||||
DWORD type, LPARAM)
|
||||
DWORD type, LPARAM lparam)
|
||||
{
|
||||
const ENUMLOGFONTEX *f = reinterpret_cast<const ENUMLOGFONTEX *>(logFont);
|
||||
const QString faceName = QString::fromWCharArray(f->elfLogFont.lfFaceName);
|
||||
|
|
@ -314,8 +314,16 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t
|
|||
// to the documentation is identical to a TEXTMETRIC except for the last four
|
||||
// members, which we don't use anyway
|
||||
const FONTSIGNATURE *signature = nullptr;
|
||||
if (type & TRUETYPE_FONTTYPE)
|
||||
if (type & TRUETYPE_FONTTYPE) {
|
||||
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);
|
||||
if (foundFontAndStyles->contains(fontAndStyle))
|
||||
return 1;
|
||||
foundFontAndStyles->insert(fontAndStyle);
|
||||
}
|
||||
addFontToDatabase(faceName, styleName, fullName, *logFont, textmetric, signature, type);
|
||||
|
||||
// keep on enumerating
|
||||
|
|
@ -344,7 +352,8 @@ void QWindowsFontDatabaseFT::populateFamily(const QString &familyName)
|
|||
lf.lfFaceName[familyName.size()] = 0;
|
||||
lf.lfCharSet = DEFAULT_CHARSET;
|
||||
lf.lfPitchAndFamily = 0;
|
||||
EnumFontFamiliesEx(dummy, &lf, storeFont, 0, 0);
|
||||
QSet<QPair<QString,QString>> foundFontAndStyles;
|
||||
EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast<intptr_t>(&foundFontAndStyles), 0);
|
||||
ReleaseDC(0, dummy);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue