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>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2015-07-02 10:18:08 +02:00 committed by Konstantin Ritt
parent a05d8c73ff
commit 47113a1f36

View File

@ -1169,23 +1169,19 @@ QT_WARNING_POP
CustomFontFileLoader fontFileLoader; CustomFontFileLoader fontFileLoader;
fontFileLoader.addKey(this, fontData); fontFileLoader.addKey(this, fontData);
IDWriteFactory *factory = 0; QSharedPointer<QWindowsFontEngineData> fontEngineData = sharedFontData();
HRESULT hres = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, if (!initDirectWrite(fontEngineData.data()))
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown **>(&factory));
if (FAILED(hres)) {
qErrnoWarning(hres, "%s: DWriteCreateFactory failed", __FUNCTION__);
return 0; return 0;
}
IDWriteFontFile *fontFile = 0; IDWriteFontFile *fontFile = 0;
void *key = this; void *key = this;
hres = factory->CreateCustomFontFileReference(&key, sizeof(void *), HRESULT hres = fontEngineData->directWriteFactory->CreateCustomFontFileReference(&key,
fontFileLoader.loader(), &fontFile); sizeof(void *),
fontFileLoader.loader(),
&fontFile);
if (FAILED(hres)) { if (FAILED(hres)) {
qErrnoWarning(hres, "%s: CreateCustomFontFileReference failed", __FUNCTION__); qErrnoWarning(hres, "%s: CreateCustomFontFileReference failed", __FUNCTION__);
factory->Release();
return 0; return 0;
} }
@ -1196,30 +1192,31 @@ QT_WARNING_POP
fontFile->Analyze(&isSupportedFontType, &fontFileType, &fontFaceType, &numberOfFaces); fontFile->Analyze(&isSupportedFontType, &fontFileType, &fontFaceType, &numberOfFaces);
if (!isSupportedFontType) { if (!isSupportedFontType) {
fontFile->Release(); fontFile->Release();
factory->Release();
return 0; return 0;
} }
IDWriteFontFace *directWriteFontFace = 0; IDWriteFontFace *directWriteFontFace = 0;
hres = factory->CreateFontFace(fontFaceType, 1, &fontFile, 0, DWRITE_FONT_SIMULATIONS_NONE, hres = fontEngineData->directWriteFactory->CreateFontFace(fontFaceType,
&directWriteFontFace); 1,
&fontFile,
0,
DWRITE_FONT_SIMULATIONS_NONE,
&directWriteFontFace);
if (FAILED(hres)) { if (FAILED(hres)) {
qErrnoWarning(hres, "%s: CreateFontFace failed", __FUNCTION__); qErrnoWarning(hres, "%s: CreateFontFace failed", __FUNCTION__);
fontFile->Release(); fontFile->Release();
factory->Release();
return 0; return 0;
} }
fontFile->Release(); fontFile->Release();
fontEngine = new QWindowsFontEngineDirectWrite(directWriteFontFace, pixelSize, fontEngine = new QWindowsFontEngineDirectWrite(directWriteFontFace, pixelSize,
sharedFontData()); fontEngineData);
// Get font family from font data // Get font family from font data
fontEngine->fontDef.family = font.familyName(); fontEngine->fontDef.family = font.familyName();
directWriteFontFace->Release(); directWriteFontFace->Release();
factory->Release();
} }
#endif #endif