diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-10-11 12:25:03 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-11-22 10:58:24 +0100 |
commit | 1e763219a8d7309ffb13f3fb1d19505a0239b8af (patch) | |
tree | 19e16c8ac7bdd51402f5a3a3c72b5654f81ba117 | |
parent | d4ddd6bcca25122f379477bf5e6322f05dae903f (diff) | |
download | qtbase-1e763219a8d7309ffb13f3fb1d19505a0239b8af.tar.gz |
freetype/no-fc: Disambiguate fonts with different widths
When using the Freetype font database, we would ignore the
typographical width of loaded fonts, which could make it
impossible to select certain fonts in a family.
Also contains 518790af79df339143820cd9d34a74c00db1ed7e and
cde562cf6d65a3ad64fa6afd6014be74febdf912 squashed in.
[ChangeLog][Freetype] Fixed a bug where fonts of different
width within the same family would be unselectable if the
Freetype font database (no-fontconfig configuration) was in
use.
Fixes: QTBUG-89640
Change-Id: Ic9c17a7c3cc14eb7e942b05d6b21b7c1602816cf
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit e05e3c776256d35798f451f31cd71e809786ed78)
(cherry picked from commit 518790af79df339143820cd9d34a74c00db1ed7e)
(cherry picked from commit cde562cf6d65a3ad64fa6afd6014be74febdf912)
-rw-r--r-- | src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp | 32 | ||||
-rw-r--r-- | tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp | 8 |
2 files changed, 38 insertions, 2 deletions
diff --git a/src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp b/src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp index 842984709e..c71aaaf4e9 100644 --- a/src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp +++ b/src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp @@ -153,6 +153,7 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q } } + QFont::Stretch stretch = QFont::Unstretched; TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); if (os2) { quint32 unicodeRange[4] = { @@ -191,6 +192,36 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q else if (w <= 10) weight = QFont::Black; } + + switch (os2->usWidthClass) { + case 1: + stretch = QFont::UltraCondensed; + break; + case 2: + stretch = QFont::ExtraCondensed; + break; + case 3: + stretch = QFont::Condensed; + break; + case 4: + stretch = QFont::SemiCondensed; + break; + case 5: + stretch = QFont::Unstretched; + break; + case 6: + stretch = QFont::SemiExpanded; + break; + case 7: + stretch = QFont::Expanded; + break; + case 8: + stretch = QFont::ExtraExpanded; + break; + case 9: + stretch = QFont::UltraExpanded; + break; + } } QString family = QString::fromLatin1(face->family_name); @@ -198,7 +229,6 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q fontFile->fileName = QFile::decodeName(file); fontFile->indexValue = index; - QFont::Stretch stretch = QFont::Unstretched; registerFont(family,QString::fromLatin1(face->style_name),QString(),weight,style,stretch,true,true,0,fixedPitch,writingSystems,fontFile); diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index edbb090e42..15e0ecadaa 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -33,6 +33,8 @@ #include <qfontmetrics.h> #include <qtextlayout.h> #include <private/qrawfont_p.h> +#include <private/qfont_p.h> +#include <private/qfontengine_p.h> #include <qpa/qplatformfontdatabase.h> Q_LOGGING_CATEGORY(lcTests, "qt.text.tests") @@ -411,7 +413,11 @@ void tst_QFontDatabase::condensedFontMatching() tfcByStyleName.setStyleName("Condensed"); #ifdef Q_OS_WIN - QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue); + QFont f; + f.setStyleStrategy(QFont::NoFontMerging); + QFontPrivate *font_d = QFontPrivate::get(f); + if (font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::Freetype) + QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue); #endif #ifdef Q_OS_ANDROID |