Register font's english name as alias when populating font database

Register font's english name as alias in the callback of
EnumFontFamiliesEx() at the time
QWindowsFontDatabase::populateFontDatabase() is being called. This will
help us to resolve english font family name to its corresponding localized
alias once windows font database has been populated. It will also fix an
assertion in Chinese Windows.

Task-number: QTBUG-44647
Change-Id: I265d93c16a1677a7f31ff56d60c24f6e90666419
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
Liang Jian 2015-02-25 15:47:07 +08:00 committed by jian liang
parent e78643dc0a
commit 5f2f38854f

View File

@ -850,7 +850,8 @@ error:
static bool addFontToDatabase(const QString &familyName, uchar charSet,
const TEXTMETRIC *textmetric,
const FONTSIGNATURE *signature,
int type)
int type,
bool registerAlias)
{
// the "@family" fonts are just the same as "family". Ignore them.
if (familyName.isEmpty() || familyName.at(0) == QLatin1Char('@') || familyName.startsWith(QLatin1String("WST_")))
@ -887,7 +888,7 @@ static bool addFontToDatabase(const QString &familyName, uchar charSet,
#endif
QString englishName;
if (ttf && localizedName(familyName))
if (registerAlias && ttf && localizedName(familyName))
englishName = getEnglishName(familyName);
QSupportedWritingSystems writingSystems;
@ -956,7 +957,7 @@ static int QT_WIN_CALLBACK storeFont(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *textmetr
// NEWTEXTMETRICEX is a NEWTEXTMETRIC, which according to the documentation is
// identical to a TEXTMETRIC except for the last four members, which we don't use
// anyway
addFontToDatabase(familyName, charSet, (TEXTMETRIC *)textmetric, &signature, type);
addFontToDatabase(familyName, charSet, (TEXTMETRIC *)textmetric, &signature, type, false);
// keep on enumerating
return 1;
@ -991,7 +992,7 @@ struct PopulateFamiliesContext
};
} // namespace
static int QT_WIN_CALLBACK populateFontFamilies(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *, int, LPARAM lparam)
static int QT_WIN_CALLBACK populateFontFamilies(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *tm, int, LPARAM lparam)
{
// the "@family" fonts are just the same as "family". Ignore them.
const wchar_t *faceNameW = f->elfLogFont.lfFaceName;
@ -1001,6 +1002,19 @@ static int QT_WIN_CALLBACK populateFontFamilies(ENUMLOGFONTEX* f, NEWTEXTMETRICE
PopulateFamiliesContext *context = reinterpret_cast<PopulateFamiliesContext *>(lparam);
if (!context->seenSystemDefaultFont && faceName == context->systemDefaultFont)
context->seenSystemDefaultFont = true;
// Register current font's english name as alias
const bool ttf = (tm->ntmTm.tmPitchAndFamily & TMPF_TRUETYPE);
if (ttf && localizedName(faceName)) {
const QString englishName = getEnglishName(faceName);
if (!englishName.isEmpty()) {
QPlatformFontDatabase::registerAliasToFontFamily(faceName, englishName);
// Check whether the system default font name is an alias of the current font family name,
// as on Chinese Windows, where the system font "SimSun" is an alias to a font registered under a local name
if (!context->seenSystemDefaultFont && englishName == context->systemDefaultFont)
context->seenSystemDefaultFont = true;
}
}
}
return 1; // continue
}
@ -1358,7 +1372,7 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData,
GetTextMetrics(hdc, &textMetrics);
addFontToDatabase(familyName, lf.lfCharSet, &textMetrics, &signatures.at(j),
TRUETYPE_FONTTYPE);
TRUETYPE_FONTTYPE, true);
SelectObject(hdc, oldobj);
DeleteObject(hfont);