From 0b87f4f6c912a508f170cd25ff5317bb77665fa9 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 25 Mar 2014 10:08:05 +0100 Subject: [PATCH] Android: Fix font merging Our fallback fonts would contain a minimal list of hardcoded fallback fonts, which is neither sufficient for displaying all text, nor portable to different vendors which can supply different font sets. [ChangeLog][Android] Fixed font merging problem which caused e.g. missing glyphs for Arabic numerals. Task-number: QTBUG-37738 Change-Id: Ic971343a1cd5610c79a81f6f6152c637937b5626 Reviewed-by: Konstantin Ritt --- src/gui/text/qfontdatabase.cpp | 2 +- .../basic/qbasicfontdatabase.cpp | 6 +++++- .../basic/qbasicfontdatabase_p.h | 2 +- .../android/qandroidplatformfontdatabase.cpp | 20 ++++++++++++++----- .../android/qandroidplatformfontdatabase.h | 3 +++ 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index ae7b6c1c0d..558258c30e 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -531,7 +531,7 @@ static const int scriptForWritingSystem[] = { Q_STATIC_ASSERT(sizeof(scriptForWritingSystem) / sizeof(scriptForWritingSystem[0]) == QFontDatabase::WritingSystemsCount); -int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem) +Q_GUI_EXPORT int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem) { return scriptForWritingSystem[writingSystem]; } diff --git a/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp b/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp index 88814151b6..26ae0eb724 100644 --- a/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp +++ b/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp @@ -220,7 +220,7 @@ void QBasicFontDatabase::releaseHandle(void *handle) extern FT_Library qt_getFreetype(); -QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByteArray &file) +QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByteArray &file, QSupportedWritingSystems *supportedWritingSystems) { FT_Library library = qt_getFreetype(); @@ -259,6 +259,8 @@ QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByt if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM || cm->encoding == FT_ENCODING_MS_SYMBOL) { writingSystems.setSupported(QFontDatabase::Symbol); + if (supportedWritingSystems) + supportedWritingSystems->setSupported(QFontDatabase::Symbol); break; } } @@ -277,6 +279,8 @@ QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByt }; writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange); + if (supportedWritingSystems) + *supportedWritingSystems = writingSystems; if (os2->usWeightClass == 0) ; diff --git a/src/platformsupport/fontdatabases/basic/qbasicfontdatabase_p.h b/src/platformsupport/fontdatabases/basic/qbasicfontdatabase_p.h index 45d7218ece..247a2855e2 100644 --- a/src/platformsupport/fontdatabases/basic/qbasicfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/basic/qbasicfontdatabase_p.h @@ -64,7 +64,7 @@ public: QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName); void releaseHandle(void *handle); - static QStringList addTTFile(const QByteArray &fontData, const QByteArray &file); + static QStringList addTTFile(const QByteArray &fontData, const QByteArray &file, QSupportedWritingSystems *supportedWritingSystems = 0); static QString fontNameFromTTFile(const QString &filename); }; diff --git a/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp b/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp index 7f68b44ed8..7423e6c55a 100644 --- a/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp +++ b/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp @@ -60,7 +60,17 @@ void QAndroidPlatformFontDatabase::populateFontDatabase() QDir dir(fontpath, QLatin1String("*.ttf")); for (int i = 0; i < int(dir.count()); ++i) { const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); - addTTFile(QByteArray(), file); + + QSupportedWritingSystems supportedWritingSystems; + QStringList families = addTTFile(QByteArray(), file, &supportedWritingSystems); + + extern int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem); + for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) { + if (i == QFontDatabase::Any || supportedWritingSystems.supported(QFontDatabase::WritingSystem(i))) { + QChar::Script script = QChar::Script(qt_script_for_writing_system(QFontDatabase::WritingSystem(i))); + m_fallbacks[script] += families; + } + } } } @@ -71,9 +81,9 @@ QStringList QAndroidPlatformFontDatabase::fallbacksForFamily(const QString &fami { Q_UNUSED(family); Q_UNUSED(style); - Q_UNUSED(script); - if (styleHint == QFont::Monospace) - return QString(qgetenv("QT_ANDROID_FONTS_MONOSPACE")).split(";"); - return QString(qgetenv("QT_ANDROID_FONTS")).split(";"); + if (styleHint == QFont::Monospace) + return QString(qgetenv("QT_ANDROID_FONTS_MONOSPACE")).split(";") + m_fallbacks[script]; + + return QString(qgetenv("QT_ANDROID_FONTS")).split(";") + m_fallbacks[script]; } diff --git a/src/plugins/platforms/android/qandroidplatformfontdatabase.h b/src/plugins/platforms/android/qandroidplatformfontdatabase.h index 3cbfe95d36..cdd3cf1674 100644 --- a/src/plugins/platforms/android/qandroidplatformfontdatabase.h +++ b/src/plugins/platforms/android/qandroidplatformfontdatabase.h @@ -53,6 +53,9 @@ public: QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const; + +private: + QHash m_fallbacks; }; #endif // QANDROIDPLATFORMFONTDATABASE_H