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-10-12 13:33:19 +0200 |
commit | e05e3c776256d35798f451f31cd71e809786ed78 (patch) | |
tree | 49b6eeea04dc4ac3025e4100c76a42f5583afba8 /src/gui/text | |
parent | 6f0d7eb92ecf3e13e4cadac91f74cd8c1e7ce0f9 (diff) |
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 <lars.knoll@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/freetype/qfreetypefontdatabase.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
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) { |