diff options
author | Akira TAGOH <akira@tagoh.org> | 2023-08-15 15:26:52 +0800 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2024-01-30 14:48:17 +0100 |
commit | 185add27b2f7a4aa477e7988260bfaccb930f95c (patch) | |
tree | 2973521753385512dab742d8939fa001c36ce4a5 /src/gui/text/unix/qfontconfigdatabase.cpp | |
parent | 7edff3f15ae21c2310437e0711f84442a21cb6a1 (diff) |
Support the named instances of Variable Fonts
In the fontconfig, the fonts will be populated with the variable font
and the named instance from the variable font. In this patch, it will
skip the variable font, and populate the named instances from the variable font.
The FcFontMatch function ignores the FC_INDEX when match the font,
changed the code to match the FC_INDEX by iterate the font list.
[ChangeLog][Fonts] Added support for the named instances from the variable fonts.
Pick-to: 6.7
Fixes: QTBUG-111994
Fixes: QTBUG-112136
Co-authored-by: Peng Wu <alexepico@gmail.com>
Change-Id: Ic598d69a1e76109958fafa1226ea927656092319
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/gui/text/unix/qfontconfigdatabase.cpp')
-rw-r--r-- | src/gui/text/unix/qfontconfigdatabase.cpp | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/src/gui/text/unix/qfontconfigdatabase.cpp b/src/gui/text/unix/qfontconfigdatabase.cpp index a0b1abd14a..46e8f5724a 100644 --- a/src/gui/text/unix/qfontconfigdatabase.cpp +++ b/src/gui/text/unix/qfontconfigdatabase.cpp @@ -575,6 +575,12 @@ void QFontconfigDatabase::populateFontDatabase() FcObjectSetAdd(os, *p); ++p; } + +#ifdef FC_VARIABLE + /* Support the named instance of Variable Fonts. */ + FcPatternAddBool(pattern, FC_VARIABLE, FcFalse); +#endif + fonts = FcFontList(nullptr, pattern, os); FcObjectSetDestroy(os); FcPatternDestroy(pattern); @@ -974,6 +980,7 @@ void QFontconfigDatabase::setupFontEngine(QFontEngineFT *engine, const QFontDef QFontEngine::GlyphFormat format; // try and get the pattern FcPattern *pattern = FcPatternCreate(); + FcPattern *match = nullptr; FcValue value; value.type = FcTypeString; @@ -992,7 +999,7 @@ void QFontconfigDatabase::setupFontEngine(QFontEngineFT *engine, const QFontDef FcPatternAdd(pattern,FC_INDEX,value,true); } - if (fontDef.pixelSize > 0.1) + if (!qFuzzyIsNull(fontDef.pixelSize)) FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontDef.pixelSize); FcResult result; @@ -1000,7 +1007,55 @@ void QFontconfigDatabase::setupFontEngine(QFontEngineFT *engine, const QFontDef FcConfigSubstitute(nullptr, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); - FcPattern *match = FcFontMatch(nullptr, pattern, &result); +#ifdef FC_VARIABLE + if (!fid.filename.isEmpty()) { + // FC_INDEX is ignored during processing in FcFontMatch. + // So iterate FcPatterns directly and find it out. + FcFontSet *fcsets[2], *fcfs; + + fcsets[0] = FcConfigGetFonts(nullptr, FcSetSystem); + fcsets[1] = FcConfigGetFonts(nullptr, FcSetApplication); + for (int nset = 0; nset < 2; nset++) { + fcfs = fcsets[nset]; + if (fcfs == nullptr) + continue; + for (int fnum = 0; fnum < fcfs->nfont; fnum++) { + FcPattern *fcpat = fcfs->fonts[fnum]; + FcChar8 *fcfile; + FcBool variable; + double fcpixelsize; + int fcindex; + + // Skip the variable font itself, only to use the named instances and normal fonts here + if (FcPatternGetBool(fcpat, FC_VARIABLE, 0, &variable) == FcResultMatch && + variable == FcTrue) + continue; + + if (!qFuzzyIsNull(fontDef.pixelSize)) { + if (FcPatternGetDouble(fcpat, FC_PIXEL_SIZE, 0, &fcpixelsize) == FcResultMatch && + fontDef.pixelSize != fcpixelsize) + continue; + } + + if (FcPatternGetString(fcpat, FC_FILE, 0, &fcfile) == FcResultMatch && + FcPatternGetInteger(fcpat, FC_INDEX, 0, &fcindex) == FcResultMatch) { + QByteArray f = QByteArray::fromRawData((const char *)fcfile, + qstrlen((const char *)fcfile)); + if (f == fid.filename && fcindex == fid.index) { + // We found it. + match = FcFontRenderPrepare(nullptr, pattern, fcpat); + goto bail; + } + } + } + } + } +bail: +#endif + + if (!match) + match = FcFontMatch(nullptr, pattern, &result); + if (match) { engine->setDefaultHintStyle(defaultHintStyleFromMatch((QFont::HintingPreference)fontDef.hintingPreference, match, useXftConf)); |