diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c index cf3b3fa10c6..2b3f32ddd7d 100644 --- a/dlls/dwrite/gdiinterop.c +++ b/dlls/dwrite/gdiinterop.c @@ -761,14 +761,15 @@ static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop1 *iface is_supported = FALSE; hr = IDWriteFontFile_Analyze(file, &is_supported, &filetype, &facetype, &facenum); - if (FAILED(hr) || !is_supported) { - IDWriteFontFile_Release(file); - return hr; + if (SUCCEEDED(hr)) { + if (is_supported) + /* Simulations flags values match DWRITE_FONT_SIMULATIONS */ + hr = IDWriteFactory4_CreateFontFace(This->factory, facetype, 1, &file, info.face_index, + info.simulations, fontface); + else + hr = DWRITE_E_FILEFORMAT; } - /* Simulations flags values match DWRITE_FONT_SIMULATIONS */ - hr = IDWriteFactory4_CreateFontFace(This->factory, facetype, 1, &file, info.face_index, info.simulations, - fontface); IDWriteFontFile_Release(file); return hr; } diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index 2e26bc7b2de..2c874df5bf5 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -1,7 +1,7 @@ /* * Font related tests * - * Copyright 2012, 2014-2016 Nikolay Sivov for CodeWeavers + * Copyright 2012, 2014-2017 Nikolay Sivov for CodeWeavers * Copyright 2014 Aric Stewart for CodeWeavers * * This library is free software; you can redistribute it and/or @@ -3458,6 +3458,7 @@ static void test_CreateFontFaceFromHdc(void) IDWriteFactory *factory; HFONT hfont, oldhfont; LOGFONTW logfont; + LOGFONTA lf; HRESULT hr; ULONG ref; HDC hdc; @@ -3468,11 +3469,17 @@ static void test_CreateFontFaceFromHdc(void) hr = IDWriteFactory_GetGdiInterop(factory, &interop); ok(hr == S_OK, "got 0x%08x\n", hr); + /* Invalid HDC. */ fontface = (void*)0xdeadbeef; hr = IDWriteGdiInterop_CreateFontFaceFromHdc(interop, NULL, &fontface); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(fontface == NULL, "got %p\n", fontface); + fontface = (void *)0xdeadbeef; + hr = IDWriteGdiInterop_CreateFontFaceFromHdc(interop, (HDC)0xdeadbeef, &fontface); + ok(hr == E_FAIL, "got 0x%08x\n", hr); + ok(fontface == NULL, "got %p\n", fontface); + memset(&logfont, 0, sizeof(logfont)); logfont.lfHeight = 12; logfont.lfWidth = 12; @@ -3488,6 +3495,21 @@ static void test_CreateFontFaceFromHdc(void) hr = IDWriteGdiInterop_CreateFontFaceFromHdc(interop, hdc, &fontface); ok(hr == S_OK, "got 0x%08x\n", hr); IDWriteFontFace_Release(fontface); + DeleteObject(SelectObject(hdc, oldhfont)); + + /* Select bitmap font MS Sans Serif, format that's not supported by DirectWrite. */ + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = -12; + strcpy(lf.lfFaceName, "MS Sans Serif"); + + hfont = CreateFontIndirectA(&lf); + oldhfont = SelectObject(hdc, hfont); + + fontface = (void *)0xdeadbeef; + hr = IDWriteGdiInterop_CreateFontFaceFromHdc(interop, hdc, &fontface); + ok(hr == DWRITE_E_FILEFORMAT || broken(hr == E_FAIL) /* Vista */, "got 0x%08x\n", hr); + ok(fontface == NULL, "got %p\n", fontface); + DeleteObject(SelectObject(hdc, oldhfont)); DeleteDC(hdc);