Module: wine Branch: master Commit: 0344c19692396dca80a98f02fa7f713cee12b344 URL: http://source.winehq.org/git/wine.git/?a=commit;h=0344c19692396dca80a98f02fa...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Wed Apr 19 15:15:29 2017 +0300
dwrite: Make CreateFontFaceFromHdc() properly fail on unsupported font format.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/dwrite/gdiinterop.c | 13 +++++++------ dlls/dwrite/tests/font.c | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c index cf3b3fa..2b3f32d 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 2e26bc7..2c874df 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; @@ -3489,6 +3496,21 @@ static void test_CreateFontFaceFromHdc(void) 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);
IDWriteGdiInterop_Release(interop);