From 243f4b2a8c027ae18c7ffce969c48d1f8d1b5431 Mon Sep 17 00:00:00 2001 From: "Hikaru Terazono (3c1u)" <3c1u@vulpesgames.tokyo> Date: Sat, 8 Feb 2020 22:20:21 +0900 Subject: Fix sorting of fallback fonts based on writing systems Now qt_sort_families_by_writing_system checks all writing systems for sc ript. This makes Japanese text look properly on macOS. Task-number: QTBUG-81924 Change-Id: Id2a149eb84c5992414505b079be4e707f7f8c6c7 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfontdatabase.cpp | 46 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index f2fd585835..1f9e899413 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -826,7 +826,19 @@ QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFo f->ensurePopulated(); - if (writingSystem > QFontDatabase::Any && f->writingSystems[writingSystem] != QtFontFamily::Supported) + 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) continue; for (int j = 0; j < f->count; ++j) { @@ -2857,9 +2869,10 @@ QString QFontDatabase::resolveFontFamilyAlias(const QString &family) Q_GUI_EXPORT QStringList qt_sort_families_by_writing_system(QChar::Script script, const QStringList &families) { - size_t writingSystem = std::find(scriptForWritingSystem, - scriptForWritingSystem + QFontDatabase::WritingSystemsCount, - script) - scriptForWritingSystem; + const size_t writingSystem = + std::find(scriptForWritingSystem, + scriptForWritingSystem + QFontDatabase::WritingSystemsCount, script) + - scriptForWritingSystem; if (writingSystem == QFontDatabase::Any || writingSystem >= QFontDatabase::WritingSystemsCount) { return families; @@ -2879,9 +2892,30 @@ 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 (testFamily == nullptr - || (testFamily->writingSystems[writingSystem] & QtFontFamily::Supported) == 0) { + if (!isSupported) { order |= 1u << 31; } -- cgit v1.2.3