From b9b3acf39e9e3b5b7288b4f4f8c7246606e16d0d Mon Sep 17 00:00:00 2001 From: Bernd Weimer Date: Thu, 21 Feb 2013 09:58:56 +0100 Subject: Take fontconfig font width into account For fonts provided by fontconfig the FC_WIDTH will be mapped to QFont::Stretch to achieve a more accurate font matching. In Qt5 the font style is considered instead. This cannot be used without breaking binary compatibility. Change-Id: Ia519c2b70eb9f03ba0971fd6e8dd575169c7b72a Reviewed-by: Jiang Jiang --- .../fontconfig/qfontconfigdatabase.cpp | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/plugins/platforms/fontdatabases/fontconfig/qfontconfigdatabase.cpp index 656a247..d1e7abb 100644 --- a/src/plugins/platforms/fontdatabases/fontconfig/qfontconfigdatabase.cpp +++ b/src/plugins/platforms/fontdatabases/fontconfig/qfontconfigdatabase.cpp @@ -314,7 +314,7 @@ void QFontconfigDatabase::populateFontDatabase() const char *properties [] = { FC_FAMILY, FC_WEIGHT, FC_SLANT, FC_SPACING, FC_FILE, FC_INDEX, - FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT, + FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WIDTH, #if FC_VERSION >= 20297 FC_CAPABILITY, @@ -417,13 +417,26 @@ void QFontconfigDatabase::populateFontDatabase() QFont::Weight weight = QFont::Weight(getFCWeight(weight_value)); double pixel_size = 0; - if (!scalable) { - int width = 100; - FcPatternGetInteger (fonts->fonts[i], FC_WIDTH, 0, &width); + if (!scalable) FcPatternGetDouble (fonts->fonts[i], FC_PIXEL_SIZE, 0, &pixel_size); + + int width = FC_WIDTH_NORMAL; + FcPatternGetInteger(fonts->fonts[i], FC_WIDTH, 0, &width); + + QFont::Stretch stretch; + switch (width) { + case FC_WIDTH_ULTRACONDENSED: stretch = QFont::UltraCondensed; break; + case FC_WIDTH_EXTRACONDENSED: stretch = QFont::ExtraCondensed; break; + case FC_WIDTH_CONDENSED: stretch = QFont::Condensed; break; + case FC_WIDTH_SEMICONDENSED: stretch = QFont::SemiCondensed; break; + case FC_WIDTH_NORMAL: stretch = QFont::Unstretched; break; + case FC_WIDTH_SEMIEXPANDED: stretch = QFont::SemiExpanded; break; + case FC_WIDTH_EXPANDED: stretch = QFont::Expanded; break; + case FC_WIDTH_EXTRAEXPANDED: stretch = QFont::ExtraExpanded; break; + case FC_WIDTH_ULTRAEXPANDED: stretch = QFont::UltraExpanded; break; + default: stretch = QFont::Unstretched; break; } - QFont::Stretch stretch = QFont::Unstretched; QPlatformFontDatabase::registerFont(familyName,QLatin1String((const char *)foundry_value),weight,style,stretch,antialias,scalable,pixel_size,writingSystems,fontFile); // qDebug() << familyName << (const char *)foundry_value << weight << style << &writingSystems << scalable << true << pixel_size; } -- cgit v0.12