From a128347c9b51fc9fa629662a14b77e1489537276 Mon Sep 17 00:00:00 2001
From: Allan Sandfeld Jensen <allan.jensen@digia.com>
Date: Wed, 13 Aug 2014 18:44:24 +0200
Subject: [PATCH] Fix rendering of fonts matched based on stretch

If the fontdatabase matches a font based on the stretch aka width
then the stretch factor on the font-engine needs to be 100
to avoid the fontengine doing manual stretching.

Without this a font requested with 75 stretch and matched with a font
of 75 stretch would be further condensed 25% by the fontengine.

Change-Id: Ib85ff027420c0ce891b0808dab13d25417d22df1
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
---
 src/gui/text/qfontdatabase.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 7aa5af8a980..c3be9da2f7f 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -822,6 +822,13 @@ QFontEngine *loadSingleEngine(int script,
     QFontCache::Key key(def,script);
     QFontEngine *engine = QFontCache::instance()->findEngine(key);
     if (!engine) {
+        // 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.
+        bool styleNameMatch = !request.styleName.isEmpty() && request.styleName == style->styleName;
+        if (!styleNameMatch && style->key.stretch != 0 && request.stretch != 0)
+            def.stretch = (request.stretch * 100 + 50) / style->key.stretch;
+
         engine = pfdb->fontEngine(def, size->handle);
         if (engine) {
             Q_ASSERT(engine->type() != QFontEngine::Multi);
-- 
GitLab