summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2016-09-20 13:58:18 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2016-09-27 07:59:56 +0000
commit6af82fe9fd19361f56ea4bf5a6be371722bafde3 (patch)
treeef9539f2c61ccc4107c59e96bf3072a66db1803e /src/plugins/platforms/windows/qwindowsfontdatabase.cpp
parent8cd28ea8850c5365c47dd65de16f528e2e223835 (diff)
Windows: Fix crash when loading color fonts from data
When color fonts are loaded from data, the font returned will be a DirectWrite engine even the hinting preference does not require it. This would cause a crash as we unconditionally cast the pointer to QWindowsFontEngine*. Using GDI and the unique family name hack to load the font from data works fine, but we need to make sure we reference count the font resource in this case, so we have to implement the setUniqueFamilyName() logic in the DirectWrite engine as well for this specific case. [ChangeLog][Windows] Fixed crash when loading color fonts from data. Task-number: QTBUG-55595 Change-Id: I05443e8a396105da68ac4872b48339130b86c7f6 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsfontdatabase.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowsfontdatabase.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
index 314da702eb..bc237bc88c 100644
--- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
+++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
@@ -1231,8 +1231,23 @@ QT_WARNING_POP
Q_ASSERT(fontEngine->ref.load() == 0);
// Override the generated font name
- static_cast<QWindowsFontEngine *>(fontEngine)->setUniqueFamilyName(uniqueFamilyName);
- fontEngine->fontDef.family = actualFontName;
+ switch (fontEngine->type()) {
+ case QFontEngine::Win:
+ static_cast<QWindowsFontEngine *>(fontEngine)->setUniqueFamilyName(uniqueFamilyName);
+ fontEngine->fontDef.family = actualFontName;
+ break;
+
+#if !defined(QT_NO_DIRECTWRITE)
+ case QFontEngine::DirectWrite:
+ static_cast<QWindowsFontEngineDirectWrite *>(fontEngine)->setUniqueFamilyName(uniqueFamilyName);
+ fontEngine->fontDef.family = actualFontName;
+ break;
+#endif // !QT_NO_DIRECTWRITE
+
+ default:
+ Q_ASSERT_X(false, Q_FUNC_INFO, "Unhandled font engine.");
+ }
+
UniqueFontData uniqueData;
uniqueData.handle = fontHandle;
uniqueData.refCount.ref();