summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2021-10-11 12:25:03 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-10-12 16:37:41 +0000
commit8fbf61c323c0b6407aab39ba2737c4f52139cfd1 (patch)
tree89583775e12b4c727c7e4b4950a08d3b1bcf409d
parentce24eaf5ad744345c991dea8c99c0913877ec1e4 (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. 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) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/gui/text/freetype/qfreetypefontdatabase.cpp32
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) {