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;
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