Nikolay Sivov : dwrite: Implement newer version of CreateFontFromLOGFONT() .

Alexandre Julliard julliard at wine.codeweavers.com
Fri Apr 22 09:55:15 CDT 2016


Module: wine
Branch: master
Commit: 8a6c1d99c36216953207c576fd495b9569b42210
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8a6c1d99c36216953207c576fd495b9569b42210

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Fri Apr 22 16:15:35 2016 +0300

dwrite: Implement newer version of CreateFontFromLOGFONT().

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dwrite/gdiinterop.c | 81 ++++++++++++++++++++++++------------------------
 dlls/dwrite/tests/font.c | 20 ++++++++++++
 2 files changed, 61 insertions(+), 40 deletions(-)

diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c
index 711b95e..84b463a 100644
--- a/dlls/dwrite/gdiinterop.c
+++ b/dlls/dwrite/gdiinterop.c
@@ -620,47 +620,10 @@ static HRESULT WINAPI gdiinterop_CreateFontFromLOGFONT(IDWriteGdiInterop1 *iface
     LOGFONTW const *logfont, IDWriteFont **font)
 {
     struct gdiinterop *This = impl_from_IDWriteGdiInterop1(iface);
-    IDWriteFontCollection *collection;
-    IDWriteFontFamily *family;
-    DWRITE_FONT_STYLE style;
-    BOOL exists = FALSE;
-    UINT32 index;
-    HRESULT hr;
 
     TRACE("(%p)->(%p %p)\n", This, logfont, font);
 
-    *font = NULL;
-
-    if (!logfont) return E_INVALIDARG;
-
-    hr = IDWriteFactory2_GetSystemFontCollection((IDWriteFactory2*)This->factory, &collection, FALSE);
-    if (FAILED(hr)) {
-        ERR("failed to get system font collection: 0x%08x.\n", hr);
-        return hr;
-    }
-
-    hr = IDWriteFontCollection_FindFamilyName(collection, logfont->lfFaceName, &index, &exists);
-    if (FAILED(hr)) {
-        IDWriteFontCollection_Release(collection);
-        goto done;
-    }
-
-    if (!exists) {
-        hr = DWRITE_E_NOFONT;
-        goto done;
-    }
-
-    hr = IDWriteFontCollection_GetFontFamily(collection, index, &family);
-    if (FAILED(hr))
-        goto done;
-
-    style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
-    hr = IDWriteFontFamily_GetFirstMatchingFont(family, logfont->lfWeight, DWRITE_FONT_STRETCH_NORMAL, style, font);
-    IDWriteFontFamily_Release(family);
-
-done:
-    IDWriteFontCollection_Release(collection);
-    return hr;
+    return IDWriteGdiInterop1_CreateFontFromLOGFONT(iface, logfont, NULL, font);
 }
 
 static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface,
@@ -880,10 +843,48 @@ static HRESULT WINAPI gdiinterop1_CreateFontFromLOGFONT(IDWriteGdiInterop1 *ifac
     LOGFONTW const *logfont, IDWriteFontCollection *collection, IDWriteFont **font)
 {
     struct gdiinterop *This = impl_from_IDWriteGdiInterop1(iface);
+    IDWriteFontFamily *family;
+    DWRITE_FONT_STYLE style;
+    BOOL exists = FALSE;
+    UINT32 index;
+    HRESULT hr;
 
-    FIXME("(%p)->(%p %p %p): stub\n", This, logfont, collection, font);
+    TRACE("(%p)->(%p %p %p)\n", This, logfont, collection, font);
 
-    return E_NOTIMPL;
+    *font = NULL;
+
+    if (!logfont) return E_INVALIDARG;
+
+    if (collection)
+        IDWriteFontCollection_AddRef(collection);
+    else {
+        hr = IDWriteFactory2_GetSystemFontCollection((IDWriteFactory2*)This->factory, &collection, FALSE);
+        if (FAILED(hr)) {
+            ERR("failed to get system font collection: 0x%08x.\n", hr);
+            return hr;
+        }
+    }
+
+    hr = IDWriteFontCollection_FindFamilyName(collection, logfont->lfFaceName, &index, &exists);
+    if (FAILED(hr))
+        goto done;
+
+    if (!exists) {
+        hr = DWRITE_E_NOFONT;
+        goto done;
+    }
+
+    hr = IDWriteFontCollection_GetFontFamily(collection, index, &family);
+    if (FAILED(hr))
+        goto done;
+
+    style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
+    hr = IDWriteFontFamily_GetFirstMatchingFont(family, logfont->lfWeight, DWRITE_FONT_STRETCH_NORMAL, style, font);
+    IDWriteFontFamily_Release(family);
+
+done:
+    IDWriteFontCollection_Release(collection);
+    return hr;
 }
 
 static HRESULT WINAPI gdiinterop1_GetFontSignature_(IDWriteGdiInterop1 *iface, IDWriteFontFace *fontface,
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c
index bad347d..5fb4121 100644
--- a/dlls/dwrite/tests/font.c
+++ b/dlls/dwrite/tests/font.c
@@ -749,6 +749,7 @@ static ID2D1SimplifiedGeometrySink test_geomsink2 = { &test_geometrysink2_vtbl }
 static void test_CreateFontFromLOGFONT(void)
 {
     static const WCHAR tahomaspW[] = {'T','a','h','o','m','a',' ',0};
+    IDWriteGdiInterop1 *interop1;
     IDWriteGdiInterop *interop;
     DWRITE_FONT_WEIGHT weight;
     DWRITE_FONT_STYLE style;
@@ -906,6 +907,25 @@ if (0)
     ok(hr == DWRITE_E_NOFONT, "got 0x%08x\n", hr);
     ok(font == NULL, "got %p\n", font);
 
+    /* IDWriteGdiInterop1::CreateFontFromLOGFONT() */
+    hr = IDWriteGdiInterop_QueryInterface(interop, &IID_IDWriteGdiInterop1, (void**)&interop1);
+    if (hr == S_OK) {
+        memset(&logfont, 0, sizeof(logfont));
+        logfont.lfHeight = 12;
+        logfont.lfWidth  = 12;
+        logfont.lfWeight = FW_NORMAL;
+        logfont.lfItalic = 1;
+        lstrcpyW(logfont.lfFaceName, tahomaW);
+
+        hr = IDWriteGdiInterop1_CreateFontFromLOGFONT(interop1, &logfont, NULL, &font);
+        ok(hr == S_OK, "got 0x%08x\n", hr);
+
+        IDWriteFont_Release(font);
+        IDWriteGdiInterop1_Release(interop1);
+    }
+    else
+        win_skip("IDWriteGdiInterop1 is not supported, skipping CreateFontFromLOGFONT() tests.\n");
+
     IDWriteGdiInterop_Release(interop);
     IDWriteFactory_Release(factory);
 }




More information about the wine-cvs mailing list