Commit 09ba9bdb authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite: Store font style provided in LOGFONT data.

parent 56d71b04
......@@ -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;
......@@ -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 const 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;
......
......@@ -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,
......
......@@ -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 = FW_NORMAL;
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 = FW_NORMAL;
hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
todo_wine
EXPECT_HR(hr, DWRITE_E_NOFONT);
IDWriteGdiInterop_Release(interop);
}
......
......@@ -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)")
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