From 181bece09afef4e6c3b47e1d246eb7e3ba56d84f Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Wed, 12 Feb 2020 06:50:11 +0300 Subject: Fix sorting of fallback fonts based on writing systems This rewrites 243f4b2a8c027ae18c7ffce969c48d1f8d1b5431 in a more complete and optimized manner Task-number: QTBUG-81924 Change-Id: I52105a9ede07ce350fad3d50277dd631df371f06 Reviewed-by: Hikaru Terazono (3c1u) <3c1u@vulpesgames.tokyo> Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfontdatabase.cpp | 67 ++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 1f9e899413..29f56f5c85 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -597,6 +597,25 @@ Q_GUI_EXPORT int qt_script_for_writing_system(QFontDatabase::WritingSystem writi } +/*! + \internal + + Tests if the given family \a family supports writing system \a writingSystem, + including the special case for Han script mapping to several subsequent writing systems +*/ +static bool familySupportsWritingSystem(QtFontFamily *family, size_t writingSystem) +{ + Q_ASSERT(family != nullptr); + Q_ASSERT(writingSystem != QFontDatabase::Any && writingSystem < QFontDatabase::WritingSystemsCount); + + size_t ws = writingSystem; + do { + if ((family->writingSystems[ws] & QtFontFamily::Supported) != 0) + return true; + } while (writingSystem >= QFontDatabase::SimplifiedChinese && writingSystem <= QFontDatabase::Japanese && ++ws <= QFontDatabase::Japanese); + + return false; +} /*! @@ -826,19 +845,7 @@ QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFo f->ensurePopulated(); - size_t otherWritingSystem = writingSystem; - - while (writingSystem > QFontDatabase::Any && f->writingSystems[otherWritingSystem] != QtFontFamily::Supported) { - otherWritingSystem = std::find(scriptForWritingSystem + (otherWritingSystem + 1), - scriptForWritingSystem + QFontDatabase::WritingSystemsCount, - script) - scriptForWritingSystem; - - if (otherWritingSystem >= QFontDatabase::WritingSystemsCount) { - break; - } - } - - if (otherWritingSystem >= QFontDatabase::WritingSystemsCount) + if (writingSystem != QFontDatabase::Any && !familySupportsWritingSystem(f, writingSystem)) continue; for (int j = 0; j < f->count; ++j) { @@ -1283,7 +1290,7 @@ static int match(int script, const QFontDef &request, test.family->ensurePopulated(); // Check if family is supported in the script we want - if (writingSystem != QFontDatabase::Any && !(test.family->writingSystems[writingSystem] & QtFontFamily::Supported)) + if (writingSystem != QFontDatabase::Any && !familySupportsWritingSystem(test.family, writingSystem)) continue; // as we know the script is supported, we can be sure @@ -2869,10 +2876,9 @@ QString QFontDatabase::resolveFontFamilyAlias(const QString &family) Q_GUI_EXPORT QStringList qt_sort_families_by_writing_system(QChar::Script script, const QStringList &families) { - const size_t writingSystem = - std::find(scriptForWritingSystem, - scriptForWritingSystem + QFontDatabase::WritingSystemsCount, script) - - scriptForWritingSystem; + size_t writingSystem = std::find(scriptForWritingSystem, + scriptForWritingSystem + QFontDatabase::WritingSystemsCount, + script) - scriptForWritingSystem; if (writingSystem == QFontDatabase::Any || writingSystem >= QFontDatabase::WritingSystemsCount) { return families; @@ -2892,30 +2898,9 @@ Q_GUI_EXPORT QStringList qt_sort_families_by_writing_system(QChar::Script script } } - bool isSupported = false; - - if (testFamily != nullptr) { - isSupported = testFamily->writingSystems[writingSystem] & QtFontFamily::Supported; - auto otherWritingSystem = writingSystem; - - // test other writing systems - while (!isSupported) { - otherWritingSystem = - std::find(&scriptForWritingSystem[otherWritingSystem + 1], - scriptForWritingSystem + QFontDatabase::WritingSystemsCount, - script) - - scriptForWritingSystem; - - if (otherWritingSystem >= QFontDatabase::WritingSystemsCount) - break; - - isSupported |= - testFamily->writingSystems[otherWritingSystem] & QtFontFamily::Supported; - } - } - uint order = i; - if (!isSupported) { + if (testFamily == nullptr + || !familySupportsWritingSystem(testFamily, writingSystem)) { order |= 1u << 31; } -- cgit v1.2.3