summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp')
-rw-r--r--src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp
index b1ba84fe14..9d25422ca5 100644
--- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp
+++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp
@@ -1007,12 +1007,27 @@ static QChar *createFontFile(const QString &faceName)
return faceNamePtr;
}
+namespace {
+ struct StoreFontPayload {
+ StoreFontPayload(const QString &family,
+ QWindowsFontDatabase *fontDatabase)
+ : populatedFontFamily(family)
+ , windowsFontDatabase(fontDatabase)
+ {}
+
+ QString populatedFontFamily;
+ QSet<QPair<QString,QString> > foundFontAndStyles;
+ QWindowsFontDatabase *windowsFontDatabase;
+ };
+}
+
static bool addFontToDatabase(QString familyName,
QString styleName,
const LOGFONT &logFont,
const TEXTMETRIC *textmetric,
const FONTSIGNATURE *signature,
- int type)
+ int type,
+ StoreFontPayload *sfp)
{
// the "@family" fonts are just the same as "family". Ignore them.
if (familyName.isEmpty() || familyName.at(0) == QLatin1Char('@') || familyName.startsWith(QLatin1String("WST_")))
@@ -1092,6 +1107,16 @@ static bool addFontToDatabase(QString familyName,
writingSystems.setSupported(ws);
}
+ // We came here from populating a different font family, so we have
+ // to ensure the entire typographic family is populated before we
+ // mark it as such inside registerFont()
+ if (!subFamilyName.isEmpty()
+ && familyName != subFamilyName
+ && sfp->populatedFontFamily != familyName
+ && !QPlatformFontDatabase::isFamilyPopulated(familyName)) {
+ sfp->windowsFontDatabase->populateFamily(familyName);
+ }
+
QPlatformFontDatabase::registerFont(familyName, styleName, foundryName, weight,
style, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(faceName));
@@ -1118,7 +1143,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,9 +1153,18 @@ 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)
+ StoreFontPayload *sfp = reinterpret_cast<StoreFontPayload *>(lparam);
+ Q_ASSERT(sfp != nullptr);
+ if (type & TRUETYPE_FONTTYPE) {
signature = &reinterpret_cast<const NEWTEXTMETRICEX *>(textmetric)->ntmFontSig;
- addFontToDatabase(familyName, styleName, *logFont, textmetric, signature, type);
+ // 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);
+ if (sfp->foundFontAndStyles.contains(fontAndStyle))
+ return 1;
+ sfp->foundFontAndStyles.insert(fontAndStyle);
+ }
+ addFontToDatabase(familyName, styleName, *logFont, textmetric, signature, type, sfp);
// keep on enumerating
return 1;
@@ -1149,7 +1183,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);
+ StoreFontPayload sfp(familyName, this);
+ EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast<intptr_t>(&sfp), 0);
ReleaseDC(0, dummy);
}
@@ -1589,8 +1624,9 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData,
TEXTMETRIC textMetrics;
GetTextMetrics(hdc, &textMetrics);
+ StoreFontPayload sfp(familyName, this);
addFontToDatabase(familyName, styleName, lf, &textMetrics, &signatures.at(j),
- TRUETYPE_FONTTYPE);
+ TRUETYPE_FONTTYPE, &sfp);
SelectObject(hdc, oldobj);
DeleteObject(hfont);