Nikolay Sivov : dwrite: Make CreateFontFaceFromHdc() properly fail on unsupported font format.
Alexandre Julliard
julliard at winehq.org
Thu Jul 20 12:11:29 CDT 2017
Module: wine
Branch: stable
Commit: 9f0cb9c2cfb40e3d39d2fd19a1f4b2e72a62add2
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9f0cb9c2cfb40e3d39d2fd19a1f4b2e72a62add2
Author: Nikolay Sivov <nsivov at 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 at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 0344c19692396dca80a98f02fa7f713cee12b344)
Signed-off-by: Michael Stefaniuc <mstefani at 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 67fc4a0..5353810d 100644
--- a/dlls/dwrite/gdiinterop.c
+++ b/dlls/dwrite/gdiinterop.c
@@ -746,14 +746,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 ba9866a..b5cb9b5 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
@@ -3344,6 +3344,7 @@ static void test_CreateFontFaceFromHdc(void)
IDWriteFactory *factory;
HFONT hfont, oldhfont;
LOGFONTW logfont;
+ LOGFONTA lf;
HRESULT hr;
HDC hdc;
@@ -3353,11 +3354,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;
@@ -3374,6 +3381,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);
More information about the wine-cvs
mailing list