Fix fallbacks for adapted common script
When the platform plugin gives us specific fallbacks for a specific script, we need to respect this, and load the correct font family regardless of which writing systems it supports. This is especially important since the common script is adapted to match surrounding, proper scripts, so characters such as digits next to e.g. Hebrew text will be marked as Hebrew. On stock Android, there is a single Hebrew font, and this would previously be put in all fallback slots for Hebrew regardless of what fallback fonts were dictated by the platform plugin. Since this font does not support the digits, they would show up as boxes. [ChangeLog][Android] Fixed common characters like digits and punctuation showing as boxes when positioned next to non-latin scripts. Task-number: QTBUG-39377 Change-Id: I1555e208a8ddc587c0bbdbfff1600cafdd9442e9 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>bb10
parent
916c9d469b
commit
1dd9a0af4f
|
|
@ -596,7 +596,7 @@ struct QtFontDesc
|
|||
|
||||
static int match(int script, const QFontDef &request,
|
||||
const QString &family_name, const QString &foundry_name, int force_encoding_id,
|
||||
QtFontDesc *desc, const QList<int> &blacklisted);
|
||||
QtFontDesc *desc, const QList<int> &blacklisted, bool fallback);
|
||||
|
||||
static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDef *fontDef, bool multi)
|
||||
{
|
||||
|
|
@ -1079,7 +1079,7 @@ static bool matchFamilyName(const QString &familyName, QtFontFamily *f)
|
|||
*/
|
||||
static int match(int script, const QFontDef &request,
|
||||
const QString &family_name, const QString &foundry_name, int force_encoding_id,
|
||||
QtFontDesc *desc, const QList<int> &blacklistedFamilies)
|
||||
QtFontDesc *desc, const QList<int> &blacklistedFamilies, bool fallback = false)
|
||||
{
|
||||
Q_UNUSED(force_encoding_id);
|
||||
int result = -1;
|
||||
|
|
@ -1132,7 +1132,7 @@ static int match(int script, const QFontDef &request,
|
|||
load(test.family->name, script);
|
||||
|
||||
// Check if family is supported in the script we want
|
||||
if (script != QChar::Script_Common && !(test.family->writingSystems[writingSystem] & QtFontFamily::Supported))
|
||||
if (!fallback && script != QChar::Script_Common && !(test.family->writingSystems[writingSystem] & QtFontFamily::Supported))
|
||||
continue;
|
||||
|
||||
// as we know the script is supported, we can be sure
|
||||
|
|
@ -2450,7 +2450,7 @@ bool QFontDatabase::supportsThreadedFontRendering()
|
|||
*/
|
||||
QFontEngine *
|
||||
QFontDatabase::findFont(int script, const QFontPrivate *fp,
|
||||
const QFontDef &request, bool multi)
|
||||
const QFontDef &request, bool multi, bool fallback)
|
||||
{
|
||||
QMutexLocker locker(fontDatabaseMutex());
|
||||
|
||||
|
|
@ -2478,7 +2478,7 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
|
|||
|
||||
QtFontDesc desc;
|
||||
QList<int> blackListed;
|
||||
int index = match(script, request, family_name, foundry_name, force_encoding_id, &desc, blackListed);
|
||||
int index = match(script, request, family_name, foundry_name, force_encoding_id, &desc, blackListed, fallback);
|
||||
if (index >= 0) {
|
||||
engine = loadEngine(script, request, desc.family, desc.foundry, desc.style, desc.size);
|
||||
if (!engine)
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ private:
|
|||
static void createDatabase();
|
||||
static void parseFontName(const QString &name, QString &foundry, QString &family);
|
||||
static QString resolveFontFamilyAlias(const QString &family);
|
||||
static QFontEngine *findFont(int script, const QFontPrivate *fp, const QFontDef &request, bool multi = false);
|
||||
static QFontEngine *findFont(int script, const QFontPrivate *fp, const QFontDef &request, bool multi = false, bool fallback = false);
|
||||
static void load(const QFontPrivate *d, int script);
|
||||
|
||||
friend struct QFontDef;
|
||||
|
|
|
|||
|
|
@ -663,7 +663,7 @@ void QFontEngineMultiQPA::loadEngine(int at)
|
|||
request.family = fallbackFamilies.at(at-1);
|
||||
engines[at] = QFontDatabase::findFont(script,
|
||||
/*fontprivate = */0,
|
||||
request, /*multi = */false);
|
||||
request, /*multi = */false, true);
|
||||
Q_ASSERT(engines[at]);
|
||||
engines[at]->ref.ref();
|
||||
engines[at]->fontDef = request;
|
||||
|
|
|
|||
|
|
@ -9,3 +9,8 @@ wince* {
|
|||
additionalFiles.path = .
|
||||
DEPLOYMENT += additionalFiles
|
||||
}
|
||||
|
||||
android {
|
||||
RESOURCES += testdata.qrc
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>LED_REAL.TTF</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
@ -44,6 +44,8 @@
|
|||
#include <qfontdatabase.h>
|
||||
#include <qfontinfo.h>
|
||||
#include <qfontmetrics.h>
|
||||
#include <qtextlayout.h>
|
||||
#include <private/qrawfont_p.h>
|
||||
#include <qpa/qplatformfontdatabase.h>
|
||||
|
||||
class tst_QFontDatabase : public QObject
|
||||
|
|
@ -77,6 +79,7 @@ private slots:
|
|||
void addAppFont();
|
||||
|
||||
void aliases();
|
||||
void fallbackFonts();
|
||||
|
||||
private:
|
||||
const QString m_testFont;
|
||||
|
|
@ -285,5 +288,26 @@ void tst_QFontDatabase::aliases()
|
|||
QVERIFY(db.hasFamily(alias));
|
||||
}
|
||||
|
||||
void tst_QFontDatabase::fallbackFonts()
|
||||
{
|
||||
QTextLayout layout;
|
||||
QString s;
|
||||
s.append(QChar(0x31));
|
||||
s.append(QChar(0x05D0));
|
||||
layout.setText(s);
|
||||
layout.beginLayout();
|
||||
layout.createLine();
|
||||
layout.endLayout();
|
||||
|
||||
QList<QGlyphRun> runs = layout.glyphRuns(0, 1);
|
||||
foreach (QGlyphRun run, runs) {
|
||||
QRawFont rawFont = run.rawFont();
|
||||
QVERIFY(rawFont.isValid());
|
||||
|
||||
QCOMPARE(run.glyphIndexes().size(), 1);
|
||||
QVERIFY(run.glyphIndexes().at(0) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QFontDatabase)
|
||||
#include "tst_qfontdatabase.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue