From 131eee5cd7547ddb658d6337e1877da3d73b3158 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 31 Aug 2015 22:13:08 +0200 Subject: Avoid synthesizing stretch on condensed font families If an entire font family is condensed or stretched and we match by family name, the default stretch factor of 100 will make the font engine try to synthesize it back to medium stretched font. The existing code is already made to deal with a stretch of 0 that is no longer used. This patch reintroduces 0 stretch to indicate no specific stretch has been requested. Specifically setting stretch to 100 on a QFont will introduce the old behavior. [ChangeLog][QtGui][QFont] The default value of QFont::stretch() is now 0 to indicate any default stretch is acceptable. Task-number: QTBUG-48043 Change-Id: I574747f980fd4f9893df828818aae99a07b41623 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfontdatabase.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/gui/text/qfontdatabase.cpp') diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 594d791e9c..cb1619e690 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -951,12 +951,14 @@ QFontEngine *loadSingleEngine(int script, } } - // If the font data's native stretch matches the requested stretch we need to set stretch to 100 - // to avoid the fontengine synthesizing stretch. If they didn't match exactly we need to calculate - // the new stretch factor. This only done if not matched by styleName. + // To avoid synthesized stretch we need a matching stretch to be 100 after this point. + // If stretch didn't match exactly we need to calculate the new stretch factor. + // This only done if not matched by styleName. if (style->key.stretch != 0 && request.stretch != 0 && (request.styleName.isEmpty() || request.styleName != style->styleName)) { - def.stretch = (request.stretch * 100 + 50) / style->key.stretch; + def.stretch = (request.stretch * 100 + style->key.stretch / 2) / style->key.stretch; + } else { + def.stretch = 100; } engine = pfdb->fontEngine(def, size->handle); @@ -1219,7 +1221,8 @@ static int match(int script, const QFontDef &request, QtFontStyle::Key styleKey; styleKey.style = request.style; styleKey.weight = request.weight; - styleKey.stretch = request.stretch; + // Prefer a stretch closest to 100. + styleKey.stretch = request.stretch ? request.stretch : 100; char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p'; @@ -2740,8 +2743,6 @@ void QFontDatabase::load(const QFontPrivate *d, int script) } if (req.pointSize < 0) req.pointSize = req.pixelSize*72.0/d->dpi; - if (req.stretch == 0) - req.stretch = 100; // respect the fallback families that might be passed through the request const QStringList fallBackFamilies = familyList(req); -- cgit v1.2.3