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
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 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
34 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
36 ULONG rc = IUnknown_AddRef(obj);
37 IUnknown_Release(obj);
38 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
41 static IDWriteFactory *factory;
43 static void test_CreateFontFromLOGFONT(void)
45 static const WCHAR arialW[] = {'A','r','i','a','l',0};
46 static const WCHAR blahW[] = {'B','l','a','h','!',0};
47 IDWriteGdiInterop *interop;
48 DWRITE_FONT_WEIGHT weight;
49 DWRITE_FONT_STYLE style;
53 {FW_NORMAL, DWRITE_FONT_WEIGHT_NORMAL},
54 {FW_BOLD, DWRITE_FONT_WEIGHT_BOLD},
55 { 0, DWRITE_FONT_WEIGHT_NORMAL},
56 { 50, DWRITE_FONT_WEIGHT_NORMAL},
57 {150, DWRITE_FONT_WEIGHT_NORMAL},
58 {250, DWRITE_FONT_WEIGHT_NORMAL},
59 {350, DWRITE_FONT_WEIGHT_NORMAL},
60 {450, DWRITE_FONT_WEIGHT_NORMAL},
61 {650, DWRITE_FONT_WEIGHT_BOLD},
62 {750, DWRITE_FONT_WEIGHT_BOLD},
63 {850, DWRITE_FONT_WEIGHT_BOLD},
64 {950, DWRITE_FONT_WEIGHT_BOLD},
65 {960, DWRITE_FONT_WEIGHT_BOLD},
71 hr = IDWriteFactory_GetGdiInterop(factory, &interop);
75 /* null out parameter crashes this call */
76 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, NULL, NULL);
78 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, NULL, &font);
79 EXPECT_HR(hr, E_INVALIDARG);
81 memset(&logfont, 0, sizeof(logfont));
82 logfont.lfHeight = 12;
84 logfont.lfWeight = FW_NORMAL;
86 lstrcpyW(logfont.lfFaceName, arialW);
88 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
91 /* now check properties */
92 weight = IDWriteFont_GetWeight(font);
94 ok(weight == DWRITE_FONT_WEIGHT_NORMAL, "got %d\n", weight);
96 style = IDWriteFont_GetStyle(font);
97 ok(style == DWRITE_FONT_STYLE_ITALIC, "got %d\n", style);
99 ret = IDWriteFont_IsSymbolFont(font);
100 ok(!ret, "got %d\n", ret);
102 IDWriteFont_Release(font);
105 for (i = 0; i < sizeof(weights)/(2*sizeof(LONG)); i++)
107 memset(&logfont, 0, sizeof(logfont));
108 logfont.lfHeight = 12;
109 logfont.lfWidth = 12;
110 logfont.lfWeight = weights[i][0];
111 lstrcpyW(logfont.lfFaceName, arialW);
113 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
116 weight = IDWriteFont_GetWeight(font);
118 ok(weight == weights[i][1],
119 "%d: got %d, expected %d\n", i, weight, weights[i][1]);
120 IDWriteFont_Release(font);
123 /* weight not from enum */
124 memset(&logfont, 0, sizeof(logfont));
125 logfont.lfHeight = 12;
126 logfont.lfWidth = 12;
127 logfont.lfWeight = 550;
128 lstrcpyW(logfont.lfFaceName, arialW);
130 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
133 weight = IDWriteFont_GetWeight(font);
135 ok(weight == DWRITE_FONT_WEIGHT_NORMAL || broken(weight == DWRITE_FONT_WEIGHT_BOLD) /* win7 w/o SP */,
137 IDWriteFont_Release(font);
139 /* empty or nonexistent face name */
140 memset(&logfont, 0, sizeof(logfont));
141 logfont.lfHeight = 12;
142 logfont.lfWidth = 12;
143 logfont.lfWeight = FW_NORMAL;
144 lstrcpyW(logfont.lfFaceName, blahW);
146 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
148 EXPECT_HR(hr, DWRITE_E_NOFONT);
150 memset(&logfont, 0, sizeof(logfont));
151 logfont.lfHeight = 12;
152 logfont.lfWidth = 12;
153 logfont.lfWeight = FW_NORMAL;
155 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
157 EXPECT_HR(hr, DWRITE_E_NOFONT);
159 IDWriteGdiInterop_Release(interop);
162 static void test_CreateBitmapRenderTarget(void)
164 IDWriteBitmapRenderTarget *target, *target2;
165 IDWriteGdiInterop *interop;
173 hr = IDWriteFactory_GetGdiInterop(factory, &interop);
177 hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 0, 0, &target);
180 if (0) /* crashes on native */
181 hr = IDWriteBitmapRenderTarget_GetSize(target, NULL);
183 size.cx = size.cy = -1;
184 hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
186 ok(size.cx == 0, "got %d\n", size.cx);
187 ok(size.cy == 0, "got %d\n", size.cy);
190 hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 0, 0, &target2);
192 ok(target != target2, "got %p, %p\n", target2, target);
193 IDWriteBitmapRenderTarget_Release(target2);
195 hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target);
196 ok(hdc != NULL, "got %p\n", hdc);
198 hbm = GetCurrentObject(hdc, OBJ_BITMAP);
199 ok(hbm != NULL, "got %p\n", hbm);
201 /* check DIB properties */
202 ret = GetObjectW(hbm, sizeof(ds), &ds);
203 ok(ret == sizeof(BITMAP), "got %d\n", ret);
204 ok(ds.dsBm.bmWidth == 1, "got %d\n", ds.dsBm.bmWidth);
205 ok(ds.dsBm.bmHeight == 1, "got %d\n", ds.dsBm.bmHeight);
206 ok(ds.dsBm.bmPlanes == 1, "got %d\n", ds.dsBm.bmPlanes);
207 ok(ds.dsBm.bmBitsPixel == 1, "got %d\n", ds.dsBm.bmBitsPixel);
208 ok(!ds.dsBm.bmBits, "got %p\n", ds.dsBm.bmBits);
210 IDWriteBitmapRenderTarget_Release(target);
212 hbm = GetCurrentObject(hdc, OBJ_BITMAP);
213 ok(!hbm, "got %p\n", hbm);
216 hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 10, 5, &target);
219 hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target);
220 ok(hdc != NULL, "got %p\n", hdc);
222 hbm = GetCurrentObject(hdc, OBJ_BITMAP);
223 ok(hbm != NULL, "got %p\n", hbm);
225 /* check DIB properties */
226 ret = GetObjectW(hbm, sizeof(ds), &ds);
227 ok(ret == sizeof(ds), "got %d\n", ret);
228 ok(ds.dsBm.bmWidth == 10, "got %d\n", ds.dsBm.bmWidth);
229 ok(ds.dsBm.bmHeight == 5, "got %d\n", ds.dsBm.bmHeight);
230 ok(ds.dsBm.bmPlanes == 1, "got %d\n", ds.dsBm.bmPlanes);
231 ok(ds.dsBm.bmBitsPixel == 32, "got %d\n", ds.dsBm.bmBitsPixel);
232 ok(ds.dsBm.bmBits != NULL, "got %p\n", ds.dsBm.bmBits);
234 size.cx = size.cy = -1;
235 hr = IDWriteBitmapRenderTarget_GetSize(target, &size);
237 ok(size.cx == 10, "got %d\n", size.cx);
238 ok(size.cy == 5, "got %d\n", size.cy);
240 IDWriteBitmapRenderTarget_Release(target);
242 IDWriteGdiInterop_Release(interop);
245 static void test_GetFontFamily(void)
247 static const WCHAR arialW[] = {'A','r','i','a','l',0};
248 IDWriteFontFamily *family, *family2;
249 IDWriteGdiInterop *interop;
254 hr = IDWriteFactory_GetGdiInterop(factory, &interop);
257 memset(&logfont, 0, sizeof(logfont));
258 logfont.lfHeight = 12;
259 logfont.lfWidth = 12;
260 logfont.lfWeight = FW_NORMAL;
261 logfont.lfItalic = 1;
262 lstrcpyW(logfont.lfFaceName, arialW);
264 hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font);
267 if (0) /* crashes on native */
268 hr = IDWriteFont_GetFontFamily(font, NULL);
271 hr = IDWriteFont_GetFontFamily(font, &family);
274 EXPECT_REF(family, 2);
276 hr = IDWriteFont_GetFontFamily(font, &family2);
278 ok(family2 == family, "got %p, previous %p\n", family2, family);
280 EXPECT_REF(family, 3);
281 IDWriteFontFamily_Release(family2);
283 hr = IDWriteFont_QueryInterface(font, &IID_IDWriteFontFamily, (void**)&family2);
284 EXPECT_HR(hr, E_NOINTERFACE);
285 ok(family2 == NULL, "got %p\n", family2);
287 IDWriteFontFamily_Release(family);
288 IDWriteFont_Release(font);
289 IDWriteGdiInterop_Release(interop);
296 hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory);
297 ok(hr == S_OK, "got 0x%08x\n", hr);
300 win_skip("failed to create factory\n");
304 test_CreateFontFromLOGFONT();
305 test_CreateBitmapRenderTarget();
306 test_GetFontFamily();
308 IDWriteFactory_Release(factory);