From e05e3c776256d35798f451f31cd71e809786ed78 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 11 Oct 2021 12:25:03 +0200 Subject: 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. [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. Pick-to: 5.15 6.2 Fixes: QTBUG-89640 Change-Id: Ic9c17a7c3cc14eb7e942b05d6b21b7c1602816cf Reviewed-by: Lars Knoll Reviewed-by: Allan Sandfeld Jensen --- src/gui/text/freetype/qfreetypefontdatabase.cpp | 32 ++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/gui/text') diff --git a/src/gui/text/freetype/qfreetypefontdatabase.cpp b/src/gui/text/freetype/qfreetypefontdatabase.cpp index ac7520c495..21be28dba4 100644 --- a/src/gui/text/freetype/qfreetypefontdatabase.cpp +++ b/src/gui/text/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; QString styleName = QString::fromLatin1(face->style_name); if (applicationFont != nullptr) { -- cgit v1.2.3