[2/4] dwrite: Store font style provided in LOGFONT data

Nikolay Sivov nsivov at codeweavers.com
Sun Aug 5 15:26:02 CDT 2012


Store font style provided in LOGFONT data
-------------- next part --------------
>From 790832834dc910559afdd8461336a1eecfd03bff Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov at codeweavers.com>
Date: Sat, 4 Aug 2012 19:14:41 +0400
Subject: [PATCH 4/5] Store font style provided in LOGFONT data

---
 dlls/dwrite/dwrite_private.h |    2 +-
 dlls/dwrite/font.c           |   15 ++++++--
 dlls/dwrite/gdiinterop.c     |    4 +-
 dlls/dwrite/tests/font.c     |   76 ++++++++++++++++++++++++++++++++++++++++-
 include/dwrite.idl           |   14 ++++++++
 5 files changed, 102 insertions(+), 9 deletions(-)

diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index c52b93a..c3c7cb1 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -27,4 +27,4 @@ static inline BOOL heap_free(void *mem)
 }
 
 extern HRESULT create_gdiinterop(IDWriteGdiInterop**) DECLSPEC_HIDDEN;
-extern HRESULT create_font(IDWriteFont**) DECLSPEC_HIDDEN;
+extern HRESULT create_font_from_logfont(const LOGFONTW*, IDWriteFont**) DECLSPEC_HIDDEN;
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index cd79b6e..2e6e281 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -30,6 +30,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
 struct dwrite_font {
     IDWriteFont IDWriteFont_iface;
     LONG ref;
+
+    DWRITE_FONT_STYLE style;
 };
 
 static inline struct dwrite_font *impl_from_IDWriteFont(IDWriteFont *iface)
@@ -86,7 +88,7 @@ static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface)
 {
     struct dwrite_font *This = impl_from_IDWriteFont(iface);
     FIXME("(%p): stub\n", This);
-    return DWRITE_FONT_WEIGHT_NORMAL;
+    return 0;
 }
 
 static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont *iface)
@@ -99,8 +101,8 @@ static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont *iface)
 static DWRITE_FONT_STYLE WINAPI dwritefont_GetStyle(IDWriteFont *iface)
 {
     struct dwrite_font *This = impl_from_IDWriteFont(iface);
-    FIXME("(%p): stub\n", This);
-    return DWRITE_FONT_STYLE_NORMAL;
+    TRACE("(%p)\n", This);
+    return This->style;
 }
 
 static BOOL WINAPI dwritefont_IsSymbolFont(IDWriteFont *iface)
@@ -169,15 +171,20 @@ static IDWriteFontVtbl dwritefontvtbl = {
     dwritefont_CreateFontFace
 };
 
