mshtml: Added IHTMLWindow6::get_sessionStorage implementation.
[wine] / dlls / dwrite / tests / font.c
1 /*
2  *    Font related tests
3  *
4  * Copyright 2012 Nikolay Sivov for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22
23 #include "windows.h"
24
25 #include "initguid.h"
26 #include "dwrite.h"
27
28 #include "wine/test.h"
29
30 #define EXPECT_HR(hr,hr_exp) \
31     ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
32
33 static IDWriteFactory *factory;
34
35 static void test_CreateFontFromLOGFONT(void)
36 {
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},
58     };
59     HRESULT hr;
60     BOOL ret;
61     int i;
62
63     hr = IDWriteFactory_GetGdiInterop(factory, &interop);
64     EXPECT_HR(hr, S_OK);
65
66 if (0)
67     /* null out parameter crashes this call */
68     hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, NULL, NULL);
69
70     hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, NULL, &font);
71     EXPECT_HR(hr, E_INVALIDARG);
72
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);
79
80     hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
81     EXPECT_HR(hr, S_OK);
82
83     /* now check properties */
84     weight = IDWriteFont_GetWeight(font);
85 todo_wine
86     ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "got %d\n", weight);
87
88     style = IDWriteFont_GetStyle(font);
89     ok(style == DWRITE_FONT_STYLE_ITALIC, "got %d\n", style);
90
91     ret = IDWriteFont_IsSymbolFont(font);
92     ok(!ret, "got %d\n", ret);
93
94     IDWriteFont_Release(font);
95
96     /* weight values */
97     for (i = 0; i < sizeof(weights)/(2*sizeof(LONG)); i++)
98     {
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);
104
105         hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
106         EXPECT_HR(hr, S_OK);
107
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);
113     }
114
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);
121
122     hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
123     EXPECT_HR(hr, S_OK);
124
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);
130
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);
137
138     hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
139 todo_wine
140     EXPECT_HR(hr, DWRITE_E_NOFONT);
141
142     memset(&logfont, 0, sizeof(logfont));
143     logfont.lfHeight = 12;
144     logfont.lfWidth  = 12;
145     logfont.lfWeight = FW_NORMAL;
146
147     hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
148 todo_wine
149     EXPECT_HR(hr, DWRITE_E_NOFONT);
150
151     IDWriteGdiInterop_Release(interop);
152 }
153
154 static void test_CreateBitmapRenderTarget(void)
155 {
156     IDWriteBitmapRenderTarget *target, *target2;
157     IDWriteGdiInterop *interop;
158     DIBSECTION ds;
159     HBITMAP hbm;
160     HRESULT hr;
161     SIZE size;
162     HDC hdc;
163     int ret;
164
165     hr = IDWriteFactory_GetGdiInterop(factory, &interop);
166     EXPECT_HR(hr, S_OK);
167
168     target = NULL;
169     hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 0, 0, &target);
170     EXPECT_HR(hr, S_OK);
171
172 if (0) /* crashes on native */
173     hr = IDWriteBitmapRenderTarget_GetSize(target, NULL);
174
175     size.cx = size.cy = -1;
176     hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
177     EXPECT_HR(hr, S_OK);
178     ok(size.cx == 0, "got %d\n", size.cx);
179     ok(size.cy == 0, "got %d\n", size.cy);
180
181     target2 = NULL;
182     hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 0, 0, &target2);
183     EXPECT_HR(hr, S_OK);
184     ok(target != target2, "got %p, %p\n", target2, target);
185     IDWriteBitmapRenderTarget_Release(target2);
186
187     hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target);
188     ok(hdc != NULL, "got %p\n", hdc);
189
190     hbm = GetCurrentObject(hdc, OBJ_BITMAP);
191     ok(hbm != NULL, "got %p\n", hbm);
192
193     /* check DIB properties */
194     ret = GetObjectW(hbm, sizeof(ds), &ds);
195     ok(ret == sizeof(BITMAP), "got %d\n", ret);
196     ok(ds.dsBm.bmWidth == 1, "got %d\n", ds.dsBm.bmWidth);
197     ok(ds.dsBm.bmHeight == 1, "got %d\n", ds.dsBm.bmHeight);
198     ok(ds.dsBm.bmPlanes == 1, "got %d\n", ds.dsBm.bmPlanes);
199     ok(ds.dsBm.bmBitsPixel == 1, "got %d\n", ds.dsBm.bmBitsPixel);
200     ok(!ds.dsBm.bmBits, "got %p\n", ds.dsBm.bmBits);
201
202     IDWriteBitmapRenderTarget_Release(target);
203
204     hbm = GetCurrentObject(hdc, OBJ_BITMAP);
205     ok(!hbm, "got %p\n", hbm);
206
207     target = NULL;
208     hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 10, 5, &target);
209     EXPECT_HR(hr, S_OK);
210
211     hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target);
212     ok(hdc != NULL, "got %p\n", hdc);
213
214     hbm = GetCurrentObject(hdc, OBJ_BITMAP);
215     ok(hbm != NULL, "got %p\n", hbm);
216
217     /* check DIB properties */
218     ret = GetObjectW(hbm, sizeof(ds), &ds);
219     ok(ret == sizeof(ds), "got %d\n", ret);
220     ok(ds.dsBm.bmWidth == 10, "got %d\n", ds.dsBm.bmWidth);
221     ok(ds.dsBm.bmHeight == 5, "got %d\n", ds.dsBm.bmHeight);
222     ok(ds.dsBm.bmPlanes == 1, "got %d\n", ds.dsBm.bmPlanes);
223     ok(ds.dsBm.bmBitsPixel == 32, "got %d\n", ds.dsBm.bmBitsPixel);
224     ok(ds.dsBm.bmBits != NULL, "got %p\n", ds.dsBm.bmBits);
225
226     size.cx = size.cy = -1;
227     hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
228     EXPECT_HR(hr, S_OK);
229     ok(size.cx == 10, "got %d\n", size.cx);
230     ok(size.cy == 5, "got %d\n", size.cy);
231
232     IDWriteBitmapRenderTarget_Release(target);
233
234     IDWriteGdiInterop_Release(interop);
235 }
236
237 START_TEST(font)
238 {
239     HRESULT hr;
240
241     hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory);
242     ok(hr == S_OK, "got 0x%08x\n", hr);
243     if (hr != S_OK)
244     {
245         win_skip("failed to create factory\n");
246         return;
247     }
248
249     test_CreateFontFromLOGFONT();
250     test_CreateBitmapRenderTarget();
251
252     IDWriteFactory_Release(factory);
253 }