summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-07-02 10:18:08 +0200
committerKonstantin Ritt <ritt.ks@gmail.com>2015-07-06 10:23:10 +0000
commit47113a1f368a10ccafc41582b0f586c5c2277d36 (patch)
tree4f7c6222e81394a552aa7e0be4f083517943b4b2
parenta05d8c73ffd38414c22be801d6c9d27c1d34ab93 (diff)
DirectWrite: Fix crash when loading QRawFont from data
In Qt 4, we would create and destroy the DirectWrite factory for each time we load the font data from a QRawFont. This factory would then be passed to the font engine ctor. However, in Qt 5, some things have been refactored, and the font engine will now try to use the factory stored in the sharedFontData(). This would cause dereferencing a null pointer because we didn't initialize the data before constructing the font engine. [ChangeLog][Windows][Text] Fixed crash in DirectWrite engine when constructing a QRawFont from raw font data. Task-number: QTBUG-46963 Change-Id: I4813c7f818c9df5707c27f5b6ce507649d902270 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
-rw-r--r--src/plugins/platforms/windows/qwindowsfontdatabase.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
index a544b9d81e..1c5b114efd 100644
--- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
+++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp
@@ -1169,23 +1169,19 @@ QT_WARNING_POP
CustomFontFileLoader fontFileLoader;
fontFileLoader.addKey(this, fontData);
- IDWriteFactory *factory = 0;
- HRESULT hres = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
- __uuidof(IDWriteFactory),
- reinterpret_cast<IUnknown **>(&factory));
- if (FAILED(hres)) {
- qErrnoWarning(hres, "%s: DWriteCreateFactory failed", __FUNCTION__);
+ QSharedPointer<QWindowsFontEngineData> fontEngineData = sharedFontData();
+ if (!initDirectWrite(fontEngineData.data()))
return 0;
- }
IDWriteFontFile *fontFile = 0;
void *key = this;
- hres = factory->CreateCustomFontFileReference(&key, sizeof(void *),
- fontFileLoader.loader(), &fontFile);
+ HRESULT hres = fontEngineData->directWriteFactory->CreateCustomFontFileReference(&key,
+ sizeof(void *),
+ fontFileLoader.loader(),
+ &fontFile);
if (FAILED(hres)) {
qErrnoWarning(hres, "%s: CreateCustomFontFileReference failed", __FUNCTION__);
- factory->Release();
return 0;
}
@@ -1196,30 +1192,31 @@ QT_WARNING_POP
fontFile->Analyze(&isSupportedFontType, &fontFileType, &fontFaceType, &numberOfFaces);
if (!isSupportedFontType) {
fontFile->Release();
- factory->Release();
return 0;
}
IDWriteFontFace *directWriteFontFace = 0;
- hres = factory->CreateFontFace(fontFaceType, 1, &fontFile, 0, DWRITE_FONT_SIMULATIONS_NONE,
- &directWriteFontFace);
+ hres = fontEngineData->directWriteFactory->CreateFontFace(fontFaceType,
+ 1,
+ &fontFile,
+ 0,
+ DWRITE_FONT_SIMULATIONS_NONE,
+ &directWriteFontFace);
if (FAILED(hres)) {
qErrnoWarning(hres, "%s: CreateFontFace failed", __FUNCTION__);
fontFile->Release();
- factory->Release();
return 0;
}
fontFile->Release();
fontEngine = new QWindowsFontEngineDirectWrite(directWriteFontFace, pixelSize,
- sharedFontData());
+ fontEngineData);
// Get font family from font data
fontEngine->fontDef.family = font.familyName();
directWriteFontFace->Release();
- factory->Release();
}
#endif