-HRESULT create_font(IDWriteFont **font)
+HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
 {
     struct dwrite_font *This;
 
+    *font = NULL;
+
     This = heap_alloc(sizeof(struct dwrite_font));
     if (!This) return E_OUTOFMEMORY;
 
     This->IDWriteFont_iface.lpVtbl = &dwritefontvtbl;
     This->ref = 1;
+
+    This->style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
+
     *font = &This->IDWriteFont_iface;
 
     return S_OK;
diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c
index d374724..d98eb5b 100644
--- a/dlls/dwrite/gdiinterop.c
+++ b/dlls/dwrite/gdiinterop.c
@@ -57,11 +57,11 @@ static ULONG WINAPI gdiinterop_Release(IDWriteGdiInterop *iface)
 static HRESULT WINAPI gdiinterop_CreateFontFromLOGFONT(IDWriteGdiInterop *iface,
     LOGFONTW const *logfont, IDWriteFont **font)
 {
-    FIXME("(%p %p): stub\n", logfont, font);
+    TRACE("(%p %p)\n", logfont, font);
 
     if (!logfont) return E_INVALIDARG;
 
-    return create_font(font);
+    return create_font_from_logfont(logfont, font);
 }
 
 static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop *iface,
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c
index 520fc1b..7e30eb0 100644
--- a/dlls/dwrite/tests/font.c
+++ b/dlls/dwrite/tests/font.c
@@ -30,18 +30,35 @@
 #define EXPECT_HR(hr,hr_exp) \
     ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
 
-IDWriteFactory *factory;
+static IDWriteFactory *factory;
 
 static void test_CreateFontFromLOGFONT(void)
 {
     static const WCHAR arialW[] = {'A','r','i','a','l',0};
+    static const WCHAR blahW[]  = {'B','l','a','h','!',0};
     IDWriteGdiInterop *interop;
     DWRITE_FONT_WEIGHT weight;
     DWRITE_FONT_STYLE style;
     IDWriteFont *font;
     LOGFONTW logfont;
+    LONG weights[][2] = {
+        {FW_NORMAL, DWRITE_FONT_WEIGHT_NORMAL},
+        {FW_BOLD, DWRITE_FONT_WEIGHT_BOLD},
+        {  0, DWRITE_FONT_WEIGHT_NORMAL},
+        { 50, DWRITE_FONT_WEIGHT_NORMAL},
+        {150, DWRITE_FONT_WEIGHT_NORMAL},
+        {250, DWRITE_FONT_WEIGHT_NORMAL},
+        {350, DWRITE_FONT_WEIGHT_NORMAL},
+        {450, DWRITE_FONT_WEIGHT_NORMAL},
+        {650, DWRITE_FONT_WEIGHT_BOLD},
+        {750, DWRITE_FONT_WEIGHT_BOLD},
+        {850, DWRITE_FONT_WEIGHT_BOLD},
+        {950, DWRITE_FONT_WEIGHT_BOLD},
+        {960, DWRITE_FONT_WEIGHT_BOLD},
+    };
     HRESULT hr;
     BOOL ret;
+    int i;
 
     hr = IDWriteFactory_GetGdiInterop(factory, &interop);
     EXPECT_HR(hr, S_OK);
@@ -65,10 +82,10 @@ if (0)
 
     /* now check properties */
     weight = IDWriteFont_GetWeight(font);
+todo_wine
     ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "got %d\n", weight);
 
     style = IDWriteFont_GetStyle(font);
-todo_wine
     ok(style == DWRITE_FONT_STYLE_ITALIC, "got %d\n", style);
 
     ret = IDWriteFont_IsSymbolFont(font);
@@ -76,6 +93,61 @@ todo_wine
 
     IDWriteFont_Release(font);
 
+    /* weight values */
+    for (i = 0; i < sizeof(weights)/(2*sizeof(LONG)); i++)
+    {
+        memset(&logfont, 0, sizeof(logfont));
+        logfont.lfHeight = 12;
+        logfont.lfWidth  = 12;
+        logfont.lfWeight = weights[i][0];
+        lstrcpyW(logfont.lfFaceName, arialW);
+
+        hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
+        EXPECT_HR(hr, S_OK);
+
+        weight = IDWriteFont_GetWeight(font);
+    todo_wine
+        ok(weight == weights[i][1],
+            "%d: got %d, expected %d\n", i, weight, weights[i][1]);
+        IDWriteFont_Release(font);
+    }
+
+    /* weight not from enum */
+    memset(&logfont, 0, sizeof(logfont));
+    logfont.lfHeight = 12;
+    logfont.lfWidth  = 12;
+    logfont.lfWeight = 550;
+    lstrcpyW(logfont.lfFaceName, arialW);
+
+    hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
+    EXPECT_HR(hr, S_OK);
+
+    weight = IDWriteFont_GetWeight(font);
+todo_wine
+    ok(weight == DWRITE_FONT_WEIGHT_NORMAL || broken(weight == DWRITE_FONT_WEIGHT_BOLD) /* win7 w/o SP */,
+        "got %d\n", weight);
+    IDWriteFont_Release(font);
+
+    /* empty or nonexistent face name */
+    memset(&logfont, 0, sizeof(logfont));
+    logfont.lfHeight = 12;
+    logfont.lfWidth  = 12;
+    logfont.lfWeight = weights[i][0];
+    lstrcpyW(logfont.lfFaceName, blahW);
+
+    hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
+todo_wine
+    EXPECT_HR(hr, DWRITE_E_NOFONT);
+
+    memset(&logfont, 0, sizeof(logfont));
+    logfont.lfHeight = 12;
+    logfont.lfWidth  = 12;
+    logfont.lfWeight = weights[i][0];
+
+    hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
+todo_wine
+    EXPECT_HR(hr, DWRITE_E_NOFONT);
+
     IDWriteGdiInterop_Release(interop);
 }
 
diff --git a/include/dwrite.idl b/include/dwrite.idl
index aff529a..60a2bae 100644
--- a/include/dwrite.idl
+++ b/include/dwrite.idl
@@ -1394,3 +1394,17 @@ interface IDWriteFactory : IUnknown
 }
 
 cpp_quote("HRESULT WINAPI DWriteCreateFactory(DWRITE_FACTORY_TYPE,REFIID,IUnknown**);")
+
+/* error codes */
+cpp_quote("#define FACILITY_DWRITE 0x898")
+cpp_quote("#define DWRITE_ERR_BASE 0x5000")
+cpp_quote("#define MAKE_DWRITE_HR(severity, code) MAKE_HRESULT(severity, FACILITY_DWRITE, (DWRITE_ERR_BASE + code))")
+cpp_quote("#define MAKE_DWRITE_HR_ERR(code) MAKE_DWRITE_HR(SEVERITY_ERROR, code)")
+
+cpp_quote("#define DWRITE_E_FILEFORMAT              MAKE_DWRITE_HR_ERR(0x0)")
+cpp_quote("#define DWRITE_E_UNEXPECTED              MAKE_DWRITE_HR_ERR(0x1)")
+cpp_quote("#define DWRITE_E_NOFONT                  MAKE_DWRITE_HR_ERR(0x2)")
+cpp_quote("#define DWRITE_E_FILENOTFOUND            MAKE_DWRITE_HR_ERR(0x3)")
+cpp_quote("#define DWRITE_E_FILEACCESS              MAKE_DWRITE_HR_ERR(0x4)")
+cpp_quote("#define DWRITE_E_FONTCOLLECTIONOBSOLETE  MAKE_DWRITE_HR_ERR(0x5)")
+cpp_quote("#define DWRITE_E_ALREADYREGISTERED       MAKE_DWRITE_HR_ERR(0x6)")
-- 
1.5.6.5




More information about the wine-patches mailing list