diff options
author | Hikaru Terazono (3c1u) <3c1u@vulpesgames.tokyo> | 2020-02-08 22:20:21 +0900 |
---|---|---|
committer | Hikaru Terazono (3c1u) <3c1u@vulpesgames.tokyo> | 2020-02-12 02:36:25 +0900 |
commit | 243f4b2a8c027ae18c7ffce969c48d1f8d1b5431 (patch) | |
tree | 617c55cf331addf8bfad8b8cbdb063f43fc4f2c0 /src/gui | |
parent | f9802b2fb126fe018c6ba595e35d800ae8409e1c (diff) |
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 <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 46 |
1 files changed, 40 insertions, 6 deletions
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; } |