Fix QFontconfigDatabase unable to fallback to a localized family

When populating the font database, FcPatternGetString(FC_FAMILY) gets
a localized font family name; but, in fallbacksForFamily, it gets
a non-localized font family name, so it unable to find the proper font to fallback.
Simply register all family name variants as aliases to localized name
and make sure they are checked when getting fallback families.

Task-number: QTBUG-28806
Task-number: QTBUG-30415

Change-Id: I71c03ae9b51a28736c2576f3442f1bbdb3497c09
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: jian liang <jianliang79@gmail.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
Konstantin Ritt 2013-04-05 16:20:15 +03:00 committed by The Qt Project
parent aeaab5210f
commit 9f7bc42b7d
3 changed files with 13 additions and 15 deletions

View File

@ -344,6 +344,7 @@ struct QtFontFamily
bool askedForFallback;
unsigned char writingSystems[QFontDatabase::WritingSystemsCount];
bool matchesFamilyName(const QString &familyName) const;
QtFontFoundry *foundry(const QString &f, bool = false);
};
@ -383,6 +384,11 @@ QtFontFoundry *QtFontFamily::foundry(const QString &f, bool create)
return foundries[count++];
}
bool QtFontFamily::matchesFamilyName(const QString &familyName) const
{
return name.compare(familyName, Qt::CaseInsensitive) == 0 || aliases.contains(familyName, Qt::CaseInsensitive);
}
class QFontDatabasePrivate
{
@ -852,19 +858,7 @@ static bool matchFamilyName(const QString &familyName, QtFontFamily *f)
{
if (familyName.isEmpty())
return true;
if (f->name.compare(familyName, Qt::CaseInsensitive) == 0)
return true;
QStringList::const_iterator it = f->aliases.constBegin();
while (it != f->aliases.constEnd()) {
if ((*it).compare(familyName, Qt::CaseInsensitive) == 0)
return true;
++it;
}
return false;
return f->matchesFamilyName(familyName);
}
/*!

View File

@ -110,8 +110,7 @@ static QStringList fallbackFamilies(const QString &family, QFont::Style style, Q
for (i = retList.begin(); i != retList.end(); ++i) {
bool contains = false;
for (int j = 0; j < db->count; j++) {
QtFontFamily *qtFamily = db->families[j];
if (!(i->compare(qtFamily->name,Qt::CaseInsensitive))) {
if (db->families[j]->matchesFamilyName(*i)) {
contains = true;
break;
}

View File

@ -370,6 +370,8 @@ static bool isSymbolFont(FontFile *fontFile)
return hasSymbolMap;
}
Q_GUI_EXPORT void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias);
void QFontconfigDatabase::populateFontDatabase()
{
FcFontSet *fonts;
@ -511,6 +513,9 @@ void QFontconfigDatabase::populateFontDatabase()
QString styleName = style_value ? QString::fromUtf8((const char *) style_value) : QString();
QPlatformFontDatabase::registerFont(familyName,styleName,QLatin1String((const char *)foundry_value),weight,style,stretch,antialias,scalable,pixel_size,fixedPitch,writingSystems,fontFile);
// qDebug() << familyName << (const char *)foundry_value << weight << style << &writingSystems << scalable << true << pixel_size;
for (int k = 1; FcPatternGetString(fonts->fonts[i], FC_FAMILY, k, &value) == FcResultMatch; ++k)
qt_registerAliasToFontFamily(familyName, QString::fromUtf8((const char *)value));
}
FcFontSetDestroy (fonts);