dwrite: Store font style provided in LOGFONT data.
[wine/multimedia.git] / dlls / dwrite / tests / font.c
blobf169393478ca78aae46d99025ef76c2acd0b3ab4
1 /*
2 * Font related tests
4 * Copyright 2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include "windows.h"
25 #include "initguid.h"
26 #include "dwrite.h"
28 #include "wine/test.h"
30 #define EXPECT_HR(hr,hr_exp) \
31 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
33 static IDWriteFactory *factory;
35 static void test_CreateFontFromLOGFONT(void)
37 static const WCHAR arialW[] = {'A','r','i','a','l',0};
38 static const WCHAR blahW[] = {'B','l','a','h','!',0};
39 IDWriteGdiInterop *interop;
40 DWRITE_FONT_WEIGHT weight;
41 DWRITE_FONT_STYLE style;
42 IDWriteFont *font;
43 LOGFONTW logfont;
44 LONG weights[][2] = {
45 {FW_NORMAL, DWRITE_FONT_WEIGHT_NORMAL},
46 {FW_BOLD, DWRITE_FONT_WEIGHT_BOLD},
47 { 0, DWRITE_FONT_WEIGHT_NORMAL},
48 { 50, DWRITE_FONT_WEIGHT_NORMAL},
49 {150, DWRITE_FONT_WEIGHT_NORMAL},
50 {250, DWRITE_FONT_WEIGHT_NORMAL},
51 {350, DWRITE_FONT_WEIGHT_NORMAL},
52 {450, DWRITE_FONT_WEIGHT_NORMAL},
53 {650, DWRITE_FONT_WEIGHT_BOLD},
54 {750, DWRITE_FONT_WEIGHT_BOLD},
55 {850, DWRITE_FONT_WEIGHT_BOLD},
56 {950, DWRITE_FONT_WEIGHT_BOLD},
57 {960, DWRITE_FONT_WEIGHT_BOLD},
59 HRESULT hr;
60 BOOL ret;
61 int i;
63 hr = IDWriteFactory_GetGdiInterop(factory, &interop);
64 EXPECT_HR(hr, S_OK);
66 if (0)
67 /* null out parameter crashes this call */
68 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, NULL, NULL);
70 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, NULL, &font);
71 EXPECT_HR(hr, E_INVALIDARG);
73 memset(&logfont, 0, sizeof(logfont));
74 logfont.lfHeight = 12;
75 logfont.lfWidth = 12;
76 logfont.lfWeight = FW_NORMAL;
77 logfont.lfItalic = 1;
78 lstrcpyW(logfont.lfFaceName, arialW);
80 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
81 EXPECT_HR(hr, S_OK);
83 /* now check properties */
84 weight = IDWriteFont_GetWeight(font);
85 todo_wine
86 ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "got %d\n", weight);
88 style = IDWriteFont_GetStyle(font);
89 ok(style == DWRITE_FONT_STYLE_ITALIC, "got %d\n", style);
91 ret = IDWriteFont_IsSymbolFont(font);
92 ok(!ret, "got %d\n", ret);
94 IDWriteFont_Release(font);
96 /* weight values */
97 for (i = 0; i < sizeof(weights)/(2*sizeof(LONG)); i++)
99 memset(&logfont, 0, sizeof(logfont));
100 logfont.lfHeight = 12;
101 logfont.lfWidth = 12;
102 logfont.lfWeight = weights[i][0];
103 lstrcpyW(logfont.lfFaceName, arialW);
105 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
106 EXPECT_HR(hr, S_OK);
108 weight = IDWriteFont_GetWeight(font);
109 todo_wine
110 ok(weight == weights[i][1],
111 "%d: got %d, expected %d\n", i, weight, weights[i][1]);
112 IDWriteFont_Release(font);
115 /* weight not from enum */
116 memset(&logfont, 0, sizeof(logfont));
117 logfont.lfHeight = 12;
118 logfont.lfWidth = 12;
119 logfont.lfWeight = 550;
120 lstrcpyW(logfont.lfFaceName, arialW);
122 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
123 EXPECT_HR(hr, S_OK);
125 weight = IDWriteFont_GetWeight(font);
126 todo_wine
127 ok(weight == DWRITE_FONT_WEIGHT_NORMAL || broken(weight == DWRITE_FONT_WEIGHT_BOLD) /* win7 w/o SP */,
128 "got %d\n", weight);
129 IDWriteFont_Release(font);
131 /* empty or nonexistent face name */
132 memset(&logfont, 0, sizeof(logfont));
133 logfont.lfHeight = 12;
134 logfont.lfWidth = 12;
135 logfont.lfWeight = FW_NORMAL;
136 lstrcpyW(logfont.lfFaceName, blahW);
138 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
139 todo_wine
140 EXPECT_HR(hr, DWRITE_E_NOFONT);
142 memset(&logfont, 0, sizeof(logfont));
143 logfont.lfHeight = 12;
144 logfont.lfWidth = 12;
145 logfont.lfWeight = FW_NORMAL;
147 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
148 todo_wine
149 EXPECT_HR(hr, DWRITE_E_NOFONT);
151 IDWriteGdiInterop_Release(interop);
154 START_TEST(font)
156 HRESULT hr;
158 hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory);
159 ok(hr == S_OK, "got 0x%08x\n", hr);
160 if (hr != S_OK)
162 win_skip("failed to create factory\n");
163 return;
166 test_CreateFontFromLOGFONT();
168 IDWriteFactory_Release(factory);