Commit 0344c196 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite: Make CreateFontFaceFromHdc() properly fail on unsupported font format.

parent ef31887c
...@@ -761,14 +761,15 @@ static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop1 *iface ...@@ -761,14 +761,15 @@ static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop1 *iface
is_supported = FALSE; is_supported = FALSE;
hr = IDWriteFontFile_Analyze(file, &is_supported, &filetype, &facetype, &facenum); hr = IDWriteFontFile_Analyze(file, &is_supported, &filetype, &facetype, &facenum);
if (FAILED(hr) || !is_supported) { if (SUCCEEDED(hr)) {
IDWriteFontFile_Release(file); if (is_supported)
return hr; /* 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); IDWriteFontFile_Release(file);
return hr; return hr;
} }
......
/* /*
* Font related tests * 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 * Copyright 2014 Aric Stewart for CodeWeavers
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -3458,6 +3458,7 @@ static void test_CreateFontFaceFromHdc(void) ...@@ -3458,6 +3458,7 @@ static void test_CreateFontFaceFromHdc(void)
IDWriteFactory *factory; IDWriteFactory *factory;
HFONT hfont, oldhfont; HFONT hfont, oldhfont;
LOGFONTW logfont; LOGFONTW logfont;
LOGFONTA lf;
HRESULT hr; HRESULT hr;
ULONG ref; ULONG ref;
HDC hdc; HDC hdc;
...@@ -3468,11 +3469,17 @@ static void test_CreateFontFaceFromHdc(void) ...@@ -3468,11 +3469,17 @@ static void test_CreateFontFaceFromHdc(void)
hr = IDWriteFactory_GetGdiInterop(factory, &interop); hr = IDWriteFactory_GetGdiInterop(factory, &interop);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
/* Invalid HDC. */
fontface = (void*)0xdeadbeef; fontface = (void*)0xdeadbeef;
hr = IDWriteGdiInterop_CreateFontFaceFromHdc(interop, NULL, &fontface); hr = IDWriteGdiInterop_CreateFontFaceFromHdc(interop, NULL, &fontface);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(fontface == NULL, "got %p\n", fontface); 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)); memset(&logfont, 0, sizeof(logfont));
logfont.lfHeight = 12; logfont.lfHeight = 12;
logfont.lfWidth = 12; logfont.lfWidth = 12;
...@@ -3489,6 +3496,21 @@ static void test_CreateFontFaceFromHdc(void) ...@@ -3489,6 +3496,21 @@ static void test_CreateFontFaceFromHdc(void)
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
IDWriteFontFace_Release(fontface); IDWriteFontFace_Release(fontface);
DeleteObject(SelectObject(hdc, oldhfont)); 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); DeleteDC(hdc);
IDWriteGdiInterop_Release(interop); IDWriteGdiInterop_Release(interop);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment